bulk-insert
v1.2.0
Published
A writable stream that batches
Downloads
1,502
Maintainers
Readme
Asymmetrical Signing
A writable stream that batches.
Example
const createBulk = require('bulk-insert')
const onError = (err) => {
if (err) console.error(err.stack || err)
}
const writable = createBulk({
limit: 500, // maximum # of documents to insert at one time
interval: '0.5s', // minimum interval between flushes,
onError,
flush (data) {
// `data` will be an array
kinesis.putRecords({
Records: data.map((x) => ({
Data: JSON.stringify(x),
PartitionKey: 'some_key'
})),
StreamName: 'some_stream_name'
}, onError)
}
})
writable.write({
some: 'data'
})
writable.write({
some: 'more data'
})
API
const writable = bulkInsert(options)
Options:
limit<Integer>: 1000
- maximum # of documents to insert at one timeinterval<Number|String>: '300ms'
- minimum interval between flushes,onError<Function>
- optional function that handlesflush()
errorsflush<Function>
- a function with the signature(data<Array>) => {}
writable.write(data)
Write data to the stream.
writable.flush()
Flush all the data immediately.
writable.close()
Flushes immediately and unrefs all future timers, allowing the process to exit gracefully. Even though you are still able to write to the stream after you've closed it, you should not.