[TUTORIAL]: Using in-memory Postgres when testing with vitest #4216
wilfredjonathanjames
started this conversation in
General
Replies: 2 comments
-
|
Using normal imports also works (except the import { drizzle } from "drizzle-orm/pglite";
import { PGlite } from "@electric-sql/pglite"; |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks for this… any ideas on how I could do something similar in a cloudflare environment? push api won’t work there nether will manually executing the sql files with drizzle |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Crosspost from here - just realised discussions gets use.
Sharing for posterity as it may help someone. A
vi.mockto switchpgdatabases to in-memorypglite, push your drizzle schema, and insert seed data.pgliteruns-WASM compiled postgres in memory, which is ideal for testing as there's no docker containers, no delay, and it's real pg. This solution supports parallelism and watch mode. Most importantly - it uses push in place of migrate, as there's no need to create migration files when testing.Note to Drizzle maintainers, please do not remove
drizzle-kit/api'spushSchemamethod. While it's not well documented, it allows us to push schema directly to test dbs. Please don't make me push via child_process execSync again.Stack:
drizzle-orm/node-postgres)Mock:
Detail:
Beta Was this translation helpful? Give feedback.
All reactions