Registry / database / db3
library4.2.1jsnpmunverified

Db3 is a Node.js MySQL client (v4.2.1, stable) that replaces raw SQL queries with clean, readable method calls for common database operations like CRUD, schema management, and aggregate functions. It wraps the node-mysql library and targets developers who prefer an ORM-like API without full SQL knowledge. Key differentiators include shorthand methods for table operations and auto-inference of field types (e.g., 'id' becomes bigint primary key auto_increment). It uses callbacks (not Promises) and supports streaming. Node >= 4.0 required. Php alternative: Medoo.

npm install db3
INSTALL
IMPORT
SIG · DB3
D
db3
databasejavascriptv4.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

db3
✓ const db3 = require('db3')
✗ import db3 from 'db3'
CJS module; ESM import is not supported. Default export is a function.
connect
✓ const db = db3.connect({host:'localhost', user:'root', password:'', database:'test'})
✗ const db = require('db3').connect({...})
connect is a method on the default export, not a named export.
end
✓ db.end(callback)
✗ db.close()
Call end() to gracefully close all connections; no close() method exists.

Connects to MySQL, creates a table, inserts a row, selects all rows, and disconnects (all callbacks).

const db3 = require('db3'); const db = db3.connect({ host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test' }); db.createTable('person', ['id', 'name', 'gender'], (err, data) => { if (err) throw err; console.log('table created'); db.insert('person', {name: 'Alice', gender: 'female'}, (err, result) => { if (err) throw err; console.log('Inserted id:', result.insertId); db.select('person', (err, rows) => { if (err) throw err; console.log('Rows:', rows); db.end(() => console.log('done')); }); }); });
Debug
Known issues
gotchaField names ending with 'Id' (case-insensitive) are automatically treated as bigint, not text.
fix
Use explicit SQL queries via db.query() if you need different types for such fields.
affects: >=1.0.0
gotchaAll methods are callback-based; promises/async-await require manual wrapping.
fix
Use util.promisify or wrap calls in Promises for async/await usage.
affects: >=1.0.0
gotchaThe `id` field in createTable is always bigint primary key auto_increment, overriding any custom type.
fix
Use db.query() to create tables with custom column definitions.
affects: >=1.0.0
gotchadb3 requires Node >= 4.0; older Node versions fail to install.
fix
Upgrade Node to version 4.0 or later.
affects: >=4.0.0
gotchaAll queries go through a single connection pool; concurrent long-running queries may exhaust pool size.
fix
Configure pool size via connection options (e.g., connectionLimit) passed to mysql.createPool.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'db3'
db3 not installed or package.json missing dependency.
fix
Run `npm install db3` and ensure node_modules contains db3.
TypeError: db3.connect is not a function
Incorrect import; likely used named import in ESM or missed requiring db3.
fix
Use `const db3 = require('db3')` and then `db3.connect(...)`.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user '...'
Invalid MySQL credentials or host.
fix
Check DB_HOST, DB_USER, DB_PASS environment variables or connection options.
TypeError: db.end is not a function
db variable is not the connection object (e.g., used db3 instead of db).
fix
Ensure you assigned the result of db3.connect() to a variable (e.g., const db = db3.connect(...)).
Error: ER_BAD_DB_ERROR: Unknown database '...'
Database specified does not exist.
fix
Create the database first: `CREATE DATABASE yourdb;` or specify an existing database.
Upgrade
Version history
4.2.1latest on npm
Audit
Dependencies
mysqlrequiredUnderlying MySQL driver; db3 wraps node-mysql's connection pool via mysql.createPool.
Agent activity
14 hits · last 30 days
node
12
Resources
packagedb3 ↗
db3 — npm install db3 · libregistry