flora-sql-parser
Advanced tools
Comparing version
@@ -147,3 +147,3 @@ 'use strict'; | ||
function columnRefToSQL(expr) { | ||
var str = '"' + expr.column + '"'; | ||
var str = expr.column !== '*' ? '"' + expr.column + '"' : '*'; | ||
if (expr.hasOwnProperty('table') && expr.table !== null) str = '"' + expr.table + '".' + str; | ||
@@ -150,0 +150,0 @@ return !expr.parentheses ? str : '(' + str + ')'; |
{ | ||
"name": "flora-sql-parser", | ||
"version": "0.2.3", | ||
"version": "0.6.0", | ||
"description": "Parse SQL (select) statements into abstract syntax tree (AST) and convert ASTs back to SQL.", | ||
@@ -40,14 +40,13 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0", | ||
"iojs": ">=2.0" | ||
"node": ">=0.10.0" | ||
}, | ||
"dependencies": { | ||
"flora-errors": "^0.2.0", | ||
"flora-errors": "^0.6.0", | ||
"pegjs": "^0.9.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.0.0", | ||
"chai": "^3.4.1", | ||
"grunt": "^0.4.5", | ||
"grunt-cli": "^0.1.13", | ||
"grunt-eslint": "^17.2.0", | ||
"grunt-eslint": "^18.0.0", | ||
"grunt-exec": "^0.4.6", | ||
@@ -57,7 +56,7 @@ "grunt-mocha-istanbul": "^3.0.1", | ||
"grunt-newer-explicit": "^0.9.4", | ||
"istanbul": "^0.3.15", | ||
"load-grunt-tasks": "^3.2.0", | ||
"mocha": "^2.2.5", | ||
"istanbul": "^0.4.2", | ||
"load-grunt-tasks": "^3.4.0", | ||
"mocha": "^2.3.4", | ||
"mocha-bamboo-reporter": "^1.1.0" | ||
} | ||
} |
@@ -40,2 +40,7 @@ Flora SQL Parser | ||
Acknowledgement | ||
-------------- | ||
This project is based on the SQL parser extracted from Alibaba's [nquery](https://github.com/alibaba/nquery) module. | ||
License | ||
@@ -42,0 +47,0 @@ ------- |
@@ -27,2 +27,6 @@ 'use strict'; | ||
it('should support asterisk prefixed by table', function () { | ||
expect(getParsedSql('SELECT t.* FROM t')).to.equal('SELECT "t".* FROM "t"'); | ||
}); | ||
it('should parse multiple expressions', function () { | ||
@@ -29,0 +33,0 @@ sql = 'SELECT col1 AS a, col2 AS b FROM t'; |
@@ -40,2 +40,10 @@ 'use strict'; | ||
it('should parse "table.*" column expressions', function () { | ||
ast = parser.parse('SELECT t.* FROM t'); | ||
expect(ast.columns).to.eql([ | ||
{ expr: { type: 'column_ref', 'table': 't', column: '*' }, as: null } | ||
]); | ||
}); | ||
it('should parse aliases w/o "AS" keyword', function () { | ||
@@ -435,2 +443,14 @@ ast = parser.parse('SELECT a aa FROM t'); | ||
}); | ||
describe('strings', function () { | ||
it('should parse single quoted strings', function () { | ||
ast = parser.parse('SELECT \'string\''); | ||
expect(ast.columns).to.eql([{ expr: { type: 'string', value: 'string' }, as: null }]); | ||
}); | ||
it('should parse keywords in single quotes as string', function () { | ||
ast = parser.parse('SELECT \'select\''); | ||
expect(ast.columns).to.eql([{ expr: { type: 'string', value: 'select' }, as: null }]); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
76271
1.98%16
6.67%1103
1.75%49
11.36%1
Infinity%+ Added
- Removed
Updated