Registry / database / mysql-zod

mysql-zod

JSON →
library2.2.0jsnpmunverified

CLI and library to generate Zod schemas (v2.2.0) from a MySQL database by introspecting table schemas. Supports configurable output including camelCase conversion, nullish vs nullable, and required string validation. Differentiators include simple JSON config, table filtering, and direct API usage. Actively maintained by a single developer, release cadence is irregular.

npm install mysql-zod
INSTALL
IMPORT
SIG · MYSQL-ZOD
M
mysql-zod
databasejavascriptv2.2.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.

generate
✓ import { generate } from 'mysql-zod'
✗ import generate from 'mysql-zod'
Named export, not default. Works in ESM and CJS.
default (zod)
✓ import z from 'zod'
Generated files import default Zod. Ensure zod is installed.
user (generated)
✓ import { user } from './user'
✗ import { user } from '@zod/user'
Output path depends on config 'folder' and 'suffix'.

Shows both JSON config and programmatic usage to generate Zod schemas from MySQL tables.

// 1. Install as dev dependency // npm install mysql-zod --save-dev // 2. Create mysql-zod.json in project root { "host": "127.0.0.1", "port": 3306, "user": "root", "password": "secret", "database": "myapp" } // 3. Create SQL table and run CLI // npx mysql-zod // Or use programmatically in a script import { generate } from 'mysql-zod' await generate({ host: process.env.DB_HOST ?? '127.0.0.1', port: parseInt(process.env.DB_PORT ?? '3306'), user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'myapp', })
Debug
Known issues
gotchaIf using 'folder' config, ensure the directory exists or has write permissions.
fix
Create directory beforehand or remove 'folder' to use default './'.
affects: >=0.0.0
gotchaThe CLI will overwrite existing files for the same table without warning.
fix
Backup previous generated files or use a different output folder.
affects: >=0.0.0
gotchaEnum columns become zod enums; ensure zod version supports .enum().
fix
Update zod to latest. Minimum zod peer dependency is 3.x.
affects: >=2.0.0
deprecatedConfig option 'nullable' is deprecated in favor of 'nullish' (boolean).
fix
Use 'nullish' instead to generate .nullish() schemas.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'zod'
Missing zod dependency in project
fix
Install zod: npm install zod
ECONNREFUSED 127.0.0.1:3306
MySQL server not running or wrong host/port
fix
Start MySQL server or update connection config in mysql-zod.json
ER_ACCESS_DENIED_ERROR: Access denied for user
Invalid MySQL credentials
fix
Check 'user' and 'password' in mysql-zod.json
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
zodrequiredpeer dependency for type generation
mysql2requiredruntime dependency for connecting to MySQL
Agent activity
9 hits · last 30 days
node
8
Resources
mysql-zod — npm install mysql-zod · libregistry