Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Release v1.0.0-rc1

Pre-release
Pre-release
Compare
Choose a tag to compare
@nwronski nwronski released this 17 Oct 05:16
· 20 commits to master since this release

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). The sqlite-parser command 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 through sqlite-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 from v0.14.5). This is defined in the package.json as the browser version of the module, which is recognized by tools such as jspm and browserify.