Registry / database / mysql-dbc-table

mysql-dbc-table

JSON →
library0.1.7jsnpmunverified

A lightweight Node.js library for creating and manipulating MySQL tables by inheriting a parent DbTable class. Version 0.1.7, released with no clear cadence. It wraps mysql-dbc for connection management and provides a simple ORM-like interface with field formatting and CRUD operations. Differentiates from heavier ORMs like Sequelize or TypeORM by focusing on table-level abstraction with minimal dependency.

npm install mysql-dbc-table
INSTALL
IMPORT
SIG · MYSQL-DBC-TABLE
M
mysql-dbc-table
databasejavascriptv0.1.7
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.

initDbc
const { initDbc } = require('mysql-dbc-table')
import { initDbc } from 'mysql-dbc-table'
Package is CJS-only, no ESM support as of v0.1.7. Use require().
dbSqlAsync
const { dbSqlAsync } = require('mysql-dbc-table')
const dbSqlAsync = require('mysql-dbc-table').dbSqlAsync
Named export from package root.
DbTable
const { DbTable } = require('mysql-dbc-table')
const DbTable = require('mysql-dbc-table').DbTable
ES6 class, extend for custom models.

Shows how to initialize a MySQL connection, create a table, define a DbTable subclass, and perform a find query.

const { initDbc, dbSqlAsync, DbTable } = require('mysql-dbc-table'); const dbc = initDbc({ host: 'localhost', port: 3306, user: 'root', password: '', database: 'test' }); const sql = 'CREATE TABLE IF NOT EXISTS user (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(64) NOT NULL) ENGINE=InnoDB'; await dbSqlAsync(dbc, sql); class User extends DbTable { static fields() { return { id: { fmt: parseInt }, name: { fmt: String, default: '' } }; } } const userTable = new User('user', dbc); const rows = await userTable.findAsync(); console.log(rows); await dbc.end();
Debug
Known issues
gotchaPackage uses CJS require only; ESM imports will fail.
fix
Use require() or transpile.
affects: >=0.0.0
gotchadbSqlAsync is not promise-based by default; it uses callbacks. Must be promisified if using async/await.
fix
Wrap calls in a Promise or use a wrapper library.
affects: >=0.0.0
gotchaThe package relies on mysql-dbc which has its own quirks; connection pooling not built-in.
fix
Handle connection lifecycle manually.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: initDbc is not a function
Using ES6 import syntax on a CJS module
fix
Change to const { initDbc } = require('mysql-dbc-table')
Cannot read property 'fields' of undefined
DbTable subclass missing static fields() method
fix
Implement static fields() returning an object with field definitions.
Upgrade
Version history
0.1.7latest on npm
Audit
Dependencies
mysql-dbcrequiredCore dependency for MySQL connection and query execution
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-dbc-table — npm install mysql-dbc-table · libregistry