adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.97k stars 97 forks source link

Support multiple ENV vars #523

Open zbolan opened 1 year ago

zbolan commented 1 year ago

Is your feature request related to a problem? Please describe.

In large projects, especially monorepos, there can be multiple databases, users, etc. While it is trivial to have multiple 'config' files that support each DB, it is not acceptable to commit these credentials into source. The library currently supports common PG ENV variables but this is limited to a single database, making it impossible to define multiple ENV

Describe the solution you'd like

Taking inspiration from the templatized {{dir}} {{name}} I plan to allow consumers to dynamically specify which ENV vars to use in the db config:

{
  ...,
  "db": {
    "host": "{{MY_DB_HOST}}",
    "port":"{{MY_DB_PORT}}",
    "user": "{{MY_DB_USER}}",
    "dbName": "{{MY_DB_NAME}}",
    "password": "{{MY_DB_PASSWORD}}"
  }
}

It should be simple enough to have the config parser pick up these variables rather than use the default PG onese

Additional context Somewhat related to https://github.com/adelsz/pgtyped/issues/504

zbolan commented 1 year ago

https://github.com/adelsz/pgtyped/pull/524