Registry / database / dbtabla

dbtabla

JSON →
library2.2.10jsnpmunverified

dbTabla is a high-level abstract interface for generating and executing SQL queries compatible with MySQL, SQLite3, and PostgreSQL. It provides a unified JavaScript API for CRUD operations, model management, and structural metadata inspection across different SQL engines. The current stable version is 2.2.10, released on npm with a monthly release cadence. Key differentiators: fluent insertion syntax, support for both positional and object-based query building, built-in SQL injection prevention via `__escapeString`, and model loading from directories. Requires Node >=18.0.0 and manual implementation of driver-specific methods (query, escape, schema introspection), making it an abstraction layer rather than an ORM.

npm install dbtabla
INSTALL
IMPORT
SIG · DBTABLA
D
dbtabla
databasejavascriptv2.2.10
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.

Connect
import { Connect } from 'dbtabla'
const Connect = require('dbtabla').Connect
ESM only since v2. Package no longer provides CommonJS exports.
dbTabla
import { dbTabla } from 'dbtabla'
const { dbTabla } = require('dbtabla')
Class representing a table. Requires ESM import. Cannot be instantiated directly; use Connect#tabla().
dbRow
import { dbRow } from 'dbtabla'
Class representing a single row. Available since v2.
MYSQL_DB
import { MYSQL_DB } from 'dbtabla'
const { MYSQL_DB } = require('dbtabla')
Constant for MySQL driver type. Used in Connect constructor.
connect
import { connect } from 'dbtabla'
import { Connect } from 'dbtabla'
deprecated alias for Connect. Use Connect instead. Removed in v3.

Shows how to extend the Connect class with a MySQL adapter, instantiate it, and perform an insert operation using the fluent API.

import { Connect, MYSQL_DB } from 'dbtabla'; class MySqlTable extends Connect { constructor(params) { super(params, MYSQL_DB); // Initialize MySQL connection... } query(sql) { // Execute SQL and return promise return Promise.resolve([]); } __escapeString(str) { return str.replace(/'/g, "''"); } __keysInTable(table) { return Promise.resolve({ tabla: table, colums: [{ name: 'id', type: 'INTEGER', defaultNull: false, primary: true, unique: true, defaul: '', autoincrement: true }] }); } } const conn = new MySqlTable({ host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '' }); const usuarios = conn.tabla('usuarios'); usuarios.insert({ nombre: 'Juan', rol: 'Admin' }).then(console.log);
Debug
Known issues
breakingPackage switched from CommonJS to ES modules only in v2.0.0. require() will not work and throws MODULE_NOT_FOUND.
fix
Use import statements. If you must use CommonJS, downgrade to v1.x or use dynamic import().
affects: >=2.0.0
deprecatedThe export 'connect' (lowercase) is deprecated since v2.5.0. Use 'Connect' (uppercase) instead.
fix
Replace import { connect } with import { Connect }.
affects: >=2.5.0
gotchaThe insert() method does not validate input types. Passing undefined or null as field values may produce unexpected SQL.
fix
Always pass defined values. Use conditional checks before calling insert().
affects: *
gotcha__keysInTable must return a promise with an object containing key 'colums' (misspelled). The misspelling is intentional and consistent; using 'columns' will break metadata parsing.
fix
Ensure your __keysInTable implementation uses the exact property name 'colums' (no 'n').
affects: *
gotchaNode engine requirement is >=18.0.0. Using older Node versions may cause runtime errors due to missing ESM support.
fix
Upgrade Node.js to version 18 or later.
affects: >=2.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/dbtabla/index.js not supported.
Package is ESM-only since v2. Using require() in a CommonJS file.
fix
Use import or convert your project to ESM (add 'type':'module' to package.json, or use .mjs extension).
TypeError: (intermediate value).tabla is not a function
Forgetting to extend the Connect class and calling tabla() on a raw instance without constructor logic.
fix
Ensure you subclass Connect and provide the required methods (query, __escapeString, __keysInTable).
UnhandledPromiseRejectionWarning: TypeError: __keysInTable is not a function
The method __keysInTable was not defined in the subclass of Connect.
fix
Add __keysInTable method to your subclass that returns a promise with the correct schema object.
Cannot find module 'mysql'
Missing optional dependency for MySQL driver.
fix
Run 'npm install mysql' if using MySQL adapter.
Upgrade
Version history
2.2.10latest on npm
Audit
Dependencies
mysqloptionalRequired for MySQL adapter implementation
sqlite3optionalRequired for SQLite adapter implementation
pgoptionalRequired for PostgreSQL adapter implementation
Agent activity
11 hits · last 30 days
node
10
Resources
dbtabla — npm install dbtabla · libregistry