Releases: codeschool/sqlite-parser
Release v1.0.0
Added
-
The root node of the AST now has
typeandvariantproperties:{ "type": "statement", "variant": "list", "statement": [{ "type": "statement", "variant": "select", "statement": {} }] } -
There is now a command line version of the parser when it is installed as a global module (e.g.,
npm i -g sqlite-parser). Thesqlite-parsercommand is then available to use to parse input SQL files and write the results to stdout or a JSON file. Additional usage instructions and options available throughsqlite-parser --help.sqlite-parser input.sql --output foo.json -
To allow users to parse arbitrarily long SQL files or other readable stream sources, there is now a stream transform that can accept a readable stream and then push (write) out JSON strings of the ASTs for individual statements.
-
The AST for each statement is pushed down the stream as soon as it is read and parsed instead of reading the entire file into memory before parsing begins.
var parserTransform = require('sqlite-parser').createParser(); var readStream = require('fs').createReadStream('./large-input-file.sql'); readStream.pipe(parserTransform); parserTransform.pipe(process.stdout); parserTransform.on('error', function (err) { console.error(err); process.exit(1); }); parserTransform.on('finish', function () { process.exit(0); });
-
To pipe the output into a file that contains a single valid JSON structure, the output of the parser steam transform needs to be wrapped in statement list node where every statement is separated by a comma.
var fs = require('fs'); var sqliteParser = require('sqlite-parser'); var parserTransform = sqliteParser.createParser(); var singleNodeTransform = sqliteParser.createStitcher(); var readStream = fs.createReadStream('./large-input-file.sql'); var writeStream = fs.createWriteStream('./large-output-file.json'); readStream.pipe(parserTransform); parserTransform.pipe(singleNodeTransform); singleNodeTransform.pipe(writeStream); parserTransform.on('error', function (err) { console.error(err); process.exit(1); }); writeStream.on('finish', function () { process.exit(0); });
-
-
Added missing
ATTACH DATABASEstatement. It will pair nicely with the existingDETACH DATABASEstatement.ATTACH DATABASE 'bees2.db' AS more_bees
-
SQLite allows you to enter basically anything you want for a datatype, such as the datatype for a column in a
CREATE TABLEstatement, because it doesn't enforce types you provide. So, the parser will accept almost any unquoted string in place of a datatype. ref1 ref2CREATE TABLE t1(x DINOSAUR, y BIRD_PERSON);
-
Run parser against entire SQLite test corpus using
grunt testallcommand.- Warning: This command will parse ~49,000 of queries, across almost 900 different files, representing the entire SQLite test corpus at the time it was processed.
-
Allow multi-byte UTF-8 characters (e.g.,
\u1234) in identifier names. -
Add support for table functions in the
FROMclause of aSELECTstatement.SELECT j2.rowid, jx.rowid FROM j2, json_tree(j2.json) AS jx
Changed
-
BREAKING CHANGE Instead of publishing this module on npm as a browserified and minified bundle, The transpiled ES2015 code in
lib/is now published and I have left it up to the end user to decide if they want to browserify or minify the library. The combined unminified file sizes for the published version of the parser is now ~127kB.- There is still a
dist/folder containing the minified browserified bundle that comes in at ~81kB (7% reduction fromv0.14.5). This is defined in thepackage.jsonas the browser version of the module, which is recognized by tools such as jspm and browserify.
- There is still a
-
BREAKING CHANGE The
onproperty of aCREATE INDEXstatement is now treated as a table expression identifier, and has the correspondingtypeandvariant:{ "type": "statement", "variant": "create", "format": "index", "target": { "type": "identifier", "variant": "index", "name": "bees.hive_state" }, "on": { "type": "identifier", "variant": "expression", "format": "table", "name": { "type": "identifier", "variant": "table", "name": "hive" }, "columns": [] } } -
BREAKING CHANGE Indexed columns (e.g., the column list in the
ONpart of aCREATE INDEXstatement) and ordering expressions (e.g., theORDER BYpart of aSELECTstatement) now have the following format:- When they are proceeded by an ordering term (e.g.,
ASC,DESC) and/orCOLLATE, such asORDER BY nick ASC
{ "order": [{ "type": "expression", "variant": "order", "expression": { "type": "identifier", "variant": "column", "name": "nick" }, "direction": "asc" }] }- But, when it is only an expression or column name without any ordering term or
COLLATEthen it will only be the expression itself, and the implicit"direction": "asc"will not be added to the AST, such asORDER BY nick:
{ "order": [{ "type": "identifier", "variant": "column", "name": "nick" }] } - When they are proceeded by an ordering term (e.g.,
-
BREAKING CHANGE Because of changes to how binary expressions are parsed, the order that expressions are composed may be different then the previous release. For example, ASTs may change such as those for queries that contain multiple binary expressions:
SELECT * FROM hats WHERE x != 2 OR x == 3 AND y > 5
-
BREAKING CHANGE Expressions such as
x NOT NULLwere previously treated as a unary expressions but are now considered binary expressions.{ "type": "expression", "format": "binary", "variant": "operation", "operation": "not", "left": { "type": "identifier", "variant": "column", "name": "x" }, "right": { "type": "literal", "variant": "null", "value": "null" } } -
BREAKING CHANGE Now, instead of transaction statements being parsed as a single statement of type
transactionto be considered valid, each statement that makes up a the transaction (e.g.,BEGIN,END) is considered its own distinct statement that can exist independent of the others. Because a single transaction can be spread across multiple input strings given to the parser, it is no longer treated as a single, large, transaction statement.BEGIN; DROP TABLE t1; END;
{ "type": "statement", "variant": "list", "statement": [ { "type": "statement", "variant": "transaction", "action": "begin" }, { "type": "statement", "target": { "type": "identifier", "variant": "table", "name": "t1" }, "variant": "drop", "format": "table", "condition": [] }, { "type": "statement", "variant": "transaction", "action": "commit" } ] } -
BREAKING CHANGE
COLLATEcan now appear multiple times in a row wherever it would previously be allowed to appear, and as a result, thecollateproperty of the AST will contain an array.SELECT 'cats' ORDER BY 1 COLLATE nocase COLLATE nocase
-
BREAKING CHANGE
CONSTRAINTnames can now appear multiple times before or after a column or table constraint in aCREATE TABLEstatement. Having aCONSTRAINTname after the constraint is an undocumented SQLite feature. However, while it will not give an error, any constraint name appearing after the constraint is ignored.CREATE TABLE t2c( -- Two leading and two trailing CONSTRAINT clauses -- Name used: x_two x INTEGER CONSTRAINT x_one CONSTRAINT x_two CHECK( typeof( coalesce(x,0) ) == 'integer' ) CONSTRAINT x_two CONSTRAINT x_three, y INTEGER, z INTEGER, -- Two trailing CONSTRAINT clauses -- Name used: (none) UNIQUE(x, y, z) CONSTRAINT u_one CONSTRAINT u_two )
-
BREAKING CHANGE
JOINclauses and table lists can now occur in the sameFROMclause of a singleSELECTstatement. Tables separated by a comma will be included in theJOINmap as a cross join.SELECT * FROM aa LEFT JOIN bb, cc WHERE cc.c = aa.a;
-
BREAKING CHANGE A comma-separated list of table or subquery names in the
FROMclause of aSELECTstatement are now treated as a join map of cross joins. Also, each pair of comma-separated tables or subqueries can include a join constraint expression (e.g.,ON t.col1 = b.col2).SELECT t1.rowid, t2.rowid FROM t1, t2 ON t1.a = t2.b;
{ "type": "statement", "variant": "list", "statement": [ { "type": "statement", "variant": "select", "result": [ { "type": "identifier", "variant": "column", "name": "t1.rowid" }, { "type": "identifier", "variant": "column", "name": "t2.rowid" } ], "from": { "type": "map", "variant": "join", "source": { "type": "identifier", "variant": "table", "name": "t1" }, "map": [ { "type": "join", "variant": "cross join", "source": { "type"...
Release v1.0.0-rc3
Changed
RangeError: Maximum call stack size exceededgenerated when running the uglified bundle (dist/sqlite-parser.js) in the browser, so I am skipping the minification step and only publishing the browserified bundle.
Release v1.0.0-rc2
Changed
-
BREAKING CHANGE All named values for properties such as
variant,format, andtypeshould always be lowercase, even when uppercase in the input SQL (e.g.,variantis nownatural joininstead ofNATURAL JOINin the AST). -
BREAKING CHANGE New format for
CASEexpression AST nodes:variantwhenhas aconditionand aconsequentvariantelsehas just aconsequent- the outer
expressionis nowvariantcaseinstead ofbinary - instead of taking whatever is provided between
CASEandWHEN(e.g.,CASE foo WHEN ...) and calling that the expression, it is now added as thediscriminant
select case acc when a = 0 then a1 when a = 1 then b1 else c1 end
{ "type": "expression", "variant": "case", "expression": [ { "type": "condition", "variant": "when", "condition": { "type": "expression", "format": "binary", "variant": "operation", "operation": "=", "left": { "type": "identifier", "variant": "column", "name": "a" }, "right": { "type": "literal", "variant": "decimal", "value": "0" } }, "consequent": { "type": "identifier", "variant": "column", "name": "a1" } }, { "type": "condition", "variant": "when", "condition": { "type": "expression", "format": "binary", "variant": "operation", "operation": "=", "left": { "type": "identifier", "variant": "column", "name": "a" }, "right": { "type": "literal", "variant": "decimal", "value": "1" } }, "consequent": { "type": "identifier", "variant": "column", "name": "b1" } }, { "type": "condition", "variant": "else", "consequent": { "type": "identifier", "variant": "column", "name": "c1" } } ], "discriminant": { "type": "identifier", "variant": "column", "name": "acc" } } -
BREAKING CHANGE New format for
EXISTSexpression nodes. Useexpressionnode inconditionforIF NOT EXISTS.NOT EXISTS, andEXISTSmodifiers instead of a string value.-
CREATE TABLEstatementcreate table if not exists foo(id int)
{ "type": "statement", "name": { "type": "identifier", "variant": "table", "name": "foo" }, "variant": "create", "format": "table", "definition": [ { "type": "definition", "variant": "column", "name": "id", "definition": [], "datatype": { "type": "datatype", "variant": "int", "affinity": "integer" } } ], "condition": [ { "type": "condition", "variant": "if", "condition": { "type": "expression", "variant": "exists", "operator": "not exists" } } ] } -
DROP TABLEstatementdrop table if exists foo
{ "type": "statement", "target": { "type": "identifier", "variant": "table", "name": "foo" }, "variant": "drop", "format": "table", "condition": [ { "type": "condition", "variant": "if", "condition": { "type": "expression", "variant": "exists", "operator": "exists" } } ] } -
NOT EXISTSexpressionselect a where not exists (select b)
{ "type": "statement", "variant": "select", "result": [ { "type": "identifier", "variant": "column", "name": "a" } ], "where": [ { "type": "expression", "format": "unary", "variant": "exists", "expression": { "type": "statement", "variant": "select", "result": [ { "type": "identifier", "variant": "column", "name": "b" } ] }, "operator": "not exists" } ] }
-
Release v1.0.0-rc1
Added
-
There is now a command line version of the parser when it is installed as a global module (e.g.,
npm i -g sqlite-parser). Thesqlite-parsercommand is then available to use to parse input SQL files and write the results to stdout or a JSON file. Additional usage instructions and options available throughsqlite-parser --help.sqlite-parser input.sql --output foo.json -
To allow users to parse arbitrarily long SQL files or other readable stream sources, there is now a stream transform that can accept a readable stream and then push (write) out JSON strings of the ASTs for individual statements.
-
The AST for each statement is pushed down the stream as soon as it is read and parsed instead of reading the entire file into memory before parsing begins.
var parserTransform = require('sqlite-parser').createParser(); var readStream = require('fs').createReadStream('./large-input-file.sql'); readStream.pipe(parserTransform); parserTransform.pipe(process.stdout); parserTransform.on('error', function (err) { console.error(err); process.exit(1); }); parserTransform.on('finish', function () { process.exit(0); });
-
To pipe the output into a file that contains a single valid JSON structure, the output of the parser steam transform needs to be wrapped in statement list node where every statement is separated by a comma.
var fs = require('fs'); var sqliteParser = require('sqlite-parser'); var parserTransform = sqliteParser.createParser(); var singleNodeTransform = sqliteParser.createStitcher(); var readStream = fs.createReadStream('./large-input-file.sql'); var writeStream = fs.createWriteStream('./large-output-file.json'); readStream.pipe(parserTransform); parserTransform.pipe(singleNodeTransform); singleNodeTransform.pipe(writeStream); parserTransform.on('error', function (err) { console.error(err); process.exit(1); }); writeStream.on('finish', function () { process.exit(0); });
-
Changed
- BREAKING CHANGE Instead of publishing this module on npm as a browserified and minified bundle, The transpiled ES2015 code in
lib/is now published and I have left it up to the end user to decide if they want to browserify or minify the library. The combined unminified file sizes for the published version of the parser is now ~127kB.- There is still a
dist/folder containing the minified browserified bundle that comes in at ~81kB (7% reduction fromv0.14.5). This is defined in thepackage.jsonas the browser version of the module, which is recognized by tools such as jspm and browserify.
- There is still a
Release v1.0.0-beta
Added
-
The root node of the AST now has
typeandvariantproperties:{ "type": "statement", "variant": "list", "statement": [{ "type": "statement", "variant": "select", "statement": {} }] } -
Added missing
ATTACH DATABASEstatement. It will pair nicely with the existingDETACH DATABASEstatement.ATTACH DATABASE 'bees2.db' AS more_bees
-
SQLite allows you to enter basically anything you want for a datatype, such as the datatype for a column in a
CREATE TABLEstatement, because it doesn't enforce types you provide. So, the parser will accept almost any unquoted string in place of a datatype. ref1 ref2CREATE TABLE t1(x DINOSAUR, y BIRD_PERSON);
-
Run parser against entire SQLite test corpus using
grunt testallcommand.- Warning: This command will parse ~49,000 of queries, across almost 900 different files, representing the entire SQLite test corpus at the time it was processed.
-
Allow multi-byte UTF-8 characters (e.g.,
\u1234) in identifier names. -
Add support for table functions in the
FROMclause of aSELECTstatement.SELECT j2.rowid, jx.rowid FROM j2, json_tree(j2.json) AS jx
Changed
-
BREAKING CHANGE The
onproperty of aCREATE INDEXstatement is now treated as a table expression identifier, and has the correspondingtypeandvariant:{ "type": "statement", "variant": "create", "format": "index", "target": { "type": "identifier", "variant": "index", "name": "bees.hive_state" }, "on": { "type": "identifier", "variant": "expression", "format": "table", "name": { "type": "identifier", "variant": "table", "name": "hive" }, "columns": [] } } -
BREAKING CHANGE Indexed columns (e.g., the column list in the
ONpart of aCREATE INDEXstatement) and ordering expressions (e.g., theORDER BYpart of aSELECTstatement) now have the following format:- When they are proceeded by an ordering term (e.g.,
ASC,DESC) and/orCOLLATE, such asORDER BY nick ASC
{ "order": [{ "type": "expression", "variant": "order", "expression": { "type": "identifier", "variant": "column", "name": "nick" }, "direction": "asc" }] }- But, when it is only an expression or column name without any ordering term or
COLLATEthen it will only be the expression itself, and the implicit"direction": "asc"will not be added to the AST, such asORDER BY nick:
{ "order": [{ "type": "identifier", "variant": "column", "name": "nick" }] } - When they are proceeded by an ordering term (e.g.,
-
BREAKING CHANGE Because of changes to how binary expressions are parsed, the order that expressions are composed may be different then the previous release. For example, ASTs may change such as those for queries that contain multiple binary expressions:
SELECT * FROM hats WHERE x != 2 OR x == 3 AND y > 5
-
BREAKING CHANGE Expressions such as
x NOT NULLwere previously treated as a unary expressions but are now considered binary expressions.{ "type": "expression", "format": "binary", "variant": "operation", "operation": "not", "left": { "type": "identifier", "variant": "column", "name": "x" }, "right": { "type": "literal", "variant": "null", "value": "null" } } -
BREAKING CHANGE Now, instead of transaction statements being parsed as a single statement of type
transactionto be considered valid, each statement that makes up a the transaction (e.g.,BEGIN,END) is considered its own distinct statement that can exist independent of the others. Because a single transaction can be spread across multiple input strings given to the parser, it is no longer treated as a single, large, transaction statement.BEGIN; DROP TABLE t1; END;
{ "type": "statement", "variant": "list", "statement": [ { "type": "statement", "variant": "transaction", "action": "begin" }, { "type": "statement", "target": { "type": "identifier", "variant": "table", "name": "t1" }, "variant": "drop", "format": "table", "condition": [] }, { "type": "statement", "variant": "transaction", "action": "commit" } ] } -
BREAKING CHANGE
COLLATEcan now appear multiple times in a row wherever it would previously be allowed to appear, and as a result, thecollateproperty of the AST will contain an array.SELECT 'cats' ORDER BY 1 COLLATE nocase COLLATE nocase
-
BREAKING CHANGE
CONSTRAINTnames can now appear multiple times before or after a column or table constraint in aCREATE TABLEstatement. Having aCONSTRAINTname after the constraint is an undocumented SQLite feature. However, while it will not give an error, any constraint name appearing after the constraint is ignored.CREATE TABLE t2c( -- Two leading and two trailing CONSTRAINT clauses -- Name used: x_two x INTEGER CONSTRAINT x_one CONSTRAINT x_two CHECK( typeof( coalesce(x,0) ) == 'integer' ) CONSTRAINT x_two CONSTRAINT x_three, y INTEGER, z INTEGER, -- Two trailing CONSTRAINT clauses -- Name used: (none) UNIQUE(x, y, z) CONSTRAINT u_one CONSTRAINT u_two )
-
BREAKING CHANGE
JOINclauses and table lists can now occur in the sameFROMclause of a singleSELECTstatement. Tables separated by a comma will be included in theJOINmap as a cross join.SELECT * FROM aa LEFT JOIN bb, cc WHERE cc.c = aa.a;
-
BREAKING CHANGE A comma-separated list of table or subquery names in the
FROMclause of aSELECTstatement are now treated as a join map of cross joins. Also, each pair of comma-separated tables or subqueries can include a join constraint expression (e.g.,ON t.col1 = b.col2).SELECT t1.rowid, t2.rowid FROM t1, t2 ON t1.a = t2.b;
{ "type": "statement", "variant": "list", "statement": [ { "type": "statement", "variant": "select", "result": [ { "type": "identifier", "variant": "column", "name": "t1.rowid" }, { "type": "identifier", "variant": "column", "name": "t2.rowid" } ], "from": { "type": "map", "variant": "join", "source": { "type": "identifier", "variant": "table", "name": "t1" }, "map": [ { "type": "join", "variant": "cross join", "source": { "type": "identifier", "variant": "table", "name": "t2" }, "constraint": { "type": "constraint", "variant": "join", "format": "on", "on": { "type": "expression", "format": "binary", "variant": "operation", "operation": "=", "left": { "type": "identifier", "variant": "column", "name": "t1.a" }, "right": { "type": "identifier", "variant": "column", "name": "t2.b" } } } } ] } } ] } -
BREAKING CHANGE Instead of an array, for the
argsproperty of an AST node, it will now contain an expression list node containing the arguments on theexpressionproperty.{ "type": "expression", "variant": "list", "expression": [] }
Fixed
-
Fixed binary expression parsing logic so that it can handle expressions such as:
SELECT * FROM t where -1 * (2 + 3); SELECT * FROM t where 3 + 4 * 5 > 20; SELECT * FROM t where v1 = ((v2 * 5) - v3);
-
Allow qualified table name in
ONclause ofCREATE TRIGGERstatement (e.g.,ON dbName.tableName). -
Allow literal boolean values
onandoffinPRAGMAstatements:PRAGMA legacy_file_format = ON;
-
Do not treat
TEMPorROWIDas reserved words, since the official parser allowstemporrowid, when used as an identifier (e.g., a table namedtempor therowidcolumn of a table).CREATE TABLE temp.t1(a, b); SELECT rowid AS "Internal Row ID" FROM bees;
-
Require semicolons to delineate
BEGINandENDstatements for transactions while also allowing unnecessary semicolons to be omitted:BEGIN;CREATE TABLE nick(a, b);END -
Only allow CRUD operations inside of the body of a
CREATE TRIGGERstatement. -
Allow empty strings or
NULLto be used as aliases, to match behavior of the native SQLite parser, such as in anATTACH DATABASEstatement:ATTACH DATABASE '' AS ''
-
Allow datatype names to be provided to
COLLATEto match the behavior of the official SQLite parser:SELECT c1 FROM t ORDER BY 1 COLLATE numeric
-
Some
CREATE TRIGGERstatements were previously parsed as a binary expressions instead of create trigger statements. -
Allow indexed columns to be parsed when they include a
COLLATEand/or a ordering direction (e.g.,ASC,DESC) when part of a table constraint in a `CREATE T...
Release v0.15.0-beta
Changed
-
BREAKING CHANGE Because of changes to how binary expressions are parsed, the order that expressions are composed may be different then the previous release. For example, ASTs may change such as those for queries that contain multiple binary expressions:
SELECT * FROM hats WHERE x != 2 OR x == 3 AND y > 5
-
BREAKING CHANGE Expressions such as
x NOT NULLwere previously treated as a unary expressions but are now considered binary expressions.
Fixed
-
Fixed binary expression parsing logic so that it can handle expressions such as:
SELECT * FROM t where -1 * (2 + 3); SELECT * FROM t where 3 + 4 * 5 > 20; SELECT * FROM t where v1 = ((v2 * 5) - v3);
Release v0.14.5
Fixed
-
Fix alternate not equal operator
<>SELECT * FROM hats WHERE quantity <> 1
Release v0.14.4
Fixed
-
Allow spaces between a function name and the argument list
SELECT COUNT (*) FROM hats;
Release v0.14.3
Fixed
- Do not run grunt tasks on
npm install. Did not realize thatprepublishis run on a regularnpm installcommand.
Release v0.14.2
Fixed
- Minified bundle was missing from
dist/folder after runninggrunt release- This would have caused the parser to not work as an installed npm module since the
package.jsonmainproperty points to the minified bundle
- This would have caused the parser to not work as an installed npm module since the
- Fixed broken Grunt tasks (e.g.
grunt release) in Windows