Registry / database / mysql-types-generator

mysql-types-generator

JSON →
library2.1.0jsnpmunverified

Generates TypeScript type definitions from a MySQL database schema. v2.1.0, active development, requires Node >=18.3. Automatically converts snake_case table names to PascalCase types, supports custom suffix, column type overrides, enum string generation, and tinyint-as-boolean toggle. Outputs per-table files with index re-export or single file. Useful for Knex or raw MySQL users who want typed database schemas without an ORM. Alternatives like mysql-type-defs-generator exist but this package offers a more focused API and CLI with minimal configuration.

npm install mysql-types-generator
INSTALL
IMPORT
SIG · MYSQL-TYPES-GENERA
M
mysql-types-generator
databasejavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generateMysqlTypes
import { generateMysqlTypes } from 'mysql-types-generator'
import { generateTypes } from 'mysql-types-generator'
Named export only; no default export.
generateMysqlTypes
const { generateMysqlTypes } = require('mysql-types-generator')
const generateMysqlTypes = require('mysql-types-generator')
CommonJS require destructures the named export.
GenerateOptions / config
import type { GenerateOptions } from 'mysql-types-generator'
import { GenerateOptions } from 'mysql-types-generator'
Type import for TypeScript users; not exported as value.

Generates TypeScript types from a MySQL database, outputting each table as a PascalCase type with 'PO' suffix in separate files.

// file: updateTypes.js import { generateMysqlTypes } from 'mysql-types-generator'; const dbConfig = { host: process.env.DB_HOST ?? 'localhost', port: parseInt(process.env.DB_PORT ?? '3306'), user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'mydb', }; generateMysqlTypes({ db: dbConfig, output: { dir: 'src/types' }, suffix: 'PO', ignoreTables: ['knex_migrations', 'knex_migrations_lock'], tinyintIsBoolean: false, }) .then(() => console.log('Types generated!')) .catch(err => console.error(err));
mysql-types-generator --version
Debug
Known issues
warningOutput directory will be emptied and overwritten if 'dir' option is used.
fix
Ensure the output directory is dedicated; back up any existing files.
affects: >=0.0.0
breakingCLI changed from positional arguments to options in v2.0.0 (database name is now required as positional).
fix
Use syntax: npx mysql-types-generator --outFile types.ts mydb
affects: >=2.0.0
gotchaTable names must be in snake_case; otherwise PascalCase conversion may be incorrect.
fix
Rename tables to snake_case or use overrides to manually map types.
affects: >=0.0.0
gotchaIf 'uri' is provided in db config, host/port/user/password are ignored.
fix
Use only 'uri' or the individual fields, not both.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pluralize'
Missing dependency 'pluralize' (internal dependency not installed).
fix
Ensure 'mysql-types-generator' is installed with all dependencies: npm install mysql-types-generator
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or unreachable with given credentials.
fix
Verify MySQL is running on port 3306, check host/port/credentials.
Error: Cannot use 'require' with ESM modules (ERR_REQUIRE_ESM)
Using require() to import the package in an ESM-only project.
fix
Use import statement: import { generateMysqlTypes } from 'mysql-types-generator'
TypeError: generateMysqlTypes is not a function
Default import instead of named import.
fix
Use named import: import { generateMysqlTypes } from 'mysql-types-generator'
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
mysql2requiredDatabase connection driver
pluralizerequiredUsed for type name pluralization (internal)
dotenvoptionalUsed to load .env files in CLI mode
Agent activity
6 hits · last 30 days
node
6
Resources
mysql-types-generator — npm install mysql-types-generator · libregistry