Eulavo
Eulavo

Reputation: 109

Running node-postgres in memory

I'm using Node and the node-postgres package and I would like to perform some unit tests using jest and supertest without saving to the actual database.

When using sequelize it is possible to configure the storage in memory, like so:

const sequelize = new Sequelize({
  ...
  storage: ":memory:"
});

I know it is possible to set the dialect to Postgres in sequelize, but I was wondering how would one go about to set the in memory storage using node-postgres. Is that possible?

Thanks

Upvotes: 3

Views: 3626

Answers (2)

Oleksandr Hrin
Oleksandr Hrin

Reputation: 886

for my approach I'm using docker-container with clear postgres server, which is getting up before all the tests.

then I run all migrations and seeds, then I run all the tests, then I kill that container. All that stuff is done automatically.

But I'm using it in mocha/chai, and using globalSetup and globalTeardown hooks for that. Don't know if it is possible in Jest

Upvotes: 0

Shankar
Shankar

Reputation: 360

I think in sequelize that ":memory:" storage would be available only for sqlite like in memory databases. It isn't possible to run postgresql in memory so you can't connect to in memory postgres from node-postgres/any client.

You can refer this answer for more details (Using in-memory PostgreSQL)

Upvotes: 1

Related Questions