Registry / database / dbqb
library1.0.50jsnpmunverified

DBQB v1.0.50 is a lightweight, TypeScript-first MySQL query builder for Node.js that generates parameterized SQL queries (SELECT, INSERT, UPDATE, DELETE, COUNT) using a simple JSON syntax. It supports complex WHERE/Having conditions including operators (>, <, BETWEEN, LIKE, IN, IS NULL), OR/AND nesting via Symbol('OR'), and raw string conditions. Unlike full ORMs like Sequelize or Knex, DBQB focuses solely on query generation without executing queries — you provide getTables/getFields callbacks. Released weekly on npm with TypeScript definitions. Current stable version: 1.0.50. Peer dependency: sequelize ^6.28.0 (only for type compatibility, not runtime).

npm install dbqb
INSTALL
IMPORT
SIG · DBQB
D
dbqb
databasejavascriptv1.0.50
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.

DBQB
✓ import DBQB from 'dbqb'
✗ import { DBQB } from 'dbqb'
Default export only. Named import will cause undefined error.
IFieldItem
✓ import type { IFieldItem } from 'dbqb'
✗ import { IFieldItem } from 'dbqb'
Type import only available in TypeScript. Runtime use will throw.
DBQB
✓ const DBQB = require('dbqb')
✗ const { DBQB } = require('dbqb')
CommonJS require gets the default export. Destructuring from require will fail because the module does not export named members.

Initializes DBQB with table/field introspection callbacks and generates a simple SELECT query.

import DBQB from 'dbqb'; const dbqb = new DBQB({ getTables: () => ['user', 'order'], getFields: (table: string) => [ { Field: 'id', Type: 'int', Null: 'NO', Key: 'PRI', Default: '', Extra: 'auto_increment' }, { Field: 'nick', Type: 'varchar(32)', Null: 'NO', Key: '', Default: '', Extra: '' } ] }); async function example() { const query = await dbqb.selectQuery({ table: 'user', where: { id: 'test' } }); console.log(query); // SELECT * FROM `user` WHERE id = 'test'; } example();
Debug
Known issues
breakingDBQB constructor requires getTables and getFields callbacks; omitting them throws a runtime error.
fix
Always provide both callback functions when instantiating DBQB.
affects: >=1.0.0
gotchaUsing Symbol('OR') or Symbol('AND') in where conditions requires const OR = Symbol('OR') but the library only checks the symbol key. Using a literal Symbol('OR') each time creates a new symbol, but DBQB uses the same symbol instance internally; you must use the same symbol reference.
fix
Define the symbols once: const OR = Symbol('OR'); const AND = Symbol('AND'); and reuse them.
affects: >=1.0.0
gotchaThe 'set' property name in updateQuery and insertUpdateQuery conflicts with JavaScript's Set object. Ensure you use a plain object, not a Set instance.
fix
Use a plain object literal for 'set', e.g., set: { nick: 'new' }.
affects: >=1.0.0
deprecatedQuery methods return a string, not a promise in older versions; async/await is required since v1.0.0.
fix
Upgrade to v1.0.0+ and await all query methods.
affects: <1.0.0
breakingThe getFields callback must return an array of IFieldItem objects with exact fields: Field, Type, Null, Key, Default, Extra. Missing or extra fields will cause unexpected behavior.
fix
Ensure your callback returns objects matching the IFieldItem interface exactly.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: DBQB is not a constructor
Using named import instead of default import: import { DBQB } from 'dbqb'
fix
Change to: import DBQB from 'dbqb'
Cannot find module 'dbqb' or its corresponding type declarations.
Missing sequelize peer dependency or incorrect TypeScript configuration (e.g., no moduleResolution: 'node').
fix
Install sequelize: npm install sequelize. Ensure tsconfig.json has 'moduleResolution': 'node' and 'esModuleInterop': true.
Property 'Symbol' does not exist on type ...
Using Symbol('OR') in TypeScript without declaring a symbol constant; TypeScript errors because Symbol('OR') is not a valid property name.
fix
Use a constant: const OR = Symbol('OR'); then use [OR]: {...}
Upgrade
Version history
1.0.50latest on npm
Audit
Dependencies
sequelizeoptionalPeer dependency required for TypeScript type compatibility (e.g., IFieldItem types). Not used at runtime for query generation.
Agent activity
10 hits · last 30 days
node
8
Resources
packagedbqb ↗
dbqb — npm install dbqb · libregistry