Registry / database / dlovely-mysql

dlovely-mysql

JSON →
library2.2.2jsnpmunverified

A TypeScript-friendly MySQL query builder and connection manager (v2.2.2) providing a chained API for INSERT, DELETE, UPDATE, SELECT operations with built-in connection pooling, once-off connections, keep-alive connections, and debug/reconnect configuration. Ships TypeScript definitions. Peer dependencies include mysql (^2.18.1) and ts-toolbelt (^9.6.0). Differentiates from knex by being simpler, lightweight, and targeted at quick integration with a minimal API surface. Release cadence appears irregular.

npm install dlovely-mysql
INSTALL
IMPORT
SIG · DLOVELY-MYSQL
D
dlovely-mysql
databasejavascriptv2.2.2
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.

MySQLPool
import { MySQLPool } from 'dlovely-mysql'
import MySQLPool from 'dlovely-mysql'
Named export, not default. Also available: MySQLOnce, MySQLKeep, SQL.
MySQLOnce
import { MySQLOnce } from 'dlovely-mysql'
const MySQLOnce = require('dlovely-mysql').MySQLOnce
ESM module; CommonJS require works but is not recommended.
SQL
import { SQL } from 'dlovely-mysql'
import { Sql } from 'dlovely-mysql'
Case-sensitive: SQL class for custom queries without built-in connection.
MySQLKeep
import { MySQLKeep } from 'dlovely-mysql'
import { MySQLKeepConnection } from 'dlovely-mysql'
Export name is MySQLKeep; keep connection manually.

Shows how to create a pool connection, perform an INSERT and a SELECT with WHERE, using TypeScript generics.

import { MySQLPool } from 'dlovely-mysql'; const mysql = MySQLPool({ host : 'localhost', user : 'my_name', password : 'my_secret', database : 'my_database' }); async function run() { const insertResult = await mysql('users').insert({ name: 'Alice' }).get(); console.log('Insert result:', insertResult); const selectResult = await mysql('users').select().where({ id: 1 }).get<{ id: number; name: string }>(); console.log('Select result:', selectResult); } run().catch(console.error);
Debug
Known issues
gotchaThe module requires peerDependencies mysql@^2.18.1 and ts-toolbelt@^9.6.0; not installing them will cause runtime errors or TypeScript compilation failures.
fix
Run npm install mysql ts-toolbelt
affects: >=2.0.0
deprecatedMySQLOnce and MySQLKeep are deprecated in favor of MySQLPool for production use.
fix
Use MySQLPool instead.
affects: >=2.0.0
breakingVersion 2.0.0 changed the API from a class-based to a functional factory pattern. Direct use of 'new MySQLPool()' no longer works.
fix
Use MySQLPool(options) instead of new MySQLPool(options).
affects: >=2.0.0
gotchaThe .get() method must be awaited; forgetting await returns a Promise object.
fix
Use await mysql('table').insert({col: 'val'}).get()
affects: >=1.0.0
gotchaTypeScript generic .get<T>() parameter is the row type, not the array type. Return type is T[] for SELECT.
fix
Use .get<{id: number; name: string}>() which returns an array.
affects: >=2.0.0
gotchaDebug mode is enabled via the second argument as an object { debugger: true }, not the first argument.
fix
Pass options as separate argument: MySQLPool(dbConfig, { debugger: true })
affects: >=1.0.0
deprecatedmaxReconnectTime option is available only for MySQLOnce, not for MySQLPool.
fix
Use MySQLOnce with maxReconnectTime if reconnection is needed.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'dlovely-mysql' or its corresponding type declarations.
Missing peer dependency installation or incorrect import path.
fix
Run 'npm install dlovely-mysql mysql ts-toolbelt' and ensure tsconfig.json includes 'moduleResolution': 'node'.
Property 'insert' does not exist on type '...'
Using MySQLPool or MySQLOnce incorrectly (missing table name).
fix
Use mysql('tablename').insert() instead of mysql.insert()
Expected 0-1 arguments, but got 2
Passing database config and debug config as separate arguments to MySQLPool - it expects a single options object or two arguments (config, proxy).
fix
Use MySQLPool(config, { debugger: true }) not MySQLPool(config, true)
Type 'OkPacket' is not generic
Calling .get<T>() on a non-SELECT query (e.g., insert).
fix
Do not use generics on insert/delete/update; they return OkPacket.
Cannot use namespace 'SQL' as a type
Importing SQL as a type instead of a class.
fix
Use 'import { SQL } from 'dlovely-mysql';' and not 'import type { SQL } ...'
Upgrade
Version history
2.2.2latest on npm
Audit
Dependencies
mysqlrequiredRequired peer dependency for MySQL driver connectivity.
ts-toolbeltrequiredRequired peer dependency for TypeScript utility types.
Agent activity
12 hits · last 30 days
node
10
Resources
dlovely-mysql — npm install dlovely-mysql · libregistry