Registry / database / mysqlconnector

mysqlconnector

JSON →
library2.0.6jsnpmunverified

A TypeScript-friendly MySQL helper library (v2.0.6) built on top of the popular mysqljs/mysql package. It provides Promise-based async/await support for connections, queries, and transactions, along with fluent query builders for SELECT, UPDATE, INSERT, DELETE, and other operations. The library emphasizes ease of use with DbContext and automatic transaction commit/rollback. Key differentiators include built-in TypeScript type definitions, a simple query builder API, and a focus on reducing boilerplate for common MySQL operations. However, it is not actively maintained (last release 2019) and has limited community adoption compared to alternatives like mysql2 or knex.

npm install mysqlconnector
INSTALL
IMPORT
SIG · MYSQLCONNECTOR
M
mysqlconnector
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.

MySqlConnection
import { MySqlConnection } from 'mysqlconnector'
const mysqlconnector = require('mysqlconnector')
ESM and CommonJS both supported. Default export is not available; use named import.
DbContext
import { DbContext } from 'mysqlconnector'
DbContext is a wrapper around MySqlConnection providing transaction management. Must be instantiated with a MySqlConnection instance.
Select
import { Select } from 'mysqlconnector'
const Select = require('mysqlconnector').Select
CommonJS require is possible but prefer named import for TypeScript types. Select is a factory class for building SELECT queries.
Update
import { Update } from 'mysqlconnector'
Same pattern as Select. Provides fromModel() to build UPDATE from object.

Demonstrates connecting to MySQL, executing a query, and closing the connection using async/await.

import { MySqlConnection } from 'mysqlconnector'; const connection = new MySqlConnection({ hostname: process.env.MYSQL_HOST ?? 'localhost', username: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DB ?? 'test' }); async function main() { await connection.connectAsync(); const rows = await connection.queryAsync('SELECT * FROM users'); console.log(rows); await connection.closeAsync(); } main().catch(console.error);
Debug
Known issues
deprecatedPackage has not been updated since 2019. Consider using mysql2 or knex.
fix
Migrate to mysql2 with its promise API or use an ORM like Sequelize/TypeORM.
affects: >=2.0.0
gotchaThe underlying mysqljs/mysql package is not maintained and has known security issues.
fix
Switch to mysql2 which fixes those issues.
affects: >=2.0.0
gotchaConnection options use 'hostname' not 'host'.
fix
Use hostname property when creating connection.
affects: >=2.0.0
breakingQuery builder methods are static; do not instantiate Select (e.g., `new Select()` is incorrect).
fix
Use `Select.Table(...)` or `Select.Properties(...)` directly.
affects: >=2.0.0
gotchaTransaction rollback happens automatically on any error; must catch exceptions to prevent silent failures.
fix
Wrap transaction code in try-catch and handle rollback logic manually if needed.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'mysql'
Missing peer dependency mysql.
fix
Run: npm install mysql
TypeError: connection.connectAsync is not a function
Using CommonJS require instead of named import.
fix
Use: import { MySqlConnection } from 'mysqlconnector'
Property 'Table' does not exist on type 'typeof Select'
Using TypeScript without enabling esModuleInterop or using wrong import.
fix
Ensure tsconfig has esModuleInterop: true and import { Select } correctly.
Upgrade
Version history
2.0.6latest on npm
Audit
Dependencies
mysqlrequiredCore dependency for MySQL protocol implementation; the library wraps mysqljs/mysql.
Agent activity
2 hits · last 30 days
node
2
Resources
mysqlconnector — npm install mysqlconnector · libregistry