Registry / database / coa-mysql

coa-mysql

JSON →
library1.7.1jsnpmunverified

MySQL database components for the coajs framework, providing basic data models with built-in CRUD, cache data models backed by coa-redis, and distributed UUID generation. Version 1.7.1 is stable with intermittent releases. It wraps the mysql driver and knex query builder, keeping full knex API access via .io. All components are written in TypeScript and support ESM. Compared to standalone knex, it adds model abstractions for rapid CRUD and automatic cache management.

npm install coa-mysql
INSTALL
IMPORT
SIG · COA-MYSQL
C
coa-mysql
databasejavascriptv1.7.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.

MysqlBin
import { MysqlBin } from 'coa-mysql'
const MysqlBin = require('coa-mysql').MysqlBin
ESM-only package; default export is not available, must use named import.
MysqlNative
import { MysqlNative } from 'coa-mysql'
const { MysqlNative } = require('coa-mysql')
ESM-only; used to create basic CRUD models.
MysqlCache
import { MysqlCache } from 'coa-mysql'
Requires coa-redis to be installed; otherwise throws at runtime.

Demonstrates initializing MysqlBin with a config, performing a query via knex, and defining a simple model with MysqlNative to find a record by primary key.

import { MysqlBin, MysqlNative } from 'coa-mysql'; const mysqlConfig = { host: '127.0.0.1', port: 3306, user: 'root', password: process.env.MYSQL_PASSWORD ?? '', charset: 'utf8mb4', databases: { main: { database: 'test', ms: 7 * 24 * 3600 * 1000 }, }, }; const mysqlBin = new MysqlBin(mysqlConfig); // Basic query via knex const users = await mysqlBin.io.table('user').where('status', 1).select(); // Using MysqlNative model class UserModel extends MysqlNative { static tableName = 'user'; static primaryKey = 'userId'; } const user = await UserModel.find('user-a');
Debug
Known issues
breakingVersion 1.0.0 changed from CommonJS to ESM only. Requires Node.js >= 12 and 'type': 'module' in package.json, or use dynamic import().
fix
Update imports to use ESM syntax: import { MysqlBin } from 'coa-mysql'.
affects: >=1.0.0
gotchaMysqlCache requires coa-redis to be installed. If missing, it throws 'Cannot find module \'coa-redis\'' at runtime.
fix
Install coa-redis: yarn add coa-redis or npm install coa-redis.
affects: >=1.0.0
deprecatedThe direct use of mysql driver via .io is not deprecated, but relying on it for complex queries is discouraged in favor of model methods.
fix
Use MysqlNative or MysqlCache model methods for CRUD.
affects: >=1.0.0
gotchaThe config property 'databases' expects an object with database names as keys and objects containing 'database' and 'ms' (cache TTL). Missing or incorrect structure causes silent failures or connection errors.
fix
Ensure 'databases' is provided with at least one entry, e.g., { main: { database: 'test', ms: 3600000 } }.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'coa-redis'
MysqlCache tries to import coa-redis but it is not installed.
fix
Install coa-redis: npm install coa-redis or yarn add coa-redis.
TypeError: MysqlBin is not a constructor
Using CommonJS require with ESM-only package.
fix
Use ES module import: import { MysqlBin } from 'coa-mysql'.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Incorrect MySQL credentials or missing password in config.
fix
Verify MYSQL_PASSWORD environment variable or hardcode correct password in config (not recommended for production).
Upgrade
Version history
1.7.1latest on npm
Audit
Dependencies
mysqlrequiredUnderlying MySQL driver used for connections and queries
knexrequiredSQL query builder exposed via mysqlBin.io
coa-redisoptionalRequired by MysqlCache for automatic cache management
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
coa-mysql — npm install coa-mysql · libregistry