typify-db
v0.1.3
Published
Generate TypeScript types from your DB schema
Readme
Generate TypeScript interfaces from your database schema (PostgreSQL, MySQL, or SQLite) with a simple CLI.
Features
- Introspects tables & columns from PostgreSQL, MySQL, or SQLite
- Outputs a single
schema.d.tsfile containing all interfaces - Converts snake_case or CamelCase table names into PascalCase types
- Configurable via a JSON file
- Easy to integrate into CI/CD or build scripts
Installation
Install globally:
npm install -g typify-dbOr as a dev dependency:
npm install --save-dev typify-dbConfiguration
Execute the command:
npx typify-db initThis will create a typify-db.config.json file in your project root:
This file will look like this:
{
"dbType": "postgres",
"host": "localhost",
"port": "5432",
"user": "username",
"password": "password",
"database": "mydb",
"outputDir": "./types"
}- dbType:
postgres|mysql|sqlite - host: database host (ignored for SQLite)
- port: database port (ignored for SQLite)
- user: database user (ignored for SQLite)
- password: database password (ignored for SQLite)
- database: database name or file path for SQLite
- outputDir: directory where
schema.d.tswill be generated - outputFileName: an optional file name where the types will be written
Usage
Simply run:
npx typify-db generateBy default, it looks for typify-db.config.json in your current directory and writes schema.d.ts to the configured outputDir.
Development
Clone the repo and install dependencies:
git clone https://github.com/marcos-padilla/typify-db.git
cd typify-db
npm installBuild and link locally:
npm run build
npm linkContributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the MIT License.
