Converts MySQL table schemas directly into Zod validation schemas (TypeScript). Version 2.3.1. Connects to a MySQL database, reads CREATE TABLE statements using node-sql-parser, and generates .ts files with Zod object schemas and inferred types. Differentiators: zero-config CLI usage via npx, config file support, handles MySQL-specific types and defaults. Release cadence: irregular, minor updates.
npm install mysql-to-zodNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Run the CLI to connect to MySQL and generate Zod schemas for all tables in the database.
Use mysqlToZod.config.js with `dbConnection: { host, port, user, password, database }` instead of a URL.In mysqlToZod.config.js, set `tableNames: ['table1', 'table2']` to restrict which tables are processed.
In config, set `schema.nullType: 'nullable'` or `'null'` to change null handling behavior.
Ensure you have a backup or version control before running; use a dedicated output directory.
Test connection separately (e.g., mysql CLI) before running mysql-to-zod.
Run `npm install zod` in the project where you copy the generated .ts files.
Double-check connection string or config object credentials; ensure MySQL allows remote connections if not localhost.
Simplify complex table definitions; avoid MySQL-specific extensions not supported by node-sql-parser. Check table creation for any unusual column types.
Supply a valid MySQL connection string as first argument: `npx mysql-to-zod mysql://user:pass@host:port/db`.