{"id":44038,"library":"think-mysql","title":"think-mysql","description":"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.","status":"maintenance","version":"1.4.4","language":"javascript","source_language":"en","source_url":"https://github.com/thinkjs/think-mysql","tags":["javascript"],"install":[{"cmd":"npm install think-mysql","lang":"bash","label":"npm"},{"cmd":"yarn add think-mysql","lang":"bash","label":"yarn"},{"cmd":"pnpm add think-mysql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"MySQL driver for Node.js; think-mysql wraps its connection pool and queries.","package":"mysql","optional":false}],"imports":[{"note":"ESM default import is standard; CommonJS require works but not recommended for modern code.","wrong":"const mysql = require('think-mysql');","symbol":"default","correct":"import mysql from 'think-mysql';"},{"note":"Factory method to create a new instance with given config.","wrong":null,"symbol":"getInstance","correct":"const instance = mysql.getInstance(config);"}],"quickstart":{"code":"import mysql from 'think-mysql';\n\nconst config = {\n  host: process.env.DB_HOST ?? '127.0.0.1',\n  user: process.env.DB_USER ?? 'root',\n  password: process.env.DB_PASS ?? '',\n  database: process.env.DB_NAME ?? 'test'\n};\n\nconst instance = mysql.getInstance(config);\n\n(async () => {\n  try {\n    await instance.execute({\n      sql: \"CREATE TABLE IF NOT EXISTS `books` (`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(255), `author` VARCHAR(255))\"\n    });\n    await instance.execute({\n      sql: \"INSERT INTO `books` (`name`, `author`) VALUES (?, ?)\",\n      values: ['Node.js Design Patterns', 'Mario Casciaro']\n    });\n    const rows = await instance.query({\n      sql: 'SELECT * FROM `books`',\n      values: []\n    });\n    console.log('Books:', rows);\n  } catch (err) {\n    console.error('Error:', err);\n  }\n})();","lang":"javascript","description":"Demonstrates creating an instance, executing DDL/INSERT, and querying rows with parameterized queries."},"warnings":[{"fix":"Explicitly set 'multipleStatements: false' if not needed, or ensure all statements are parameterized.","message":"Default configuration sets 'multipleStatements: true', which may expose SQL injection if not carefully handled.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use async/await or .catch() on promises.","message":"Promise-based API; callbacks are not supported. Mixing async/await with .then() may cause unhandled rejections.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Increase 'connectionLimit' to 10 or more based on workload.","message":"The 'connectionLimit' default is 1, which limits concurrency. May cause performance issues.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2020':36 'altern':27 'app':32 'base':14 'built':23 'connect':17 'framework':8 'javascript':41 'last':33 'latest':10 'lightweight':26 'log':22 'low':39 'mainten':40 'method':16 'mysql':3,4 'mysqljs/mysql':25 'pool':18 'promis':13 'promise-bas':12 'provid':11 'query/execute':15 'sequelize/typeorm':29 'stabl':37 'support':20 'think':2 'think-mysql':1 'thinkj':7,31 'transact':19 'updat':34 'v1.4.4':9 'wrapper':5","created_at":"2026-06-05T17:02:40.499095+00:00","updated_at":"2026-06-05T17:02:40.499095+00:00","problems":[{"fix":"Run 'npm install think-mysql' and ensure import uses default import.","cause":"Package not installed or import path incorrect.","error":"Cannot find module 'think-mysql'"},{"fix":"Use 'import mysql from 'think-mysql'' (ESM) or 'const mysql = require('think-mysql')' (CJS).","cause":"Using CommonJS require incorrectly or importing wrong symbol.","error":"TypeError: mysql.getInstance is not a function"},{"fix":"Check DB_HOST, DB_USER, DB_PASS environment variables or config object.","cause":"Invalid database credentials or host.","error":"ER_ACCESS_DENIED_ERROR: Access denied for user ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/thinkjs/think-mysql#readme","github":"https://github.com/thinkjs/think-mysql","docs":null,"changelog":null,"pypi":null,"npm":"think-mysql","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}