Registry / database / tabla-model

tabla-model

JSON →
library2.0.6jsnpmunverified

Declarative SQL table model definition and SQL generation for the dbtabla ecosystem. Version 2.0.6 supports MySQL, SQLite, and PostgreSQL via adapters (mysql-tab, sqlite3-tab, pg-table). Features include model methods, seed data, reverse engineering, and advanced filtering with comparison operators. Requires Node >=18.

npm install tabla-model
INSTALL
IMPORT
SIG · TABLA-MODEL
T
tabla-model
databasejavascriptv2.0.6
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.

Model
const Model = require('tabla-model');
import Model from 'tabla-model';
Library uses CommonJS and does not provide ESM exports. Using ESM import will fail.
new Model(name, schema)
const userModel = new Model('users', { columns: [...] });
const userModel = Model('users', { columns: [...] });
Model must be instantiated with 'new'; calling without 'new' will throw.
foreingKey
new Model('orders', { foreingKey: [{ key: 'user_id', reference: 'users', keyReference: 'id', onDelete: 'CASCADE' }] });
new Model('orders', { foreignKey: [...] });
The schema property is spelled 'foreingKey' (missing 'i' in 'foreign'). Using the correct spelling will not work.

Demonstrates creating a model, defining columns and foreign keys, adding a custom method, and generating CREATE TABLE SQL.

const Model = require('tabla-model'); const UsuarioModel = new Model('usuarios', { colums: [ { name: 'id', type: 'int', primary: true, autoincrement: true }, { name: 'username', type: 'varchar(50)', defaultNull: false, unique: true }, { name: 'email', type: 'varchar(100)' }, { name: 'puntos', type: 'int', default: 0 } ], foreingKey: [ { key: 'id_perfil', reference: 'perfiles', keyReference: 'id', onDelete: 'CASCADE' } ] }); UsuarioModel.method('getByPuntos', async (tabla, db, minPuntos, limit = 10) => { return await tabla.select('*', `puntos > ${minPuntos}`, 'puntos DESC', limit); }); console.log(UsuarioModel.sqlCreate());
Debug
Known issues
gotchaSchema property 'foreingKey' is misspelled (missing 'i' in 'foreign').
fix
Use 'foreingKey' (as library expects) instead of 'foreignKey'.
affects: >=2.0.0
gotchaColumn property 'colums' is misspelled (should be 'columns' but library uses 'colums').
fix
Use 'colums' in schema definition.
affects: >=2.0.0
breakingNode.js >=18.0.0 required; older versions are not supported.
fix
Upgrade Node.js to version 18 or later.
affects: >=2.0.0
gotchaLibrary uses CommonJS; no ESM exports. Attempting ESM import will fail.
fix
Use require('tabla-model') instead of import.
affects: >=2.0.0
gotchaModel must be instantiated with 'new'. Calling without 'new' will throw or misbehave.
fix
Always use 'new Model(...)'.
affects: >=2.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/tabla-model/index.js from /path/to/app.js not supported.
Trying to ESM-import a CommonJS-only library using import statement.
fix
Change to const Model = require('tabla-model');
TypeError: Model is not a constructor
Calling Model as a function without 'new'.
fix
Use new Model(name, schema).
Cannot read properties of undefined (reading 'colums')
Schema object is missing 'colums' property (misspelled or wrong key).
fix
Ensure schema has a 'colums' array (not 'columns').
Upgrade
Version history
2.0.6latest on npm
Audit
Dependencies
mysql-taboptionalRequired to use models with MySQL/MariaDB
sqlite3-taboptionalRequired to use models with SQLite3
pg-tableoptionalRequired to use models with PostgreSQL
Agent activity
21 hits · last 30 days
node
18
Meta
1
OpenAI (training)
1
Resources
tabla-model — npm install tabla-model · libregistry