Registry / database / kp-mysql-models

kp-mysql-models

JSON →
library1.5.1jsnpmunverified

kp-mysql-models v1.5.1 is a lightweight, promise-based Node.js ORM for MySQL that simplifies CRUD operations, advanced joins, pagination, soft deletes, and relationship handling (hasOne, belongsTo, hasMany). It uses model-based query building with a minimal footprint. Compared to larger ORMs like Sequelize, it offers a simpler, less opinionated API with direct pool connection management. The package is available on npm under both 'kp-mysql-models' and '@krishnapawar/kp-mysql-models' with no significant release cadence documented. It requires Node.js >=12.0.0 and a MySQL connection pool from the 'mysql' package.

npm install kp-mysql-models
INSTALL
IMPORT
SIG · KP-MYSQL-MODELS
K
kp-mysql-models
databasejavascriptv1.5.1
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.

BaseModels
import { BaseModels } from 'kp-mysql-models'
const BaseModels = require('kp-mysql-models')
Library is CJS-only; named import from CJS works in bundlers. In Node's native ESM, use createRequire or dynamic import().
BaseModels
const { BaseModels } = require('kp-mysql-models')
const kp = require('kp-mysql-models')
Requires destructuring because BaseModels is not a default export.
BaseModels
const { BaseModels } = require('@krishnapawar/kp-mysql-models')
require('kp-mysql-models')
Both packages are identical; choose one consistently to avoid duplication.

Shows full setup: create a MySQL pool, define a User model extending BaseModels, and fetch all users with hidden fields.

const mysql = require('mysql'); const { BaseModels } = require('kp-mysql-models'); const pool = mysql.createPool({ connectionLimit: 10, host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test' }); class User extends BaseModels { constructor() { super(pool); this._table = 'users'; this._hidden = ['password']; } } const userModel = new User(); async function main() { const users = await userModel.get(); console.log(users); } main().catch(console.error);
Debug
Known issues
breakingThe library expects a mysql connection pool, not a connection object. Passing a single connection will cause 'Cannot read property 'query' of undefined' or similar errors.
fix
Always pass a pool created with mysql.createPool().
affects: >=1.0.0
deprecatedUsing this._connection directly in the constructor may be deprecated in future versions. The recommended pattern is to pass the pool via super(pool).
fix
Use super(pool) in constructor; avoid setting this._connection manually.
affects: >=1.0.0
gotchaThe library does not support native ES modules. Attempting import { BaseModels } from 'kp-mysql-models' in Node.js ESM will fail with ERR_MODULE_NOT_FOUND.
fix
Use CommonJS require() or wrap with createRequire in ESM.
affects: >=1.0.0
breakingThe package is also published under @krishnapawar/kp-mysql-models. Installing both variants can cause duplicate registrations and conflicts.
fix
Choose one package name and stick with it; uninstall the other.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'kp-mysql-models'
Package not installed or installed under different package name (@krishnapawar/kp-mysql-models).
fix
Run: npm install kp-mysql-models (or npm install @krishnapawar/kp-mysql-models) and use consistent import.
TypeError: super is not a constructor
BaseModels is a named export, not a default export; using import BaseModels from '...' instead of { BaseModels }.
fix
Use: const { BaseModels } = require('kp-mysql-models');
Cannot read property 'query' of undefined
Pool not passed or passed incorrectly to BaseModels constructor (e.g., passing a connection instead of pool).
fix
Use mysql.createPool() and pass the pool to super(pool) in the model constructor.
ERR_REQUIRE_ESM
Trying to require the package in an ES module context.
fix
Transform your file to CommonJS (.cjs extension) or use dynamic import: const { BaseModels } = await import('kp-mysql-models');
Upgrade
Version history
1.5.1latest on npm
Audit
Dependencies
mysqlrequiredRequired to create a MySQL connection pool passed to BaseModels constructor
Agent activity
5 hits · last 30 days
node
4
Resources
kp-mysql-models — npm install kp-mysql-models · libregistry