{ } qjs-modules

dbi

Source: lib/dbi.js

A light database-independent layer over the sqlite, mysql and pgsql bindings, after Perl DBI and libdbi: one Database and Result API whatever the driver.

import { Database } from 'dbi';

const db = await Database.connect('sqlite', 'file.db');   // or { filename } / ':memory:'
const res = await db.query('SELECT * FROM t');

for await(const row of res) console.log(row);

Database.register(name, Adapter) adds a driver, Database.connect(driver, options) opens one: SQLite takes a file name or { filename }, MySQL and PostgreSQL take { host, user, password, database, port }. A Result is async-iterable and has all() and fetchFields().

Export list

Generated by utilities/doc-api.js from the dbi dump of utilities/api-surface.sh: 28 members. Edit the text above this block, not the block.

Database

class, constructible

  • static methods: connect(), register()
  • methods: close(), exec(), insertQuery(), query(), quote()
  • properties: affectedRows (get), insertId (get)

Result

class, constructible

  • methods: all(), fetchFields(), [Symbol.asyncIterator]()
  • properties: numFields (get)

default

class, constructible

  • static methods: connect(), register()
  • methods: close(), exec(), insertQuery(), query(), quote()
  • properties: affectedRows (get), insertId (get)