Comments (5)
Yeah, now I see it clearly!
If you want to submit a PR we can include this in the next release.
I would by default have no prefix so we don't introduce any breaking changes and add an option to opt in for a prefix.
from join-monster.
Interesting!
Can you show with a https://github.com/join-monster/join-monster-sscce that this actually happens?
Becase in the method that you can write raw sql, you have a variable with what will be the name of the table. So I'm not sure which kind of query could break that.
from join-monster.
Thanks for the quick reply.
Yes, we can write raw SQL, but we don’t know what alias join-monster will pass to our join/where expression function.
If we use the alias ‘a’ in our expression, it could clash with the ‘a’ that join-monster assigns to its first table reference. This conflict arises because join-monster assigns aliases automatically, and we might unknowingly use the same alias.
Since it’s common to use single letters in SQL subqueries, I’d prefer if join-monster avoided using single-letter aliases. Instead, it would be better if join-monster prefixed its generated aliases with a ‘$’ to prevent any clashes with our own aliases.
See
https://github.com/join-monster/join-monster/blob/master/src/alias-namespace.js
I would do something as trivial as:
generate(type, name) {
// if minifiying, make everything ugly and unique.
if (this.minify) {
// tables definitely all need unique names
if (type === 'table') {
- return this.mininym.next().value.join('')
+ return `$${this.mininym.next().value.join('')}`;
}
// but if its a column, we dont need to worry about the uniqueness from other columns
// because the columns will get prefixed with the parent(s)
if (!this.columnAssignments[name]) {
this.columnAssignments[name] = this.mininym.next().value.join('')
}
return this.columnAssignments[name]
}
}
Edit:
Here is an excerpt from the SQL query join-monster generated with minify: true
:
SELECT
...
"az"."id" AS "ap__az__b",
"az"."name" AS "ap__az__h",
"az"."color" AS "ap__az__ao"
FROM (
SELECT "a".*, count(*) OVER () AS "$total"
FROM property_ext "a" -- <- you can see join-monster has assigned property_ext to "a"
WHERE ("a".deleted_at IS NULL AND lower((
SELECT p.first_name || ' ' || p.last_name
FROM agent AS a -- but I have also used "a" in my WHERE subquery
INNER JOIN person AS p ON a.person_id = p.id
WHERE a.id = "a".agent_id -- causing a clash on this subquery WHERE expression
LIMIT 1
)) LIKE '%' || lower('a') || '%' AND "a".id NOT IN (
...
from join-monster.
Thank you @nicoabie! PR ready for review.
from join-monster.
FIxed in #533
from join-monster.
Related Issues (20)
- tsd failing locally HOT 2
- Fails if I extend GraphQLObjectType HOT 2
- Must call joinMonster in a resolver on a field where the type is decorated with \"sqlTable\" HOT 9
- Cannot read properties of undefined (reading 'sqlTable') HOT 2
- Failing type defs
- Issue with GlobalIDs not transforming back to "native" uuid4 IDs HOT 1
- bug in joinMonster.getNode(): def.args not iterable HOT 4
- Querying the same relation multiple times as aliases with different args results in wrong data HOT 5
- Remove requirement for uniqueKey to be defined HOT 1
- Pagination with dynamic sorting does not support null values. HOT 2
- joinMonster creating invalid MySQL sql HOT 2
- Unsupport many-to-many relation on graphql v15.8 and join-monster v3.1.1 using postgres? HOT 2
- Batching JoinMonster calls
- The HTTP server example code is broken due to deprecation of kao-graphql HOT 1
- join-monster fails to work in a react native deployment HOT 1
- Typescript type error for GraphQLFieldExtensions HOT 1
- Some disjoint fields of the same union type are discarded HOT 7
- Test flake on database startup
- Readthedocs build fails when master is updated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from join-monster.