Rollback to a previous state using backups
masterBecause pg-mem uses immutable data structures, you can create restore points for free. This is highly effective for unit testing: you can set up a schema and shared test data once, create a backup, and then call backup.restore() before each test to instantly reset the database state.
const db = newDb();
db.public.none(`create table test(id text);
insert into test values ('value');`);
// create a restore point & mess with data
const backup = db.backup();
db.public.none(`update test set id='new value';`);
// restore it !
backup.restore();
db.public.many(`select * from test`); // => {test: 'value'}