Skip to content

Commit f2524a0

Browse files
authored
Merge pull request #43 from sockstack/add-place-holder-support
`${value}` like place holder support
2 parents 09b15e4 + 4200a15 commit f2524a0

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/sqlParser.jison

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[#]\s.*\n /* skip sql comments */
1212
\s+ /* skip whitespace */
1313

14+
[$][{](.*?)[}] return 'PLACE_HOLDER'
1415
[`][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*[`] return 'IDENTIFIER'
1516
[\w]+[\u4e00-\u9fa5]+[0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
1617
[\u4e00-\u9fa5][0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
@@ -304,6 +305,7 @@ literal
304305
| number { $$ = $1 }
305306
| boolean { $$ = $1 }
306307
| null { $$ = $1 }
308+
| place_holder { $$ = $1 }
307309
;
308310
function_call
309311
: IDENTIFIER '(' function_call_param_list ')' { $$ = {type: 'FunctionCall', name: $1, params: $3} }
@@ -587,3 +589,6 @@ table_factor
587589
| '(' selectClause ')' aliasOpt { $$ = { type: 'TableFactor', value: { type: 'SubQuery', value: $2 }, alias: $4.alias, hasAs: $4.hasAs} }
588590
| '(' table_references ')' { $$ = $2; $$.hasParentheses = true }
589591
;
592+
place_holder
593+
: PLACE_HOLDER { $$ = { type: 'PlaceHolder', value: $1, param: $1.slice(2, -1)} }
594+
;

src/stringify.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,20 @@ Sql.prototype.travelSelectParenthesized = function(ast) {
551551
this.travel(ast.value);
552552
this.appendKeyword(')');
553553
};
554+
Sql.prototype.travelPlaceHolder = function (ast) {
555+
if (ast.left) {
556+
this.travel(ast.left);
557+
}
558+
559+
if (ast.operator) {
560+
this.append(ast.operator);
561+
}
562+
563+
if (ast.right) {
564+
this.append(ast.right);
565+
}
566+
567+
if (ast.value) {
568+
this.travel(ast.value);
569+
}
570+
};

test/main.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ describe('select grammar support', function () {
411411
it('bugfix table alias2', function () {
412412
testParser('select a.* from a t1 join b t2 on t1.a = t2.a')
413413
});
414+
it('place holder support', function() {
415+
testParser(
416+
"select sum(quota_value) value, busi_col2 as sh, ${a} as a, YEAR(now()) from der_quota_summary where table_ename = 'gshmyyszje_derivedidx' and cd = (select id from t1 where a = ${t1})"
417+
)
418+
});
414419

415420
it('support quoted alias: multiple alias and orderby support', function () {
416421
testParser('select a as `A A`, b as `B B` from z');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy