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

ndbi

v0.2.0

Published

NDBI is a database abstraction layer (DAL) for Node.js. It is modeled after Perl's `DBI` module and PHP's `PDO` module. It is written with ES8 async/await in mind, while providing a common set of function interfaces for all supported database types, and i

Downloads

3

Readme

NDBI: A database abstraction layer for Node.js

NDBI is a database abstraction layer (DAL) for Node.js. It is modeled after Perl's DBI module and PHP's PDO module. It is written with ES8 async/await in mind, while providing a common set of function interfaces for all supported database types, and it is easy to implement new drivers as needed.

Examples:

    async function main() {
        const Ndbi = require("ndbi");

        const ndbi = new Ndbi("postgres:host=localhost;database=test");
        await ndbi.connect();

        const stmt = await ndbi.prepare("SELECT * FROM foo WHERE bar = $1");
        await stmt.execute([ "baz" ]);

        let row;
        while (row = await stmt.fetchRow()) {
            console.log(`row.spam = ${ row.spam }`);
        }

        await ndbi.disconnect();
    }

Drivers

Drivers are manage by the Ndbi.DriverManager class. An instance of this class is created at startup and available at Ndbi.driverManager. This class holds a registry of dsn string prefixes that map to node module names. The following drivers are currently available:

|DSN prefix|Node Module|Description| |---|---|---| |postgres:|ndbi-driver-postgres|NDBI driver that wraps node-postgres|

Other drivers can easily be implemented by using ndbi-driver-postgres as a template. Drivers need to implement constructor and a set of methods that conform to the specifications below.

|Method Name|Required?|Signature|Description| |---|---|---|---| |[[constructor]]|new Driver(dsn: string, username:string|null, password:string|null, options:Object)|Constructor| |beginTransaction|N|driver.beginTransaction(): Promise<undefined>|Puts driver into transaction mode. If this method is omitted it is polyfilled with execute.| |commit|N|driver.commit(): Promise<undefined>|Commits the current transaction. If method is omitted it is polyfilled with execute.| |connect|Y|driver.connect(): Promise<undefined>|Connects to the database and updates driver instance state.| |disconnect|Y|driver.disconnect(): Promise<undefined>|Disconnects from the database and updates driver instance state, reconnection should be allowed.| |execute|N|driver.execute(sql: string, params: Array, options: {}): Promise<Statement>| Executes the sql and parameters and returns an object conforming to the Statement interface that is already resolved. If this method is omitted from the driver, then it is polyfilled using query.| |lastInsertId|Y|driver.lastInsertId(catalog: string|null, schema: string|null, table: string|null, field: string|null): Promise<number>|Retrieves the last insert ID. Driver-dependant, may not be supported by all databases. Reject promise with error if not supported.| |prepare|Y|driver.prepare(sql: string, options:Object): Promise<Statement>|Prepares the statement and returns an object that conforms to the Statement interface.| |query|N|driver.query(sql: string, params: Array, options: {}): Promise<Statement>| Executes the sql and parameters and returns an object conforming to the Statement interface that is already resolved. If this method is omitted from the driver, then it polyfilled using prepare.| |rollback|N|driver.rollback(): Promise<undefined>|Rollsback the current transaction. If method is omitted it is polyfilled via execute.| |transaction|N|driver.transaction(promisor: (function(): Promise)): Promise|Accepts a callback. The callback should return a promise. Begin a transaction, run the callback, wait for it to resolve, and either commit or rollback depending the result of promisor. If this is omitted it is polyfilled via beginTransaction and commit/rollback|

Statements model prepared connections, and the results of an execution. A statement should be executed and then read from. Below is the interface requirements for a Statement:

|Method Name|Signature|Description| |---|---|---| |execute|stmt.execute(params: Array?): Promise<undefined>|Tell DB server to execute prepared statement with optional arguments| |fetchRow|stmt.fetchRow(): Promise<row?>|Pull the next row from an executed statement. Returns undefined when no rows available| |fetchAll|stmt.fetchAll(): Promise<rows>|Fulfill promise with all rows received from server|