Skip to content

Commit 0875fe5

Browse files
committed
Support parameters inside schema.table.col syntax
1 parent d192a2c commit 0875fe5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/parser/grammar.ne

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ square_brackets -> "[" free_form_sql:* "]" {%
249249
})
250250
%}
251251

252-
property_access -> atomic_expression _ %DOT _ (identifier | array_subscript | all_columns_asterisk) {%
252+
property_access -> atomic_expression _ %DOT _ (identifier | array_subscript | all_columns_asterisk | parameter) {%
253253
// Allowing property to be <array_subscript> is currently a hack.
254254
// A better way would be to allow <property_access> on the left side of array_subscript,
255255
// but we currently can't do that because of another hack that requires

test/options/paramTypes.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,20 @@ export default function supportsParamTypes(format: FormatFn) {
9595
second;
9696
`);
9797
});
98+
99+
// Normal SQL prepared statement parameters cannot really occur like this,
100+
// but we support this to facilitate using the paramTypes config for
101+
// working around SQL templating.
102+
it('supports parameterizing schema.table.column syntax', () => {
103+
const result = format('SELECT {schema}.{table}.{column} FROM {schema}.{table}', {
104+
paramTypes: { custom: [{ regex: String.raw`\{\w+\}` }] },
105+
});
106+
expect(result).toBe(dedent`
107+
SELECT
108+
{schema}.{table}.{column}
109+
FROM
110+
{schema}.{table}
111+
`);
112+
});
98113
});
99114
}

0 commit comments

Comments
 (0)