Mocking database
I want to mock the PostgreSQL database and access it with Drizzle ORM. I tried to write a TypeScript class that should work the same way as pg's Pool class, but instead of hitting an actual database, returns rows from an in-memory object. However when SELECT'ing from the table I had mocked, Drizzle returned an object with all keys having undefined values.
Any help? 🙂
Using the mock pool:
7 Replies
we're querying the DB using raw mode, which returns a row as a tuple of values, not as an object.
Also, we don't do
*
selects because of that. You can enable logging on the Drizzle instance and see the exact queries that it sends.Yeah, the code above was just an example out of my head. My code throws an error and the query Drizzle made if there's no matching mock.
I'm not sure what should I change to work with this raw mode. Can you enlighten me a bit?
It's called an "array" mode in node-pg
Thanks, got it working now 🙂
Any plans to bring mocking into Drizzle level some day? I think it would be helpful for many devs.
Funny thing - we had it at some point, but then decided to remove
Drizzle doesn't manage the DB connection, so I don't think it makes sense to mock inside of Drizzle, since it works with a lot of different drivers
@Petja Touru would you mind sharing your solution that fixed this?