{"id":42605,"library":"db3","title":"Db3","description":"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.","status":"active","version":"4.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/afanasy/db3","tags":["javascript"],"install":[{"cmd":"npm install db3","lang":"bash","label":"npm"},{"cmd":"yarn add db3","lang":"bash","label":"yarn"},{"cmd":"pnpm add db3","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying MySQL driver; db3 wraps node-mysql's connection pool via mysql.createPool.","package":"mysql","optional":false}],"imports":[{"note":"CJS module; ESM import is not supported. Default export is a function.","wrong":"import db3 from 'db3'","symbol":"db3","correct":"const db3 = require('db3')"},{"note":"connect is a method on the default export, not a named export.","wrong":"const db = require('db3').connect({...})","symbol":"connect","correct":"const db = db3.connect({host:'localhost', user:'root', password:'', database:'test'})"},{"note":"Call end() to gracefully close all connections; no close() method exists.","wrong":"db.close()","symbol":"end","correct":"db.end(callback)"}],"quickstart":{"code":"const db3 = require('db3');\nconst db = db3.connect({\n  host: process.env.DB_HOST ?? 'localhost',\n  user: process.env.DB_USER ?? 'root',\n  password: process.env.DB_PASS ?? '',\n  database: process.env.DB_NAME ?? 'test'\n});\ndb.createTable('person', ['id', 'name', 'gender'], (err, data) => {\n  if (err) throw err;\n  console.log('table created');\n  db.insert('person', {name: 'Alice', gender: 'female'}, (err, result) => {\n    if (err) throw err;\n    console.log('Inserted id:', result.insertId);\n    db.select('person', (err, rows) => {\n      if (err) throw err;\n      console.log('Rows:', rows);\n      db.end(() => console.log('done'));\n    });\n  });\n});","lang":"javascript","description":"Connects to MySQL, creates a table, inserts a row, selects all rows, and disconnects (all callbacks)."},"warnings":[{"fix":"Use explicit SQL queries via db.query() if you need different types for such fields.","message":"Field names ending with 'Id' (case-insensitive) are automatically treated as bigint, not text.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use util.promisify or wrap calls in Promises for async/await usage.","message":"All methods are callback-based; promises/async-await require manual wrapping.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use db.query() to create tables with custom column definitions.","message":"The `id` field in createTable is always bigint primary key auto_increment, overriding any custom type.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node to version 4.0 or later.","message":"db3 requires Node >= 4.0; older Node versions fail to install.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Configure pool size via connection options (e.g., connectionLimit) passed to mysql.createPool.","message":"All queries go through a single connection pool; concurrent long-running queries may exhaust pool size.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'4.0':84 'aggreg':29 'altern':87 'api':47 'auto':62,73 'auto-infer':61 'becom':69 'bigint':70 'call':19 'callback':77 'clean':16 'client':7 'common':21 'crud':25 'databas':22 'db3':1,2 'develop':40 'differenti':53 'e.g':67 'field':65 'full':49 'function':30 'id':68 'includ':54 'increment':74 'infer':63 'javascript':89 'key':52,72 'knowledg':51 'librari':37 'like':24,46 'manag':27 'medoo':88 'method':18,56 'mysql':6,36 'node':35,83 'node-mysql':34 'node.js':5 'oper':23,59 'orm':45 'orm-lik':44 'php':86 'prefer':42 'primari':71 'promis':79 'queri':14 'raw':12 'readabl':17 'replac':11 'requir':85 'schema':26 'shorthand':55 'sql':13,50 'stabl':9 'stream':82 'support':81 'tabl':58 'target':39 'type':66 'use':76 'v4.2.1':8 'without':48 'wrap':32","created_at":"2026-06-05T16:55:47.004752+00:00","updated_at":"2026-06-05T16:55:47.004752+00:00","problems":[{"fix":"Run `npm install db3` and ensure node_modules contains db3.","cause":"db3 not installed or package.json missing dependency.","error":"Cannot find module 'db3'"},{"fix":"Use `const db3 = require('db3')` and then `db3.connect(...)`.","cause":"Incorrect import; likely used named import in ESM or missed requiring db3.","error":"TypeError: db3.connect is not a function"},{"fix":"Check DB_HOST, DB_USER, DB_PASS environment variables or connection options.","cause":"Invalid MySQL credentials or host.","error":"Error: ER_ACCESS_DENIED_ERROR: Access denied for user '...'"},{"fix":"Ensure you assigned the result of db3.connect() to a variable (e.g., const db = db3.connect(...)).","cause":"db variable is not the connection object (e.g., used db3 instead of db).","error":"TypeError: db.end is not a function"},{"fix":"Create the database first: `CREATE DATABASE yourdb;` or specify an existing database.","cause":"Database specified does not exist.","error":"Error: ER_BAD_DB_ERROR: Unknown database '...'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/afanasy/db3","github":"https://github.com/afanasy/db3","docs":null,"changelog":null,"pypi":null,"npm":"db3","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}