Registry / database / think-mysql

think-mysql

JSON →
library1.4.4jsnpmunverified

MySQL wrapper for ThinkJS framework (v1.4.4, latest). Provides promise-based query/execute methods, connection pooling, transaction support, and logging. Built on mysqljs/mysql. Lightweight alternative to Sequelize/TypeORM for ThinkJS apps. Last updated in 2020; stable but low maintenance.

npm install think-mysql
INSTALL
IMPORT
SIG · THINK-MYSQL
T
think-mysql
databasejavascriptv1.4.4
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
import mysql from 'think-mysql';
const mysql = require('think-mysql');
ESM default import is standard; CommonJS require works but not recommended for modern code.
getInstance
const instance = mysql.getInstance(config);
Factory method to create a new instance with given config.

Demonstrates creating an instance, executing DDL/INSERT, and querying rows with parameterized queries.

import mysql from 'think-mysql'; const config = { host: process.env.DB_HOST ?? '127.0.0.1', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test' }; const instance = mysql.getInstance(config); (async () => { try { await instance.execute({ sql: "CREATE TABLE IF NOT EXISTS `books` (`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(255), `author` VARCHAR(255))" }); await instance.execute({ sql: "INSERT INTO `books` (`name`, `author`) VALUES (?, ?)", values: ['Node.js Design Patterns', 'Mario Casciaro'] }); const rows = await instance.query({ sql: 'SELECT * FROM `books`', values: [] }); console.log('Books:', rows); } catch (err) { console.error('Error:', err); } })();
Debug
Known issues
gotchaDefault configuration sets 'multipleStatements: true', which may expose SQL injection if not carefully handled.
fix
Explicitly set 'multipleStatements: false' if not needed, or ensure all statements are parameterized.
affects: >=1.0.0
breakingPromise-based API; callbacks are not supported. Mixing async/await with .then() may cause unhandled rejections.
fix
Always use async/await or .catch() on promises.
affects: >=1.0.0
gotchaThe 'connectionLimit' default is 1, which limits concurrency. May cause performance issues.
fix
Increase 'connectionLimit' to 10 or more based on workload.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'think-mysql'
Package not installed or import path incorrect.
fix
Run 'npm install think-mysql' and ensure import uses default import.
TypeError: mysql.getInstance is not a function
Using CommonJS require incorrectly or importing wrong symbol.
fix
Use 'import mysql from 'think-mysql'' (ESM) or 'const mysql = require('think-mysql')' (CJS).
ER_ACCESS_DENIED_ERROR: Access denied for user ...
Invalid database credentials or host.
fix
Check DB_HOST, DB_USER, DB_PASS environment variables or config object.
Upgrade
Version history
1.4.4latest on npm
Audit
Dependencies
mysqlrequiredMySQL driver for Node.js; think-mysql wraps its connection pool and queries.
Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
think-mysql — npm install think-mysql · libregistry