Registry / database / mysql-tab

mysql-tab

JSON →
library2.1.1jsnpmunverified

High-level MySQL/MariaDB ORM for Node.js using an Active Record pattern. Current version 2.1.1, with updates via npm. Provides full CRUD abstraction, automatic schema synchronization, a fluent query builder with dynamic join support, atomic transactions, and a CLI for reverse engineering. Part of the dbtabla ecosystem, it requires Node >=18 and works alongside tabla-model for schema definition. Key differentiator: query results are smart objects with .update() and .delete() methods, and .select() supports polymorphic filtering with special prefix/suffix operators.

npm install mysql-tab
INSTALL
IMPORT
SIG · MYSQL-TAB
M
mysql-tab
databasejavascriptv2.1.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.

MySQL
const MySQL = require('mysql-tab')
import MySQL from 'mysql-tab'
This package uses CommonJS and does not expose a default ESM export. Use require in Node.js.
MySQL instance
const db = new MySQL({...})
const db = new mysql({...})
The constructor is called with 'MySQL' (uppercase) from the package, not 'mysql'.
select method
db.tabla('users').select('id > 10')
db.tabla('users').select({where: 'id > 10'})
The .select() method accepts filter strings directly as first argument, not an object with a 'where' property.

Shows required CommonJS import, connection with environment variable for password, and basic insert/select operations.

const MySQL = require('mysql-tab'); const db = new MySQL({ host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'mi_proyecto' }); async function main() { await db.connect(); const usuarios = db.tabla('usuarios'); await usuarios.insert({ nombre: 'Antigravity', email: 'ai@dev.com' }); const resultado = await usuarios.select('id > 0'); console.log(resultado); } main().catch(console.error);
Debug
Known issues
deprecatedUse of positional insert (e.g., await usuarios.insert(null, 'name', 'email')) is ambiguous and may be removed in the future.
fix
Always use object form: await usuarios.insert({ nombre: 'name', email: 'email' }).
affects: >=2.0.0
breakingNode.js versions below 18 are not supported as of v2.0.0.
fix
Upgrade Node.js to v18 or later.
affects: >=2.0.0
gotchaThe .select() method's where object uses special prefix/suffix operators (e.g., 'campo%' for LIKE, '||campo' for OR). Misunderstanding these can lead to incorrect queries.
fix
Read the documentation on filter syntax carefully. Use plain strings for simple equality.
affects: >=2.0.0
deprecatedtabla-model is optional but recommended for schema management. Using mysql-tab without it means you must manually create tables.
fix
Install tabla-model and call db.pathModels() to register model definitions.
affects: >=1.0.0
gotchaThe .update() method on a row object does not automatically save changes; you must call it explicitly with the updated data.
fix
Use: row.update({ campo: 'nuevo_valor' });
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mysql-tab'
Package not installed or wrong import syntax (ESM import used instead of require).
fix
Run 'npm install mysql-tab' and use const MySQL = require('mysql-tab');
TypeError: db.tabla is not a function
db is not connected or not an instance of MySQL.
fix
Ensure you called new MySQL(config) and then await db.connect();
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server is not running or credentials are wrong.
fix
Start MySQL service and check host/port/user/password in config.
Error: ER_NO_SUCH_TABLE: Table 'mi_proyecto.usuarios' doesn't exist
Table not created. mysql-tab does not auto-create tables without tabla-model schema definitions.
fix
Define models with tabla-model and call db.pathModels(), or create the table manually with SQL.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies
tabla-modeloptionalRequired for defining model schemas with automatic table synchronization.
mysql2requiredProvides low-level MySQL driver for database connectivity.
Agent activity
4 hits · last 30 days
node
4
Resources
mysql-tab — npm install mysql-tab · libregistry