npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bcp

v0.2.2

Published

Node.js utility for interacting with SQL Server Bulk Copy Program (bcp).

Downloads

13

Readme

node-bcp

A node.js wrapper for the SQL Server bcp utility which allows for bulk insert and export operations.

Install

npm install bcp

You will need the bcp utility installed on your system. If you're running on Windows and use SQL Server, you probably already have this. On Linux, you can use Microsoft's ODBC Driver for Linux which comes includes the bcp utility. On OSX, sorry, better luck next time.

This library does not support FreeTDS's reimplementation called freebcp. Their implementation is very incomplete and differs enough from the Microsoft version

Bulk Import Example

Imagine we have this table:

MyDatabase.dbo.MyTable

Column | Type -------- | ---- Id | Int Identity MyDate | DateTime MyFloat | Float MyString | NVarChar(50)

var Bcp = require('bcp');

// Initialize a Bcp object with settings like connection info, database, encoding, etc.
var b = new Bcp({
  user: 'login_name',
  password: 'password',
  database: 'MyDatabase',
  fieldTerminator: '\t::\t', // make sure to pick a character sequence not found in your data
  rowTerminator: '\t::\n',
  unicode: true,
  checkConstraints: true
});

// now, prepare a bulk insert. Notice how we excluded the Id column because it's an identity 
// and it would be ignored anyway, unless we set useIdentity: true. All columns in the table, 
// but not listed in the column list here will be inserted as NULL
// The column names do not need to match the same casing as the SQL Server columns, but they 
// must match the properties of the objects passed to writeRows(). Column order is insignificant.
b.prepareBulkInsert('MyTable', ['myDate', 'myFloat', 'myString'], function (err, imp) {
  if (err)
    // ...
  
  // the imp object is an ImportFile object which you can write to
  imp.writeRows([
    { myDate: new Date(), myFloat: 23.7, myString: 'hello' },
    { myDate: new Date('2014-09-01'), myFloat: 7.23, myString: 'world' }
  ]);
  
  // you can call writeRows() as many times as you'd like. It writes to a file stream.
  
  // if you decide you don't want to use this bulk insert, call cancel in order to delete 
  // temporary the data file
  // imp.cancel();
  
  // when you're done writing rows, execute the bulk insert
  imp.execute(function (error)
  {
    if (error)
      // ...
  });
});

Bulk Export Example

var b = new Bcp({
  user: 'login_name',
  password: 'password',
  database: 'MyDatabase',
  checkConstraints: false,
  unicode: false,
  native: true // if need native data format.
});

var customOptions = {
  read: false,
  keepFiles: true,
  sql: 'select * from MyDatabase.dbo.MyTable where id = 1' // if need select query, do like this.
};

b.bulkExport(tablename, customOptions, function (err) {

});

For a full description of all of the options which can be passed to the Bcp constructor, see lib/Bcp.js and Microsoft's bcp documentation.

Other Notes

This library is incomplete, and not very well tested. It needs lots more documentation, features, better error reporting, and love. Bulk Export is partially implemented, but there are no examples yet. Use at your own risk. May cause drowsiness and irritability.