mirror of
https://github.com/dbgate/dbgate
synced 2024-11-08 04:35:58 +00:00
query-splitter: documentatin for streaming support
This commit is contained in:
parent
55fb7ba8bb
commit
482ecd7c38
@ -1,15 +1,15 @@
|
|||||||
[![NPM version](https://img.shields.io/npm/v/dbgate-query-splitter.svg)](https://www.npmjs.com/package/dbgate-query-splitter)
|
[![NPM version](https://img.shields.io/npm/v/dbgate-query-splitter.svg)](https://www.npmjs.com/package/dbgate-query-splitter)
|
||||||
|
|
||||||
dbgate-query-splitter
|
# dbgate-query-splitter
|
||||||
====================
|
|
||||||
|
|
||||||
Splits long SQL query into into particular statements. Designed to have zero dependencies and to be fast.
|
Splits long SQL query into into particular statements. Designed to have zero dependencies and to be fast. Also supports nodejs-streams.
|
||||||
|
|
||||||
Supports following SQL dialects:
|
Supports following SQL dialects:
|
||||||
* MySQL
|
|
||||||
* PostgreSQL
|
- MySQL
|
||||||
* SQLite
|
- PostgreSQL
|
||||||
* Microsoft SQL Server
|
- SQLite
|
||||||
|
- Microsoft SQL Server
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -19,10 +19,26 @@ import { splitQuery, mysqlSplitterOptions, mssqlSplitterOptions, postgreSplitter
|
|||||||
const output = splitQuery('SELECT * FROM `table1`;SELECT * FROM `table2`;', mysqlSplitterOptions);
|
const output = splitQuery('SELECT * FROM `table1`;SELECT * FROM `table2`;', mysqlSplitterOptions);
|
||||||
|
|
||||||
// output is ['SELECT * FROM `table1`', 'SELECT * FROM `table2`']
|
// output is ['SELECT * FROM `table1`', 'SELECT * FROM `table2`']
|
||||||
|
```
|
||||||
|
|
||||||
|
## Streaming support in nodejs
|
||||||
|
Function splitQueryStream accepts input stream and query options. Result is object stream, each object for one splitted query.
|
||||||
|
Tokens must not be divided into more input chunks. This can be accomplished eg. when input stream emits one chunk per line (eg. using byline module)
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { mysqlSplitterOptions, mssqlSplitterOptions, postgreSplitterOptions } = require('dbgate-query-splitter');
|
||||||
|
const { splitQueryStream } = require('dbgate-query-splitter/lib/splitQueryStream');
|
||||||
|
const fs = require('fs');
|
||||||
|
const byline = require('byline');
|
||||||
|
|
||||||
|
const fileStream = fs.createReadStream('INPUT_FILE_NAME', 'utf-8');
|
||||||
|
const lineStream = byline(fileStream);
|
||||||
|
const splittedStream = splitQueryStream(lineStream, mysqlSplitterOptions);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Please run tests before pushing any changes.
|
Please run tests before pushing any changes.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@ -30,7 +46,8 @@ yarn test
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Supported syntax
|
## Supported syntax
|
||||||
* Comments
|
|
||||||
* Dollar strings (PostgreSQL)
|
- Comments
|
||||||
* GO separators (MS SQL)
|
- Dollar strings (PostgreSQL)
|
||||||
* Custom delimiter, setby DELIMITER keyword (MySQL)
|
- GO separators (MS SQL)
|
||||||
|
- Custom delimiter, setby DELIMITER keyword (MySQL)
|
||||||
|
Loading…
Reference in New Issue
Block a user