Skip to content
/ pgzod Public
forked from owncoral/pgzod

Transform PostgreSQL schemas into Zod validators and types

License

Notifications You must be signed in to change notification settings

j4mesim/pgzod

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


pgzod

Transform PostgreSQL schemas into Zod validators and types
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Keeping Typescript types in sync with your PostgreSQL database schemas very useful but hard. With pgzod that you can maintain all your tables in sync with Typescript through "Zod". Zod is, in their own words:

a TypeScript-first schema declaration and validation library. You can use a Zod schema for validation or as a normal type.

It works great when you couple it with a PostgreSQL client like slonik.

(back to top)

Built With

(back to top)

Getting Started

The best way to run pgzod is by installing it globally or using it through npx.

  • npm
    npm install pgzod -g
  • yarn
    yarn global add pgzod

If you want to use npx, you don't have to install pgzod run:

# Shows the command help.
npx pgzod --help

(back to top)

Usage

You can use pgzod from the command line. It needs the credentials and the address of the live database from where to read the schema. You can provide this information through command options or environment variables. All the variables from PostgreSQL are supported.

Your database credentials could be stored on a local .env file, or even better, on a secret manager. You then load the credentials to your current session and run the pgzod command.

For example, you could build the following .env file:

PGHOST=some.postgresql.host
PGPORT=12345
PGDATABASE=app
PGSSLMODE=require
PGUSER=postgres
PGPASSWORD=yourpassword!

Load the .env variables, and override others through command options.

env $(xargs < .env) pgzod --pghost 127.0.0.1 --pgport 5432

For more examples, please refer to the Documentation

(back to top)

Roadmap

  • Find a better solution to deal with dates. Currently we treat them as strings.
  • Add support for more types.
  • Allow the user to override the current type mappings.
  • Add tests.

See the open issues for a complete list of proposed features (and known issues).

(back to top)

Contributing

Your contributions makes the open source community a fantastic place to learn, inspire, and create.

If you have a suggestion to improve this project, please fork the repo and create a pull request. You can also create an issue with the tag "enhancement."

Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Your Name - @guzmonne - guzmonne@hotmail.com

Project Link: https://github.com/guzmonne/pgzod

(back to top)

About

Transform PostgreSQL schemas into Zod validators and types

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PLpgSQL 67.1%
  • TypeScript 17.1%
  • JavaScript 15.8%