{"id":18582,"library":"mysql-types-generator","title":"mysql-types-generator","description":"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.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/coreyarms/mysql-types-generator","tags":["javascript","typescript"],"install":[{"cmd":"npm install mysql-types-generator","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-types-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-types-generator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Database connection driver","package":"mysql2","optional":false},{"reason":"Used for type name pluralization (internal)","package":"pluralize","optional":false},{"reason":"Used to load .env files in CLI mode","package":"dotenv","optional":true}],"imports":[{"note":"Named export only; no default export.","wrong":"import { generateTypes } from 'mysql-types-generator'","symbol":"generateMysqlTypes","correct":"import { generateMysqlTypes } from 'mysql-types-generator'"},{"note":"CommonJS require destructures the named export.","wrong":"const generateMysqlTypes = require('mysql-types-generator')","symbol":"generateMysqlTypes","correct":"const { generateMysqlTypes } = require('mysql-types-generator')"},{"note":"Type import for TypeScript users; not exported as value.","wrong":"import { GenerateOptions } from 'mysql-types-generator'","symbol":"GenerateOptions / config","correct":"import type { GenerateOptions } from 'mysql-types-generator'"}],"quickstart":{"code":"// file: updateTypes.js\nimport { generateMysqlTypes } from 'mysql-types-generator';\n\nconst dbConfig = {\n  host: process.env.DB_HOST ?? 'localhost',\n  port: parseInt(process.env.DB_PORT ?? '3306'),\n  user: process.env.DB_USER ?? 'root',\n  password: process.env.DB_PASSWORD ?? '',\n  database: process.env.DB_NAME ?? 'mydb',\n};\n\ngenerateMysqlTypes({\n  db: dbConfig,\n  output: { dir: 'src/types' },\n  suffix: 'PO',\n  ignoreTables: ['knex_migrations', 'knex_migrations_lock'],\n  tinyintIsBoolean: false,\n})\n  .then(() => console.log('Types generated!'))\n  .catch(err => console.error(err));","lang":"typescript","description":"Generates TypeScript types from a MySQL database, outputting each table as a PascalCase type with 'PO' suffix in separate files."},"warnings":[{"fix":"Ensure the output directory is dedicated; back up any existing files.","message":"Output directory will be emptied and overwritten if 'dir' option is used.","severity":"warning","affected_versions":">=0.0.0"},{"fix":"Use syntax: npx mysql-types-generator --outFile types.ts mydb","message":"CLI changed from positional arguments to options in v2.0.0 (database name is now required as positional).","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Rename tables to snake_case or use overrides to manually map types.","message":"Table names must be in snake_case; otherwise PascalCase conversion may be incorrect.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use only 'uri' or the individual fields, not both.","message":"If 'uri' is provided in db config, host/port/user/password are ignored.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure 'mysql-types-generator' is installed with all dependencies: npm install mysql-types-generator","cause":"Missing dependency 'pluralize' (internal dependency not installed).","error":"Error: Cannot find module 'pluralize'"},{"fix":"Verify MySQL is running on port 3306, check host/port/credentials.","cause":"MySQL server not running or unreachable with given credentials.","error":"Error: connect ECONNREFUSED 127.0.0.1:3306"},{"fix":"Use import statement: import { generateMysqlTypes } from 'mysql-types-generator'","cause":"Using require() to import the package in an ESM-only project.","error":"Error: Cannot use 'require' with ESM modules (ERR_REQUIRE_ESM)"},{"fix":"Use named import: import { generateMysqlTypes } from 'mysql-types-generator'","cause":"Default import instead of named import.","error":"TypeError: generateMysqlTypes is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}