MSSQLStream.js
back-pressure in node-mssql
mssql issure Back pressure? #67
when use node-mssql to traverse a table of MSSQL Server database, you may face the back-pressure
problem if data is very big. node-mssql
does not support the pause and resume in stream now.
why mssql-stream
use mssql-stream
you can fetch all the data row by row, with pause and resume.
when the row is coming, pause the stream, after comsume the row, resume the stream in a callback or resume the stream direct.
how to use mssql-stream
- it is not a real stream, and there are about 1000 rows cached.
- the table must have a (unique and int) field.
mssql-stream
is only support fetch all the data from table, 'SELECT WHERE' or other queries is not supported.
what is in mssql-stream
- get the range of (unique and int) field.
- fetch first 1000 rows by specific the (unique and int) field.
- after these 1000 rows consumed, fetch next 1000 rows
- until no more rows left, done.
API
Constructor
/** * @param {[Object]} dbConfig config for node-mssql connection { user: 'youruser', password: 'yourpass', port: 1433, server: '192.168.1.1', database: 'yourdb' } * @param {[Object]} tableConfig specific the table and (unique and int) field name { name: '[dbo].[test_table]', uniqueColumn: 'myid' } */var mssqlStream = dbConfig tableConfig;
Methods
mssqlStream.pause()
pause the stream, MSSQLStream will not return new rows, until calling the resume().
mssqlStream.resume()
resume the stream
Events
'row'
return a row
mssqlStream;
'error'
return error info
mssqlStream
'end'
all rows has been fetched
mssqlStream;
Use
var MSSQLStream = ; var dbConfig = user: 'youruser' password: 'yourpass' port: 1433 server: '192.168.1.1' database: 'yourdb'; var tableConfig = // specific the table name: '[dbo].[test_table]' // specific the (unique and int) field uniqueColumn: 'myid'; var mssqlStream = dbConfig tableConfig; mssqlStream; mssqlStream; mssqlStream;
Test
Run npm install
Run npm test
License
WTFPL License.