-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add schema to TableNode
s within RawNode
s @ WithSchemaPlugin
.
#826
base: master
Are you sure you want to change the base?
feat: add schema to TableNode
s within RawNode
s @ WithSchemaPlugin
.
#826
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
TableNode
s within RawNode
s @ WIthSchemaPlugin
.TableNode
s within RawNode
s @ WithSchemaPlugin
.
@@ -517,6 +520,72 @@ for (const dialect of DIALECTS.filter( | |||
}) | |||
}) | |||
|
|||
describe('raw sql', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a little copy-pasta is better than these DRY tests that are really really hard to read. This is fine, but in the future, if there's only a couple of cases, just copy paste them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely agree, it's a mess.
|
||
subsuites.forEach(([name, builder]) => { | ||
describe(`${name}.table`, () => { | ||
it('should add schema', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case like this:
sql`
select * from person as p
inner join pets on pets.owner_id = ${sql.ref('p.id')}
`
I think the current code would incorrectly add schema to mammals.p.id
🤔
It might be impossible to handle this correctly since we don't know how ref
and table
are used in raw SQL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, got some rethinking to do. Great catch! 💪
Maybe if we limit the scope to just eb.ref
& eb.table
- since it forces usage of things from query context - and find a way to skip aliases (don't remember if I handled it) - this could work.
051973f
to
fa57c64
Compare
closes #761.
When using
sql.table
,eb.table
,sql.ref
andeb.ref
, we createTableNode
s.When executing
sql
template tag queries or parts of queries, any plugins on the db instance are run - includingWithSchemaPlugin
when available.Currently, the plugin doesn't handle
RawNode
s, so we only get partial schema addition.This PR addresses that. Now using
.ref
and.table
is even more powerful. 👓