Skip to content

Commit

Permalink
Support parameters inside schema.table.col syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Nov 9, 2023
1 parent d192a2c commit 0875fe5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser/grammar.ne
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ square_brackets -> "[" free_form_sql:* "]" {%
})
%}

property_access -> atomic_expression _ %DOT _ (identifier | array_subscript | all_columns_asterisk) {%
property_access -> atomic_expression _ %DOT _ (identifier | array_subscript | all_columns_asterisk | parameter) {%
// Allowing property to be <array_subscript> is currently a hack.
// A better way would be to allow <property_access> on the left side of array_subscript,
// but we currently can't do that because of another hack that requires
Expand Down
15 changes: 15 additions & 0 deletions test/options/paramTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,20 @@ export default function supportsParamTypes(format: FormatFn) {
second;
`);
});

// Normal SQL prepared statement parameters cannot really occur like this,
// but we support this to facilitate using the paramTypes config for
// working around SQL templating.
it('supports parameterizing schema.table.column syntax', () => {
const result = format('SELECT {schema}.{table}.{column} FROM {schema}.{table}', {
paramTypes: { custom: [{ regex: String.raw`\{\w+\}` }] },
});
expect(result).toBe(dedent`
SELECT
{schema}.{table}.{column}
FROM
{schema}.{table}
`);
});
});
}

0 comments on commit 0875fe5

Please sign in to comment.