pg-god is a focused JavaScript/TypeScript library (current stable version 1.0.12) designed to simplify the creation and deletion of PostgreSQL databases, both programmatically and via a command-line interface. Its primary function is to manage database lifecycles, often in development or testing environments where databases need to be frequently spun up and torn down. Key differentiators include its minimalist API for direct database creation/dropping, support for connection URLs (added in v1.0.9), and a default behavior since v1.0.6 to automatically terminate active connections before dropping a database, preventing common errors. It also provides explicit integration guidance for TypeORM users. The project appears to have a moderate release cadence, with recent updates refining CLI behavior and adding new features.
npm install pg-godVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic creation and immediate dropping of a PostgreSQL database using environment variables for credentials and handling potential errors.
If you relied on `dropDatabase` failing when connections were active, you must now explicitly set `dropConnections: false` in the API call or use `--no-dropConnections` with the CLI. For most users, this change improves reliability and is the desired default.
Always provide explicit `DbCredential` objects to the API calls or use environment variables/CLI flags to specify correct user, password, host, and port for your PostgreSQL instance. For the CLI, consider using a connection URL with `--url`.
Be mindful of these options. If you need strict behavior (e.g., ensuring a database is *only* created if it doesn't exist), set `errorIfExist: true`. For idempotent scripts where you don't care if the database exists or not, the defaults are usually fine.
Ensure the `user` and `password` in your `DbCredential` object (or CLI flags/environment variables) match the PostgreSQL server configuration. Verify `pg_hba.conf` allows connections from your host with the specified authentication method.
If it's acceptable for the database not to exist, set `errorIfNonExist: false` in the `dropDatabase` call. Otherwise, ensure the database exists before attempting to drop it.
Ensure `dropConnections: true` (the default since v1.0.6) is used when calling `dropDatabase`. If this is not an option, you must manually terminate all connections to the database before dropping it.
No dependency data recorded yet.