Registry / database / slim-node-mysql

slim-node-mysql

JSON →
library4.0.3jsnpmunverified

A lightweight MySQL database abstraction layer for Node.js that simplifies pooling and prepared statements. Version 4.0.3 is the current stable release, with semi-regular updates from a single maintainer. It wraps the popular mysql2 driver, providing an async/await interface with named parameter support (using @param syntax) and TypeScript type definitions built-in. Key differentiators: no external dependencies beyond mysql2, minimal API surface with methods like query(), execute(), getOne(), getValue(), and exists(), and automatic connection pooling via a single class instance. Suitable for small-to-medium projects wanting a thin wrapper without ORM overhead.

npm install slim-node-mysql
INSTALL
IMPORT
SIG · SLIM-NODE-MYSQL
S
slim-node-mysql
databasejavascriptv4.0.3
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.

SlimNodeMySQL
import { SlimNodeMySQL } from 'slim-node-mysql'
const SlimNodeMySQL = require('slim-node-mysql')
Named export in TypeScript; common mistake is using default import.
ExecuteResult
import { ExecuteResult } from 'slim-node-mysql'
import ExecuteResult from 'slim-node-mysql'
TypeScript type export; not a value.
slimNodeMySQL instance method: query
const rows = await database.query<User>('SELECT * FROM users WHERE id = @id', { id: 1 })
database.query('SELECT * FROM users WHERE id = ?', [1])
Uses named parameters (@param) not positional (?).

Demonstrates creating a SlimNodeMySQL instance, then using the five main methods: query, execute, getOne, getValue, and exists with named parameters.

import { SlimNodeMySQL } from 'slim-node-mysql'; const db = new SlimNodeMySQL(process.env.MYSQL_CONNECTION_STRING || 'mysql://user:pass@localhost:3306/db'); async function main() { // query const users = await db.query<{ id: number; name: string }>('SELECT id, name FROM users WHERE active = @active', { active: true }); console.log(users); // insert const result = await db.execute('INSERT INTO users (name) VALUES (@name)', { name: 'Alice' }); console.log(`Inserted with id: ${result.insertId}`); // getOne const user = await db.getOne<{ id: number; name: string }>('SELECT id, name FROM users WHERE id = @id LIMIT 1', { id: 1 }); console.log(user); // getValue const name = await db.getValue<{ name: string }, 'name'>('name', 'SELECT name FROM users WHERE id = @id', { id: 1 }); console.log(name); // exists const exists = await db.exists('SELECT id FROM users WHERE id = @id', { id: 1 }); console.log(exists); } main().catch(console.error);
Debug
Known issues
gotchaAll parameters must use @param syntax; placeholder positions (?) are not supported.
fix
Replace ? placeholders with @paramName and pass an object with matching keys.
affects: >=1.0.0
gotchaThe query method always returns an array; for a single row use getOne.
fix
Use getOne() when expecting at most one result row.
affects: >=1.0.0
deprecatedThe method 'execute' for SELECT queries is deprecated; use 'query' instead.
fix
Use database.query() for SELECT statements to get typed results.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find name 'SlimNodeMySQL'
Forgetting to import or using wrong import syntax in TypeScript.
fix
Use: import { SlimNodeMySQL } from 'slim-node-mysql';
TypeError: db.query is not a function
Using require and not calling new correctly, or importing default instead of named export.
fix
Ensure correct import: const { SlimNodeMySQL } = require('slim-node-mysql'); then const db = new SlimNodeMySQL(connectionString);
Error: ER_PARSE_ERROR: You have an error in your SQL syntax near '@active'
Using @param in a context where mysql2 doesn't parse it; usually because the query is passed without param object.
fix
Pass the parameters object as second argument to query/execute/getOne/getValue/exists.
Upgrade
Version history
4.0.3latest on npm
Audit
Dependencies
mysql2requiredUnderlying MySQL driver; handles database connection and protocol
Agent activity
8 hits · last 30 days
node
6
Meta
1
Amazon
1
Resources
slim-node-mysql — npm install slim-node-mysql · libregistry