Registry / database / mysql-kv

mysql-kv

JSON →
library1.7.3jsnpmunverified

mysql-kv is a Node.js package that implements a key-value store with TTL expiration on top of MySQL. Version 1.7.3 is current, with no major version changes since initial release. It uses a hardcoded table schema and the mysql2 driver for connection pooling. Key differentiators: simple API (get/set/delete/cleanup), automatic expiration cleanup, and support for custom SQL queries. Not suitable for high-throughput or production without careful MySQL schema management.

npm install mysql-kv
INSTALL
IMPORT
SIG · MYSQL-KV
M
mysql-kv
databasejavascriptv1.7.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.

KV
const { KV } = require('mysql-kv')
const KV = require('mysql-kv')
KV is a named export, not default. CommonJS require destructuring is required.
KV
import { KV } from 'mysql-kv'
import KV from 'mysql-kv'
ESM import also requires named import syntax. Default import will fail.
KV
const { KV } = require('mysql-kv'); const kv = new KV({ host: 'localhost', user: 'root', password: 'pass', database: 'test' })
const kv = new KV({ host: 'localhost' })
Missing database option will cause runtime error when performing queries. Always specify database.

Create a KV instance, set/get/delete a key with TTL, cleanup expired entries, and retrieve all entries.

const { KV } = require('mysql-kv'); const kv = new KV({ host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USERNAME ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_DATABASE ?? 'test' }); async function main() { await kv.set('greeting', 'Hello, World!', 3600); const value = await kv.get('greeting'); console.log(value); // 'Hello, World!' await kv.cleanup(); // remove expired entries await kv.delete('greeting'); const entries = await kv.entries(); console.log(entries); } main().catch(console.error);
Debug
Known issues
gotchaRequires a specific table `MYSQL_KV` to exist in the database; package does not auto-create it.
fix
Run the CREATE TABLE script from the documentation before using the package.
affects: >=0.0.0
gotchaThe `database` option is optional in the constructor but queries will fail if not provided.
fix
Always specify the `database` property in the config object.
affects: >=0.0.0
gotchaThe `VALUE` column uses LONGTEXT, which may cause truncation for very large strings.
fix
Use `LONGBLOB` or alter the table schema if storing binary data or large payloads.
affects: >=0.0.0
breakingThe `custom` method uses parameterized SQL; raw SQL injection if not used properly.
fix
Always pass criteria as an array and avoid string concatenation in the query.
affects: >=0.0.0
Errors
Common errors & fixes
Error: ER_NO_DB_ERROR: No database selected
No `database` option provided in constructor.
fix
Add `database: 'your_db_name'` to the KV constructor config.
Error: ER_BAD_TABLE_ERROR: Table 'db.MYSQL_KV' doesn't exist
Required table `MYSQL_KV` not created in the database.
fix
Execute the CREATE TABLE statement from the package documentation.
TypeError: KV is not a constructor
Importing default instead of named export.
fix
Use `const { KV } = require('mysql-kv')` or `import { KV } from 'mysql-kv'`.
Upgrade
Version history
1.7.3latest on npm
Audit
Dependencies
mysql2requiredMySQL database driver used for all database operations
Agent activity
6 hits · last 30 days
node
6
Resources
mysql-kv — npm install mysql-kv · libregistry