Skip to content

ataube/node-bulk-insert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-bulk-insert

Simple SQL generator for bulk insert statements

Works nicely with node-postgres.

Install

npm install @ataube/bulk-insert --save

Usage

Simple

const bulkInsert = require('node-bulk-insert');
const values = [{ name: 'Ben', age: 20 }, { name: 'Michael', age: 30 }]];

const { sql } = bulkInsert('myTable', values);

// INSERT INTO myTable (name,age) VALUES ($1,$2),($3,$4) RETURNING *;

Ignore Fields

const bulkInsert = require('node-bulk-insert');
const options = { ignore: ['age'] };
const values = [{ name: 'Ben', age: 20 }, { name: 'Michael', age: 30 }]];

const { sql, values } = bulkInsert('myTable', values, options);

// sql: INSERT INTO myTable (name) VALUES ($1),($2) RETURNING *;
// values: ['Ben', 'Michael']

More samples can also be found in the tests.

Options

  • return {string} - defines the returning fields of sql statements, ie. { return: 'id, name' }
  • ignore {Array} - defines fields to be ignored

About

Simple SQL generator for bulk insert statements

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published