PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.
npm install @testcontainers/postgresql --save-devConnect and execute query: inside_block:connect
Connect and execute query using URI: inside_block:uriConnect
Set database: inside_block:setDatabase
Set username: inside_block:setUsername
This example shows the usage of the postgres module's Snapshot feature to give each test a clean database without having to recreate the database container on every test or run heavy scripts to clean your database. This makes the individual tests very modular, since they always run on a brand-new database.
!!!tip
You should never pass the "postgres" system database as the container database name if you want to use snapshots.
The Snapshot logic requires dropping the connected database and using the system database to run commands, which will
not work if the database for the container is set to "postgres".
Test with a reusable Postgres container inside_block:createAndRestoreFromSnapshot