Giter VIP home page Giter VIP logo

pg-insert's Introduction

pg-insert

Create bulk insert DML statement


Install

$ npm install https://github.com/gautham1985/pg-insert


Usage

const { Bulk, Column, Type } = require('pg-insert');

const dbColumns = [
  new Column(
    'userId',
    Type.Varchar(50),
    { required: true, underscored: true, },
  ),
  new Column(
    'createdAt',
    Type.Timestamp,
    { required: true, underscored: true, defaultValue: Date.now() },
  ),
  new Column(
    'ANY_JAVASCRIPT_VARIABLE_NAME',
    Type.Json,
    { required: false, alias: 'meta_data' },
  )
];

const bulk = new Bulk('user_table', dbColumns);

const sampleData = [{
  userId: 'asdf3234sdf9823hk9h',
  ANY_JAVASCRIPT_VARIABLE_NAME: {
    key: 'any value',
    numberValue: 1000,
  }
}, {
  userId: 'j3ljsdfj20o23k9sd',
  ANY_JAVASCRIPT_VARIABLE_NAME: {
    dummy: 23949,
    test: 'any data',
  }
}];

const createdDML = bulk.insert(sampleData);

console.log(createdDML);

/*
INSERT INTO user_table (user_id, created_at, meta_data) VALUES ('asdf3234sdf9823hk9h', '2019-03-14 20:46:01', '{"key":"any value","numberValue":1000}'), ('j3ljsdfj20o23k9sd', '2019-03-14 20:46:01', '{"dummy":23949,"test":"any data"}')
*/

Notes

This library is useful only to create Bulk Insert statements or insert statements only. Schema creation could be handled directly by a database DBA or using other libraries like node-postgres, sequelize, etc (Sequelize would support migration).

This library has no other dependencies and is written in pure javascript and is useful to copy large set of data where /copy cannot be used to copy data.

pg-insert's People

Contributors

gathm5 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.