New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ndbi

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ndbi

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

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
7
Maintainers
1
Weekly downloads
 
Created
Source

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 prefixNode ModuleDescription
postgres:ndbi-driver-postgresNDBI 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 NameRequired?SignatureDescription
[[constructor]]`new Driver(dsn: string, username:stringnull, password:stringnull, options:Object)`
beginTransactionNdriver.beginTransaction(): Promise<undefined>Puts driver into transaction mode. If this method is omitted it is polyfilled with execute.
commitNdriver.commit(): Promise<undefined>Commits the current transaction. If method is omitted it is polyfilled with execute.
connectYdriver.connect(): Promise<undefined>Connects to the database and updates driver instance state.
disconnectYdriver.disconnect(): Promise<undefined>Disconnects from the database and updates driver instance state, reconnection should be allowed.
executeNdriver.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.
lastInsertIdY`driver.lastInsertId(catalog: stringnull, schema: string
prepareYdriver.prepare(sql: string, options:Object): Promise<Statement>Prepares the statement and returns an object that conforms to the Statement interface.
queryNdriver.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.
rollbackNdriver.rollback(): Promise<undefined>Rollsback the current transaction. If method is omitted it is polyfilled via execute.
transactionNdriver.transaction(promisor: (function(): Promise)): PromiseAccepts 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 NameSignatureDescription
executestmt.execute(params: Array?): Promise<undefined>Tell DB server to execute prepared statement with optional arguments
fetchRowstmt.fetchRow(): Promise<row?>Pull the next row from an executed statement. Returns undefined when no rows available
fetchAllstmt.fetchAll(): Promise<rows>Fulfill promise with all rows received from server

FAQs

Package last updated on 28 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts