Registry / database / mysql-schema-ts

mysql-schema-ts

JSON →
library1.9.1jsnpmunverified

mysql-schema-ts (v1.9.1) is a CLI tool and library that connects to a MySQL database and generates TypeScript interfaces from its schema. It provides simple, opinionated defaults with no configuration files, focusing on MySQL only. It can infer entire schemas or specific tables, supports CLI usage via npx, and also offers programmatic use with inferSchema and inferTable functions. Unlike alternatives like schemats, it avoids namespaces and uses inline enums. The package is stable but in maintenance mode with infrequent updates.

npm install mysql-schema-ts
INSTALL
IMPORT
SIG · MYSQL-SCHEMA-TS
M
mysql-schema-ts
databasejavascriptv1.9.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.

inferSchema
import { inferSchema } from 'mysql-schema-ts'
const { inferSchema } = require('mysql-schema-ts')
Package exports ES modules; default export not available, named imports only.
inferTable
import { inferTable } from 'mysql-schema-ts'
import inferTable from 'mysql-schema-ts'
inferTable is a named export, not default.
mysql-schema-ts CLI
npx mysql-schema-ts mysql://user:pass@host:port/db
npm run mysql-schema-ts
CLI tool is invoked via npx, not npm script. No programmatic API for CLI.

Shows both CLI and programmatic usage to generate TypeScript interfaces from a MySQL database schema.

// Generate TypeScript interfaces from a MySQL database // Run in terminal: // npx mysql-schema-ts mysql://root@localhost:3306/mydb > types.ts // Programmatic usage: import { inferSchema, inferTable } from 'mysql-schema-ts'; const connectionString = process.env.MYSQL_CONNECTION_STRING ?? 'mysql://root@localhost:3306/mydb'; // Infer entire schema inferSchema(connectionString).then((interfaces) => { console.log(interfaces); }).catch(err => console.error(err)); // Infer specific table inferTable(connectionString, 'users').then((interfaces) => { console.log(interfaces); }).catch(err => console.error(err));
Debug
Known issues
gotchaMySQL SERIAL type maps to number but may not reflect BIGINT UNSIGNED AUTO_INCREMENT correctly; potential overflow for large IDs.
fix
Manually adjust generated interface to use bigint if needed.
affects: >=1.0.0
deprecatedThe package has not been updated since 2020; no support for newer MySQL features (e.g., JSON, GEOMETRY).
fix
Consider using schemats or other actively maintained libraries.
affects: >=1.0.0
gotchaColumn names that are reserved words in TypeScript (e.g., 'number') are automatically renamed with trailing underscore (e.g., 'number_').
fix
Be aware of renamed columns in generated code; no way to customize transformation.
affects: >=1.0.0
breakingIn version 1.0.0, the API changed from callback to Promise-based for inferSchema/inferTable.
fix
Update to use async/await or .then().
affects: <1.0.0
gotchaThe CLI expects a full MySQL connection string including protocol; missing 'mysql://' prefix causes cryptic error.
fix
Ensure connection string starts with 'mysql://'.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mysql-schema-ts'
Package not installed globally or locally.
fix
Run 'npm install mysql-schema-ts' or use 'npx mysql-schema-ts' without installation.
Error: getaddrinfo ENOTFOUND localhost
MySQL host not reachable.
fix
Ensure MySQL server is running and accessible; use correct host/port.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Invalid credentials or insufficient privileges.
fix
Provide correct username/password; ensure user has SELECT on information_schema.
Error: Cannot use 'inferSchema' because it's not a function?
Using CommonJS require incorrectly; package is ESM.
fix
Use import { inferSchema } from 'mysql-schema-ts' or use dynamic import.
Upgrade
Version history
1.9.1latest on npm
Audit
Dependencies
mysql2requiredUsed to connect to MySQL databases and query schema information.
meowrequiredCLI argument parsing for the npx command.
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-schema-ts — npm install mysql-schema-ts · libregistry