Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1064642

Browse files
committed
Merge branch 'master' of github.com:JavaScriptor/js-sql-parser into unicode-extended
2 parents199a1c6 +dec1f54 commit1064642

File tree

7 files changed

+34
-18
lines changed

7 files changed

+34
-18
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ package-lock.json
44
*.log
55
*.swp
66
dist/parser/sqlParser.js
7+
.vscode/

‎CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
1.3.0 fix tableFactor alias bug. AST changed in tableFactor. #34
1111
1.4.0 fix bug `using ' & " for column alias?` #40 #44
1212
1.4.1 hogfix "support quoted alias: multiple alias and orderby support"
13+
1.5.0 support feature placeholder.

‎Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
publish: test
22
@npm publish
33

4-
test:
4+
test:
55
@npmtest
66

7+
test-with-log:
8+
@DEBUG=js-sql-parser npmtest
9+
710
.PHONY: publish test

‎README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sql grammar follows https://dev.mysql.com/doc/refman/5.7/en/select.html
1010

1111
##news
1212

13+
- Support feature`PlaceHolder like ${param}` since v1.5.0[#43](https://github.com/JavaScriptor/js-sql-parser/pull/43)
1314
- Fix bug`using ' & " for column alias?` since v1.4.1[#40](https://github.com/JavaScriptor/js-sql-parser/issues/40),[#44](https://github.com/JavaScriptor/js-sql-parser/issues/44)
1415
- Fix bug tableFactor alias since v1.3.0[#34](https://github.com/JavaScriptor/js-sql-parser/issues/34)
1516
- Add support for "`" quoted alias since v1.2.2.[#33](https://github.com/JavaScriptor/js-sql-parser/issues/33)
@@ -35,6 +36,18 @@ console.log(parser.stringify(ast));
3536
// SELECT foo FROM bar
3637
```
3738

39+
```js
40+
// placeholder test
41+
constparser=require('js-sql-parser');
42+
constast=parser.parse('select ${a} as a');
43+
44+
ast['value']['selectItems']['value'][0]['value']="'value'";
45+
console.log(parser.stringify(ast));
46+
// SELECT 'value' AS a
47+
```
48+
49+
Note: PlaceHolder is an`literal` value but not an`identifier`. Table_name / column_name / function_name are`identifier` thus should NOT be placed with placeholder.
50+
3851
##script tag
3952

4053
```js
@@ -60,10 +73,6 @@ var sql = sqlParser.stringify(ast);
6073
- intervalexpr: Date INTERVAL keyword. // to support
6174
- into outfile: INTO OUTFILE keyword. // to support
6275

63-
##TODO
64-
65-
- ${value} like value place holder support.
66-
6776
##Build
6877

6978
- Run`npm run build` to build the distributable.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"js-sql-parser",
3-
"version":"1.4.1",
3+
"version":"1.5.0",
44
"description":"",
55
"main":"./dist/parser/sqlParser.js",
66
"scripts": {

‎src/stringify.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,18 +552,6 @@ Sql.prototype.travelSelectParenthesized = function(ast) {
552552
this.appendKeyword(')');
553553
};
554554
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-
567555
if(ast.value){
568556
this.travel(ast.value);
569557
}

‎test/main.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
constdebug=require('debug')('js-sql-parser');
44
constparser=require('../');
5+
constassert=require('assert');
56

67
consttestParser=function(sql){
78
letfirstAst=parser.parse(sql);
@@ -416,6 +417,19 @@ describe('select grammar support', function () {
416417
"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})"
417418
)
418419
});
420+
it('place holder support2',function(){
421+
testParser(
422+
"select sum(quota_value) b, 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}')"
423+
)
424+
});
425+
it('place holder support3',function(){
426+
letfirstAst=parser.parse('select ${a} as a');
427+
firstAst['value']['selectItems']['value'][0]['value']="'value'";
428+
letfirstSql=parser.stringify(firstAst);
429+
debug(JSON.stringify(firstAst,null,2));
430+
assert.equal(firstSql.trim().toUpperCase(),"select 'value' as a".toUpperCase());
431+
testParser(firstSql);
432+
});
419433

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp