electric-sql / pglite

Lightweight WASM Postgres with real-time, reactive bindings.
https://pglite.dev
Apache License 2.0
8.33k stars 164 forks source link

Is there a way to change databases? #98

Closed pmooney-socraticworks closed 1 month ago

pmooney-socraticworks commented 3 months ago

I want to leverage the template database feature in Postgres to quickly revert my test database to a pristine state between tests. I'm able to create a separate database to serve as the template, but noticed that every operation happens under the template1 database. I can't revert that database because Postgres says it's a template database and can't be dropped.

Is there a way to change the current database for a PGlite instance?

samwillis commented 2 months ago

We don't have this yet, but should. I'm open to ideas how best to support it. I think it should be possible internally, but we need a good api to expose to the user.

samwillis commented 1 month ago

This was fixed with #148 and will be in the next release (ETA Monday)

When you start a PGlite you can now pass a username and database name to connect to a specific databases as a specific user.

pmooney-socraticworks commented 1 month ago

Wow, thanks @samwillis !!