{"library":"pg-god","title":"pg-god: PostgreSQL Database Management","description":"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.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install pg-god"],"cli":{"name":"pg-god","version":null}},"imports":["import { createDatabase } from 'pg-god'","import { dropDatabase } from 'pg-god'","import type { DbCredential } from 'pg-god'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createDatabase, dropDatabase, DbCredential } from 'pg-god';\n\nasync function main() {\n  const dbConfig = { databaseName: 'my_app_test_db' };\n  const credentials: Partial<DbCredential> = {\n    user: process.env.PG_USER ?? 'postgres',\n    password: process.env.PG_PASSWORD ?? '',\n    host: process.env.PG_HOST ?? 'localhost',\n    port: parseInt(process.env.PG_PORT ?? '5432', 10),\n    database: process.env.PG_INITIAL_DB ?? 'postgres', // Initial database to connect to\n  };\n\n  try {\n    console.log(`Attempting to create database: ${dbConfig.databaseName}`);\n    await createDatabase(dbConfig, credentials);\n    console.log(`Database '${dbConfig.databaseName}' created successfully.`);\n\n    // --- Your application logic or tests would go here ---\n\n    console.log(`Attempting to drop database: ${dbConfig.databaseName}`);\n    // dropConnections: true is default since v1.0.6, but explicit for clarity\n    await dropDatabase({ ...dbConfig, dropConnections: true }, credentials);\n    console.log(`Database '${dbConfig.databaseName}' dropped successfully.`);\n  } catch (error) {\n    console.error('An error occurred during database operation:', error);\n    // Attempt to clean up even if an error occurred after creation\n    try {\n        await dropDatabase({ ...dbConfig, dropConnections: true, errorIfNonExist: false }, credentials);\n        console.log(`Attempted cleanup for database '${dbConfig.databaseName}'.`);\n    } catch (cleanupError) {\n        console.warn(`Failed to clean up database '${dbConfig.databaseName}':`, cleanupError);\n    }\n    process.exit(1);\n  }\n}\n\nmain();","lang":"typescript","description":"Demonstrates programmatic creation and immediate dropping of a PostgreSQL database using environment variables for credentials and handling potential errors.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}