@@ -55,7 +55,46 @@ describe('SqliteFormatter', () => {
5555 supportsJoin ( format ) ;
5656 supportsSetOperations ( format , [ 'UNION' , 'UNION ALL' , 'EXCEPT' , 'INTERSECT' ] ) ;
5757 supportsOperators ( format , [ '%' , '~' , '&' , '|' , '<<' , '>>' , '==' , '->' , '->>' , '||' ] ) ;
58- supportsParams ( format , { positional : true , numbered : [ '?' ] , named : [ ':' , '$' , '@' ] } ) ;
58+ supportsParams ( format , { positional : true , numbered : [ '?' ] , named : [ ':' , '@' ] } ) ;
59+
60+ // SQLite has its own Tcl-style $-parameter syntax that is handled as a custom
61+ // param type rather than the default named-param prefix. See sqlite.formatter.ts.
62+ describe ( 'supports SQLite $-style (Tcl) named placeholders' , ( ) => {
63+ it ( 'recognizes $name placeholders' , ( ) => {
64+ expect ( format ( 'SELECT $foo, $bar, $baz;' ) ) . toBe ( dedent `
65+ SELECT
66+ $foo,
67+ $bar,
68+ $baz;
69+ ` ) ;
70+ } ) ;
71+
72+ it ( 'recognizes $name(...) placeholders without inserting a space' , ( ) => {
73+ expect ( format ( 'select $p(x=y);' ) ) . toBe ( dedent `
74+ select
75+ $p(x=y);
76+ ` ) ;
77+ } ) ;
78+
79+ it ( 'recognizes $name with :: suffix and (...) trailer' , ( ) => {
80+ expect ( format ( 'SELECT $foo::bar(extra);' ) ) . toBe ( dedent `
81+ SELECT
82+ $foo::bar(extra);
83+ ` ) ;
84+ } ) ;
85+
86+ it ( 'replaces $name placeholders with param values' , ( ) => {
87+ expect (
88+ format ( `WHERE name = $name AND age > $current_age;` , {
89+ params : { name : "'John'" , current_age : '10' } ,
90+ } )
91+ ) . toBe ( dedent `
92+ WHERE
93+ name = 'John'
94+ AND age > 10;
95+ ` ) ;
96+ } ) ;
97+ } ) ;
5998 supportsWindow ( format ) ;
6099 supportsLimiting ( format , { limit : true , offset : true } ) ;
61100 supportsDataTypeCase ( format ) ;
0 commit comments