Registry / database / mysql-tk

mysql-tk

JSON →
library1.0.10jsnpmunverified

A thin wrapper around the MySQL npm package providing a fluent query builder API for Node.js. Current stable version is 1.0.10, with low release cadence (last update in 2017). It simplifies CRUD operations with chainable methods like .where(), .fields(), .limit(), .order(), .count(), .find(), .select(), .add(), .update(), .delete(). Compared to knex or Sequelize, mysql-tk offers minimal abstraction with no ORM, making it suitable for quick scripts but lacking modern features like connection pooling, migrations, or TypeScript support.

npm install mysql-tk
INSTALL
IMPORT
SIG · MYSQL-TK
M
mysql-tk
databasejavascriptv1.0.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.

default (MysqlTK)
const MysqlTK = require('mysql-tk');
const { MysqlTK } = require('mysql-tk');
Module uses CommonJS, not named export.
MysqlTK as query builder
MysqlTK('tablename').find(callback);
MysqlTK().find(callback);
MysqlTK requires a table name argument; calling without it will fail.
CONFIG
MysqlTK.CONFIG = { ... };
MysqlTK.CONFIG({ ... });
CONFIG is a direct assignment property, not a function.

Demonstrates setting up mysql-tk with configuration, inserting a record, and querying with a where clause.

const MysqlTK = require('mysql-tk'); MysqlTK.CONFIG = { host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'test' }; // Insert a record MysqlTK('users') .add({ name: 'Alice', email: 'alice@example.com' }, (res) => { console.log('Insert ID:', res.insertId); }); // Query with conditions MysqlTK('users') .where('email', 'alice@example.com') .find((data) => { console.log('Found:', data); });
Debug
Known issues
gotchaAll queries rely on callbacks; no Promise/async-await support without manual wrapping.
fix
Wrap in a Promise: new Promise((resolve, reject) => MysqlTK('t')...)
affects: >=1.0.0
deprecatedPackage uses the deprecated 'mysql' package which lacks modern features like prepared statements and connection pooling.
fix
Consider migrating to 'mysql2' and switching to a more active wrapper.
affects: >=1.0.0
gotchaCONFIG must be set before any query; setting it after a query may not take effect until restart.
fix
Set CONFIG immediately after require().
affects: >=1.0.0
gotchaNo connection pooling; each query opens a new connection unless managed manually.
fix
Use a separate connection pool from 'mysql' package and pass it to mysql-tk? (Not supported out of box.)
affects: >=1.0.0
gotchaMethods without callback (e.g., .where(), .fields(), .order()) return the MysqlTK instance for chaining, but final action methods (find, select, count, add, update, delete) require a callback.
fix
Always pass a callback to terminal methods.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: MysqlTK is not a function
Using named import instead of default import.
fix
Use: const MysqlTK = require('mysql-tk');
TypeError: Cannot read property 'CONFIG' of undefined
Attempting to call MysqlTK.CONFIG as a function.
fix
Assign directly: MysqlTK.CONFIG = { ... };
Error: getaddrinfo ENOTFOUND localhost
MySQL server is not running or hostname is incorrect.
fix
Ensure MySQL is running and host is correct (e.g., '127.0.0.1' instead of 'localhost').
TypeError: callback is not a function
Terminal method called without a callback.
fix
Add a callback: .find((data) => console.log(data));
Upgrade
Version history
1.0.10latest on npm
Audit
Dependencies
mysqlrequiredmysql-tk is a wrapper around the mysql npm package for database operations.
Agent activity
6 hits · last 30 days
node
6
Resources
mysql-tk — npm install mysql-tk · libregistry