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

pg-harness

v0.2.1

Published

A postgres test harness for Node.JS

Downloads

2

Readme

PG-Setup - A Postgres test harness

Install

npm install pg-setup

Usage

var db = require('pg-harness')();
// promise-based version.
db.initAsync() // start 
  .then(function () {
    console.log('port =', db.port);
    return db.startAsync();
  })
  .then(function () {
    console.log('create database test');
    return db.createDBAsync('test');
 })
  .then(function () {
    console.log('connect.database.auth');
    return db.connectAsync('test');
  })
  .then (function () { // run sql script separated by ;
    return db.execScriptAsync('./schema.sql');
  })
  .then (function () {
    console.log('disconnect');
    return db.disconnectAsync();
  })
  .then(function () {
    return db.stopAsync();
  })
  .then(function () {
    return db.cleanAsync();
  })
  .catch(function (e) {
    console.error(e);
  });

pg-harness uses bluebird to create the promise-based methods, so it follows bluebird's pattern with Async appended to the promise version of the calls.

db = require('pg-harness')(options);

By default, you can pass in the following options:

  • port - the port of the postgres instance. If not specified, it will be a randomly assigned port.
  • dataPath - the location of the database. If not specified it will be a temp directory. If specified, the directory needs to exist.

If you pass in either options, you should not call init or initAsync.

Supported Methods

pg-harness utilizes easydbi and wraps their calls as appropriate.

init(callback); initAsync()

Initializes the database directory. This is equivalent to initdb call (and indeed implemented via initdb).

start(callback); startAsync()

Starts the database given the option specified in the constructor. Call after init or initAsync.

createDB(name, callback); createDBAsync(name)

Creates a database with the given name.

connect(name, callback); connectAsync(name)

Connects against the database with the given name. Note that at this time the harness only supports a single connection (i.e. you should not try to connect to multiple database with this module).

query(query, args, callback); queryAsync(query, args)

Wraps over the connection's query call.

queryOne(query, args, callback); queryOneAsync(query, args);

Wraps over the connection's queryOne call.

exec(query, args, callback); execAsync(query, args);

Wraps over the connection's exec call.

execScript(filePath, callback); execScriptAsync(filePath)

Wraps over the connection's execScript call.

begin(callback); beginAsync()

Wraps over the connection's begin call.

commit(callback); commitAsync()

Wraps over the connection's commit call.

rollback(callback); rollbackAsync()

Wraps over the connection's rollback call.

disconnect(callback); disconnectAsync()

Wraps over the connection's disconnect call.

stop(callback); stopAsync()

Stops the postgres instance. This is a force-kill.

clean(callback); cleanAsync()

Removes the data directory.