Registry / database / mysql-typebox

mysql-typebox

JSON →
library2.0.2jsnpmunverified

Generate Typebox schemas and TypeScript types from MySQL table definitions. Version 2.0.2 is stable, with an npm-based CLI tool. It maps MySQL column types to Typebox schema primitives, supports enums, nullables, and configurable naming conventions. Outputs TypeScript files with both schema objects and Static type exports, ready to use with @sinclair/typebox. Differentiators: automatic generation from live database schema, zero-config defaults, and optional camelCase and nullish transformations.

npm install mysql-typebox
INSTALL
IMPORT
SIG · MYSQL-TYPEBOX
M
mysql-typebox
databasejavascriptv2.0.2
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.

user (schema)
import { user } from './path/to/generated/user'
import user from './path/to/generated/user'
Generated files use named exports for the schema object. Default export is not provided.
userType (type)
import type { userType } from './path/to/generated/user'
import { userType } from './path/to/generated/user'
Type-only import avoids bundling runtime code. Use type import for static types.
Static
import type { Static } from '@sinclair/typebox'
import { Static } from '@sinclair/typebox'
Static is a type-only export. Use type import to avoid runtime inclusion.

Shows installation, config, CLI command, and sample output for generating Typebox schemas from MySQL database.

// Install globally or as dev dependency npm install mysql-typebox --save-dev // Create mysql-typebox.json { "host": "127.0.0.1", "port": 3306, "user": "root", "password": "secret", "database": "myapp" } // Run CLI npx mysql-typebox // Example output: user.ts import { Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox' export const user = Type.Object({ id: Type.Number(), name: Type.String(), username: Type.String(), password: Type.String(), profile_picture: Type.Union([Type.String(), Type.Null()]), role: Type.Unsafe<'admin' | 'user'>({ type: 'string', enum: ['admin', 'user'] }), }) export type userType = Static<typeof user>
Debug
Known issues
gotchaGenerated file imports from @sinclair/typebox at runtime; ensure it is installed as a dependency, not just devDependency.
fix
Run 'npm install @sinclair/typebox' as a regular dependency.
affects: >=1.0.0
gotchaCLI uses a config file named 'mysql-typebox.json' in the current directory. If missing, an error occurs.
fix
Create mysql-typebox.json with required fields: host, port, user, password, database.
affects: >=1.0.0
gotchaGenerated schemas for ENUM columns use Type.Unsafe with a hardcoded enum array; this does not validate against the database values at runtime.
fix
Manually update the generated Unsafe schema if the database enum values change.
affects: >=1.0.0
breakingVersion 2.0.0 switched from 'typebox' (scoped) to '@sinclair/typebox' as the peer dependency.
fix
Update your project to use '@sinclair/typebox' and reinstall dependencies.
affects: >=2.0.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or inaccessible at the configured host/port.
fix
Start MySQL service or update mysql-typebox.json with correct connection details.
Error: Cannot find module '@sinclair/typebox'
@sinclair/typebox is not installed as a runtime dependency.
fix
Run 'npm install @sinclair/typebox' in your project.
Error: ENOENT: no such file or directory, open 'mysql-typebox.json'
Config file missing in current working directory.
fix
Create mysql-typebox.json in the project root with database credentials.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
@sinclair/typeboxrequiredGenerated schemas depend on Typebox for runtime validation and type inference.
Agent activity
4 hits · last 30 days
node
4
Resources
mysql-typebox — npm install mysql-typebox · libregistry