Registry / database / typescript-mysql-model

typescript-mysql-model

JSON →
library1.12.0jsnpmunverified

A CLI tool and library to generate TypeScript interfaces, classes, and MySQL table schemas from database definitions. Current stable version is 1.12.0. The package relies on knex for database introspection and handlebars for templating. It is primarily used as a code generator to scaffold TypeScript models from an existing MySQL database. Release cadence is low; last update was in 2020. Differentiators include generating both TypeScript types and MySQL create table statements, and handling change-case and pluralization automatically.

npm install typescript-mysql-model
INSTALL
IMPORT
SIG · TYPESCRIPT-MYSQL-M
T
typescript-mysql-model
databasejavascriptv1.12.0
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.

generateModelFiles
✓ import { generateModelFiles } from 'typescript-mysql-model'
✗ const generateModelFiles = require('typescript-mysql-model').generateModelFiles
Package provides CommonJS output; named import works in both ESM and CJS contexts. If using require, you need to destructure as shown.
ModelGenerator
✓ import { ModelGenerator } from 'typescript-mysql-model'
✗ import ModelGenerator from 'typescript-mysql-model'
ModelGenerator is a named class export, not a default export.
Config
✓ import { Config } from 'typescript-mysql-model'
Config is a named exported interface for configuration options.

Generates TypeScript model files from a MySQL database using a config object for connection and output settings.

import { generateModelFiles } from 'typescript-mysql-model'; const config = { connection: { host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'my_database' }, outputDir: './models', generateClasses: true, generateInterfaces: true, generateTables: true }; generateModelFiles(config) .then(() => console.log('Models generated successfully')) .catch(err => console.error(err));
Debug
Known issues
gotchaThe package requires a running MySQL database to generate models; it does not work with a schema file.
fix
Ensure MySQL server is running and accessible with the given credentials.
affects: >=1.0.0
gotchaThe package uses knex version 0.21.1, which may have breaking changes in newer MySQL versions (8.0+). Some column types may not be correctly identified.
fix
Consider using knex directly or another ORM for better compatibility.
affects: >=1.0.0
deprecatedThe package has not been updated since 2020; dependencies like knex and mysql are outdated.
fix
Check for newer alternatives like typeorm or prisma.
affects: >=1.0.0
gotchaThe output directory will be overwritten without warning; no diff or backup is created.
fix
Make sure to version control your generated models or backup before running.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'knex'
Missing knex dependency when using the library programmatically.
fix
Run npm install knex@0.21.1 mysql --save-dev
TypeError: generateModelFiles is not a function
Incorrect import; using default import instead of named import.
fix
Use import { generateModelFiles } from 'typescript-mysql-model'
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
MySQL 8.0 uses caching_sha2_password by default, not supported by older mysql npm package.
fix
Run ALTER USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; or upgrade to mysql2.
Upgrade
Version history
1.12.0latest on npm
Audit
Dependencies
knexrequiredUsed for database connection and schema introspection
mysqlrequiredMySQL driver for the database connection
handlebarsrequiredTemplate engine for generating output files
Agent activity
21 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
typescript-mysql-model — npm install typescript-mysql-model · libregistry