gen-types-enums-psql-schema
v1.3.1
Published
A CLI tool to automatically generate TypeScript types and enums from any PostgreSQL DB schema
Maintainers
Readme
⭐ Star us on GitHub — let's reach 10 stars together! 😊
🔥 Why use this tool? — Read the docs 📑
Table of Contents
- About
- Features
- Installation
- How to Build
- Usage
- Configuration
- Generated Files
- Documentation
- Feedback and Contributions
- License
- Contacts
🚀 About
gen-types-enums-psql-schema is a CLI tool to automatically generate TypeScript types and enums from any PostgreSQL DB schema using Drizzle ORM. It streamlines the process of keeping your TypeScript types in sync with your database schema, improving type safety and developer productivity.
- Modular: Works with any PostgreSQL schema.
- TypeScript-first: Generates enums and types with proper naming conventions.
- Flexible: Supports full and types-only generation modes.
- Automated: Cleans up, lints, and organizes output for you.
✨ Features
- Configurable: Works with any PostgreSQL schema, not just a specific one.
- TypeScript Enums: Generates properly formatted TypeScript enums for each database enum.
- Type Safety: Creates TypeScript types for all tables with proper naming conventions.
- Flexible Modes: Provides both full and types-only modes for different workflows.
- Code Quality: Automatically fixes code style issues with ESLint.
- Clean Output: Streamlines development workflow by automating types generation.
📦 Installation
Global
npm install -g gen-types-enums-psql-schemaLocal
npm install gen-types-enums-psql-schema
npx gen-types-enums-psql-schema --helpWith Bun (Recommended)
Global
bun install -g gen-types-enums-psql-schemaLocal
bun add gen-types-enums-psql-schema
bunx gen-types-enums-psql-schema --help🚦 Usage
# Full process - pull schema from database and generate types
gen-types-enums-psql-schema <schema_name>
# Only regenerate types from existing schema (without querying the database)
gen-types-enums-psql-schema <schema_name> --types-only
# Pull and generate types for all schemas
gen-types-enums-psql-schema --all
# Remove schema.ts after enum generation
gen-types-enums-psql-schema <schema_name> --remove-schema
# Skip ESLint step
gen-types-enums-psql-schema <schema_name> --disable-eslint
# Show help
gen-types-enums-psql-schema --helpShell Script Wrapper
A shell script wrapper is provided for easier usage:
./gen-types-enums.sh <schema_name> [flags]⚙️ Configuration
Environment Variables
DATABASE_URL- PostgreSQL connection string (required for schema pull)
export DATABASE_URL="postgresql://username:password@localhost:5432/database_name"Database Config Files
The tool creates schema-specific config files like db.config.public.ts for the public schema, based on the template in db.config.ts. Existing config files are not overwritten.
📂 Generated Files
For a schema named public, the following files will be generated:
./schemas/
├── public/
│ ├── schema.ts
│ ├── types.ts
│ ├── enums.ts
│ └── index.ts📚 Documentation
🤝 Feedback and Contributions
We welcome feedback, feature requests, and contributions!
Your input helps us improve and grow the project!
🗨️ Runing Into Errors?
Feel free to reach me out here or just mail me at [email protected]. Check the GitHub Issues. If an issue does not exist, feel free to create a new one.
- Email: [email protected]
- Website: harjotrana.com
- GitHub: gen-types-enums-psql-schema
📃 License
MIT © Harjot Singh Rana
Free for non-commercial use.
