{"library":"pg-test","title":"PostgreSQL SQL Test Runner","description":"pg-test is a focused command-line interface (CLI) utility designed for running tests directly from `.sql` files against a PostgreSQL database. As of version 1.0.7, it provides a straightforward mechanism for database-centric testing, executing each `.sql` file in a specified directory sequentially and stopping on the first failure. Its release cadence appears to be stable and utility-focused, without frequent major updates. Key differentiators include its simplicity, direct execution of SQL scripts, and reliance on a `DB` environment variable for database connection, making it suitable for CI environments like Travis-CI. Unlike typical JavaScript test runners, pg-test primarily operates on raw SQL files rather than integrating with JS/TS test frameworks.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pg-test"],"cli":{"name":"pg-test","version":null}},"imports":["import { spawn } from 'child_process'; spawn('pg-test', ['path/to/tests'], { stdio: 'inherit' });","// No direct programmatic API documented for import.","// Configuration is via environment variables or CLI arguments."],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { spawnSync } from 'child_process';\nimport path from 'path';\nimport fs from 'fs';\n\n// Create a dummy test file\nconst testFilePath = path.join(process.cwd(), 'temp_test.sql');\nfs.writeFileSync(testFilePath, 'SELECT 1 = 1; -- Should pass');\n\n// Set the DB environment variable (replace with your actual DB URL)\n// For local PostgreSQL without password: 'postgres://postgres@localhost/your_db_name'\n// Make sure 'your_db_name' exists and is accessible.\nprocess.env.DB = process.env.DB ?? 'postgres://postgres@localhost/testdb';\n\nconsole.log(`Running pg-test against: ${process.env.DB}`);\n\nconst result = spawnSync('pg-test', [path.dirname(testFilePath)], {\n  stdio: 'inherit',\n  env: process.env\n});\n\nif (result.status !== 0) {\n  console.error('pg-test failed!');\n} else {\n  console.log('pg-test completed successfully.');\n}\n\n// Clean up the dummy test file\nfs.unlinkSync(testFilePath);","lang":"typescript","description":"Demonstrates how to run `pg-test` programmatically using `child_process` after setting the required `DB` environment variable, including creating a temporary SQL test file.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}