express-mysql-framework
v1.0.6
Published
Database framework for Express.js
Readme
express-mysql-framework
Lightweight TypeScript helper for using Knex with MySQL in Express projects.
Overview
This small library provides a base Model class and a simple Knex db wrapper
to make building database-backed models easier in TypeScript + Express apps.
Key features:
- Minimal base
Modelwith atable()helper that returns a Knex query builder. - Knex configuration driven by environment variables.
Quick start
- Install dependencies:
npm installProvide environment variables (see
.envexample below).Type-check only:
npx tsc --noEmit- Build:
npm run buildLocal .env example
Create a .env file at the project root (not committed to source control):
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD=secret
DB_NAME=my_database
NODE_ENV=development
DB_POOL_MIN=2
DB_POOL_MAX=10Usage
Example usage in TypeScript source:
import UserModel from './src/User.mode.js';
const users = new UserModel();
const q = users.table().select('*').limit(10);
// await q to run query in async contextNotes:
- Set
protected tableNamein model subclasses to match your database table. - The base
ModeldefaultsprimaryKeytoid.
package.json review (A → Z)
name:express-mysql-framework— OK for publishing if desired.type:module— code uses ES module imports/exports.main/module/types: point to./dist/*— matches compiled output.scripts: containsbuild(tsc) and lifecycle hooks (prepare,prepublishOnly).dependencies:dotenv,knex,mysql2— appropriate for runtime.devDependencies:typescript,@types/noderecommended and added.repository/homepage: update to your repo if different from current value.keywords: contains useful tags; duplicates were removed.
Scripts
build— compile TypeScript intodistusingtsc.prepare/prepublishOnly— run build steps before publishing.
Add a test script if you introduce tests.
Publishing checklist
- Bump
versioninpackage.jsonfor releases. - Confirm
repository,bugs, andhomepagepoint to the correct repository. - Run
npm run buildand verifydistcontainsindex.jsand.d.tsfiles. - Optionally add CI to run
npx tsc --noEmiton PRs.
Recommendations
- Install dev types for Node if not already present:
npm install -D @types/node- Consider adding a small integration test or local script that verifies DB
connectivity using your
.envsettings.
Changes made
- Added comments to
src/Model.tsandsrc/db.ts. - Fixed
src/User.mode.tsto usetableNameand set a sensible default. - Removed duplicate keyword in
package.jsonand added@types/node.
If you want, I can run npm install here to pull dependencies and then run
npx tsc --noEmit to re-check types. Which would you like me to do next?
