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

bodega

v0.1.6

Published

A simple wrapper for node-postgres to make your life even easier.

Downloads

19

Readme

Bodega

/bəˈdeɪgə/
	
	noun: bodega; plural noun: bodegas
	A cellar or shop selling wine and food,
	especially in a Spanish-speaking country or area.

Dependencies

NPM

NPM

A simple wrapper for node-postgres to make your life even easier. You do not need to worry about which connection to use, about pooling or about returning a client/connection to the pool after using it.

There is no need to additionally install node-postgres. Bodega will take care of it. If you need more information/details on the actual node-postgres module, take a look at its own repository.

Super simple usage:

Install your bodega:

npm install bodega

Require your bodega and open it:

var bodega = require('bodega').open(config);

The config object requires these properties:

  • user - Your DB username (string).
  • password - Your DB password (string).
  • database - The database you are trying to connect to (string).

Optional properties:

  • host - The host where your DB is to be found. (string, default: localhost).
  • port - The port on which your DB is listening. (int, default: 5432).
  • ssl - Whether to use an SSL connection or not. (boolean, default: false).
Below you will find some basic examples to illustrate the use of bodega

SELECT

var query = 'SELECT * FROM "Wine"';
bodega.do(query, function (err, data) {
	if (err) {
		throw err;
	}

	// Do something with your data
	return data;
});
Expected response
{
 "rows": [],
 "rowCount": int,
}

INSERT

var query = 'INSERT INTO "Wine"("brand", "year") VALUES($1, $2) RETURNING id';
bodega.do(query, ['Quintanilla del Monte', '1980'], function (err, data) {
	if (err) {
		throw err;
	}

	// Do something with your data
	return data.id;
});
Expected response
{
 "rows": [
 		{ "id": int }
 	],
 "rowCount": int,
 "id": int
}

The id property is what's expected to be returned from the DB by using the RETURNING syntax. Furthemore -to keep things easy and comfortable; if rows contains only one object, then all of this object's properties will be mapped to the root, hence the presence of id at root level.

INSERT (Via a stored procedure)

var query = 'SELECT "insertWine"($1, $2) AS "bottle"';
bodega.do(query, ['Tempranillo de la Torre', '1980'], function (err, data) {
	if (err) {
		throw err;
	}

	// Do something with your data
	return data.bottle;
});
Expected response
{
 "rows": [
 		{ "bottle": variable }
 	],
 "rowCount": int,
 "bottle": variable
}

In this case, the contents of the bottle property will depend on what the stored procedure decides to return. The rest is the same as described above.

DELETE

var query = 'DELETE FROM "Wine" WHERE "year" = $1';
bodega.do(query, ['1980'], function (err, data) {
	if (err) {
		throw err;
	}

	// Do something with your data
	return data.rowCount;
});
Expected response
{
 "rows": [],
 "rowCount": int
}

The rowCount property will hold the number of deleted rows.