This repository was archived by the owner on Jul 15, 2021. It is now read-only.
This repository was archived by the owner on Jul 15, 2021. It is now read-only.
Ability to use parser as a stream transform for pipes #27
Closed
Description
To allow users to parse arbitrarily long SQL files or other readable stream sources, I want to create a stream transform that can accept a readable stream and then push (write) out JSON strings of the ASTs for individual statements, e.g.:
import { createReadStream } from 'fs';
import { SqliteParserTransform } from 'sqlite-parser';
const parser = new SqliteParserTransform();
// A file with hundreds of SQL queries
const fileName = './test/sql/official-suite/randexpr1-1.sql';
const read = createReadStream(fileName);
// Pipe the readable stream to the parser transform
read.pipe(parser);
// Stream the ASTs for individual statements to stdout
parser.pipe(process.stdout);
parser.on('error', function (err) {
console.log(err);
process.exit(1);
});
parser.on('finish', function () {
process.exit(0);
});