Skip to content

Commit

Permalink
Add schema & database to contextFunctions in compile time (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
pokutuna authored May 9, 2023
1 parent f58bbdd commit cf2f509
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function compileSqlx(rootNode: SyntaxTreeNode, path: string) {
rootNode
);

const contextFunctions = ["self", "ref", "resolve", "name", "when", "incremental"]
const contextFunctions = ["self", "ref", "resolve", "name", "when", "incremental", "schema", "database"]
.map(name => `const ${name} = ctx.${name} ? ctx.${name}.bind(ctx) : undefined;`)
.join("\n");

Expand Down
4 changes: 4 additions & 0 deletions tests/core/backslashes-act-literally.js.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const resolve = ctx.resolve ? ctx.resolve.bind(ctx) : undefined;
const name = ctx.name ? ctx.name.bind(ctx) : undefined;
const when = ctx.when ? ctx.when.bind(ctx) : undefined;
const incremental = ctx.incremental ? ctx.incremental.bind(ctx) : undefined;
const schema = ctx.schema ? ctx.schema.bind(ctx) : undefined;
const database = ctx.database ? ctx.database.bind(ctx) : undefined;

return [`
select
Expand All @@ -31,6 +33,8 @@ const resolve = ctx.resolve ? ctx.resolve.bind(ctx) : undefined;
const name = ctx.name ? ctx.name.bind(ctx) : undefined;
const when = ctx.when ? ctx.when.bind(ctx) : undefined;
const incremental = ctx.incremental ? ctx.incremental.bind(ctx) : undefined;
const schema = ctx.schema ? ctx.schema.bind(ctx) : undefined;
const database = ctx.database ? ctx.database.bind(ctx) : undefined;

return [`
select
Expand Down
2 changes: 2 additions & 0 deletions tests/core/backticks-are-escaped.js.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const resolve = ctx.resolve ? ctx.resolve.bind(ctx) : undefined;
const name = ctx.name ? ctx.name.bind(ctx) : undefined;
const when = ctx.when ? ctx.when.bind(ctx) : undefined;
const incremental = ctx.incremental ? ctx.incremental.bind(ctx) : undefined;
const schema = ctx.schema ? ctx.schema.bind(ctx) : undefined;
const database = ctx.database ? ctx.database.bind(ctx) : undefined;

return [`
select "\`" from \`location\`
Expand Down
2 changes: 2 additions & 0 deletions tests/core/basic-syntax.js.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const resolve = ctx.resolve ? ctx.resolve.bind(ctx) : undefined;
const name = ctx.name ? ctx.name.bind(ctx) : undefined;
const when = ctx.when ? ctx.when.bind(ctx) : undefined;
const incremental = ctx.incremental ? ctx.incremental.bind(ctx) : undefined;
const schema = ctx.schema ? ctx.schema.bind(ctx) : undefined;
const database = ctx.database ? ctx.database.bind(ctx) : undefined;

return [`
select * from ${ref('dab')}
Expand Down
2 changes: 2 additions & 0 deletions tests/core/js-placeholder-strings-inside-sql-strings.js.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const resolve = ctx.resolve ? ctx.resolve.bind(ctx) : undefined;
const name = ctx.name ? ctx.name.bind(ctx) : undefined;
const when = ctx.when ? ctx.when.bind(ctx) : undefined;
const incremental = ctx.incremental ? ctx.incremental.bind(ctx) : undefined;
const schema = ctx.schema ? ctx.schema.bind(ctx) : undefined;
const database = ctx.database ? ctx.database.bind(ctx) : undefined;

return [`
select '${`bar`}'
Expand Down
4 changes: 4 additions & 0 deletions tests/core/strings-act-literally.js.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const resolve = ctx.resolve ? ctx.resolve.bind(ctx) : undefined;
const name = ctx.name ? ctx.name.bind(ctx) : undefined;
const when = ctx.when ? ctx.when.bind(ctx) : undefined;
const incremental = ctx.incremental ? ctx.incremental.bind(ctx) : undefined;
const schema = ctx.schema ? ctx.schema.bind(ctx) : undefined;
const database = ctx.database ? ctx.database.bind(ctx) : undefined;

return [`
select
Expand All @@ -30,6 +32,8 @@ const resolve = ctx.resolve ? ctx.resolve.bind(ctx) : undefined;
const name = ctx.name ? ctx.name.bind(ctx) : undefined;
const when = ctx.when ? ctx.when.bind(ctx) : undefined;
const incremental = ctx.incremental ? ctx.incremental.bind(ctx) : undefined;
const schema = ctx.schema ? ctx.schema.bind(ctx) : undefined;
const database = ctx.database ? ctx.database.bind(ctx) : undefined;

return [`
select
Expand Down

0 comments on commit cf2f509

Please sign in to comment.