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

release: v1.5.0#59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
albin3 merged 2 commits intomasterfromfeat-placeholder-support
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@ package-lock.json
*.log
*.swp
dist/parser/sqlParser.js
.vscode/
1 change: 1 addition & 0 deletionsCHANGELOG
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,3 +10,4 @@
1.3.0 fix tableFactor alias bug. AST changed in tableFactor. #34
1.4.0 fix bug `using ' & " for column alias?` #40 #44
1.4.1 hogfix "support quoted alias: multiple alias and orderby support"
1.5.0 support feature placeholder.
5 changes: 4 additions & 1 deletionMakefile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
publish: test
@npm publish

test:
test:
@npmtest

test-with-log:
@DEBUG=js-sql-parser npmtest

.PHONY: publish test
17 changes: 13 additions & 4 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@ sql grammar follows https://dev.mysql.com/doc/refman/5.7/en/select.html

## news

- Support feature `PlaceHolder like ${param}` since v1.5.0 [#43](https://github.com/JavaScriptor/js-sql-parser/pull/43)
- 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)
- Fix bug tableFactor alias since v1.3.0 [#34](https://github.com/JavaScriptor/js-sql-parser/issues/34)
- Add support for "`" quoted alias since v1.2.2. [#33](https://github.com/JavaScriptor/js-sql-parser/issues/33)
Expand All@@ -35,6 +36,18 @@ console.log(parser.stringify(ast));
// SELECT foo FROM bar
```

```js
// placeholder test
const parser = require('js-sql-parser');
const ast = parser.parse('select ${a} as a');

ast['value']['selectItems']['value'][0]['value'] = "'value'";
console.log(parser.stringify(ast));
// SELECT 'value' AS a
```

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.

## script tag

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

## TODO

- ${value} like value place holder support.

## Build

- Run `npm run build` to build the distributable.
Expand Down
2 changes: 1 addition & 1 deletionpackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
{
"name": "js-sql-parser",
"version": "1.4.1",
"version": "1.5.0",
"description": "",
"main": "./dist/parser/sqlParser.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletionsrc/sqlParser.jison
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@
[#]\s.*\n /* skip sql comments */
\s+ /* skip whitespace */

[$][{](.*?)[}] return 'PLACE_HOLDER'
[$][{](.+?)[}] return 'PLACE_HOLDER'
[`][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*[`] return 'IDENTIFIER'
[\w]+[\u4e00-\u9fa5]+[0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
[\u4e00-\u9fa5][0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
Expand Down
12 changes: 0 additions & 12 deletionssrc/stringify.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -552,18 +552,6 @@ Sql.prototype.travelSelectParenthesized = function(ast) {
this.appendKeyword(')');
};
Sql.prototype.travelPlaceHolder = function (ast) {
if (ast.left) {
this.travel(ast.left);
}

if (ast.operator) {
this.append(ast.operator);
}

if (ast.right) {
this.append(ast.right);
}

if (ast.value) {
this.travel(ast.value);
}
Expand Down
14 changes: 14 additions & 0 deletionstest/main.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@

const debug = require('debug')('js-sql-parser');
const parser = require('../');
const assert = require('assert');

const testParser = function (sql) {
let firstAst = parser.parse(sql);
Expand DownExpand Up@@ -416,6 +417,19 @@ describe('select grammar support', function () {
"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})"
)
});
it('place holder support2', function() {
testParser(
"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}')"
)
});
it('place holder support3', function() {
let firstAst = parser.parse('select ${a} as a');
firstAst['value']['selectItems']['value'][0]['value'] = "'value'";
let firstSql = parser.stringify(firstAst);
debug(JSON.stringify(firstAst, null, 2));
assert.equal(firstSql.trim().toUpperCase(), "select 'value' as a".toUpperCase());
testParser(firstSql);
});

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

[8]ページ先頭

©2009-2025 Movatter.jp