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

db-connection-promise

v0.4.4

Published

Extension of Javascript Promises to provide chainable then like syntax for database queries

Downloads

14

Readme

Db Connection Promise

This library provides a class "DbConnectionPromise" which adhears to the Promises/A+ specification, but additionally wraps a any-db database connection. This allows for an additional chainable .query() method which behaves in a similar manner to .then().

This allows for a clean API for querying databases of any sort.

Build Status Coverage Status

WARNING - PRERELEASE

WARNING: This library is currently in pre-release and the API may or may not be changed before final release.

The version will be bumped to 1.0.0 when the library is released

Todo before 1.0.0 release

  • Implement Postgres Tests
  • Test using API in real project rather than just in tests (nano-orm)
  • Check ConnectionPromise fully meets the Promises/A+ specification
  • Can we wrap other Promise types (eg, javascript native promises)? Should be able to wrap anything that meets Promises/A+ spec
  • Work out the peerDependency vs dependency stuff (see any-db docs)
  • Grep for :TODO: in code
  • Cleanup of code
  • Documentation for close, commit, rollback is confusing - implement as sub classes?
  • Documentation/examples confusing - we import DbConnectionPromise, but really this is the method makeDbConnectionPromise. Maybe change to import dbcp. Then dbcp.wrap(...) or dbcp.getQueryableType(...), etc.

Usage

let DbConnectionPromise = require('db-connection-promise');

let conn = AnyDb.createConnection({ adapter: 'sqlite3'});
let dbh = DbConnectionPromise(conn);

dbh
	.fail((err) => {
		console.error("Failed to connect to database");
		console.dir(err);
		process.exit(1);
	})
	.query("SELECT * FROM user")
	.then((results) => {
		console.log("Loaded " + results.rows.length + " users from the database");
		console.log("First user: " + results.rows[0].username + ", " + results.rows[0].password);
	})
	.close()
	.then(() => {
		console.log("Database connection has been closed");
	})
	.done();

Full example programs can be found in the /examples directory

A Note on Different Database Adaptors

This library, like any-db upon which it is based, is designed to provide a consistent interface to a number of databases. However it makes no attempt to hide the differences in how those databases operate.

For example, mysql supports the keyword AUTO_INCREMENT where as sqlite3 does not - instead opting to auto-increments columns which meet certain criteria.

This library makes absolutely NO attempt to shield users from these differences; instead the intended use case is that users will pick a particular database and stick with it for the lifetime of their project, however by using db-connection-promise you can utilise the same q promise based interface regardless of which database you happen to choose.

Supported Adaptors

Theoretically all any-db-XXX adaptors conform to the same interface, and so since this library works with one it should be compatible with all of them, however it is currently only tested against the following adaptors: