pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

Prisma support

Open oguimbal opened this issue 5 years ago • 37 comments

Investigate Prisma support

oguimbal avatar Jan 06 '21 10:01 oguimbal

Would love to see this as well

nahtnam avatar Jan 16 '21 04:01 nahtnam

Just curious if you are still working on this lib and if this might come anyday?

BjoernRave avatar Feb 02 '21 01:02 BjoernRave

I am, and if it is feasible, it will :)

oguimbal avatar Feb 02 '21 08:02 oguimbal

I asked on slack and it seems that prisma does not use pg. Is it possible to mock through a connection uri?

nahtnam avatar Feb 02 '21 10:02 nahtnam

Not a problem... pg-mem is not specific to the pg library. As long as Prisma is issuing PosgreSQL queries, it should be okay.

The only thing that must be done is to replace whatever lib is used to send the requests, and redirect those SQL queries to pg-mem. I havent had the time to investigate how to do that with Prisma yet, but it could be simple. For instance, here is how the Slonik adapter is written, for instance (all supported libraries adapters are in this file). It is not possible to simply use a connection uri, since pg-mem does not listen to network requests, though.

... Once this is done, there also is a possibility that prisma will issue unsupported requests (such as cross joins), in which case I'll have to implement what's needed.

oguimbal avatar Feb 02 '21 11:02 oguimbal

It seems that integration with Prisma would be easy if pg-mem would run a server and expose a url that can be fed to prisma 🤔

flybayer avatar Feb 02 '21 15:02 flybayer

Yup. I looked a bit into prisma, and it turns out that SQL queries are issued by Rust. (I didnt know Prisma was written in Rust !).

(node) prisma -> (rust) prisma-engines -> (rust) quaint -> postgres statements (via tokio-postgres)

So yes, it will be a bit invasive to try to hook quaint to execute pg-mem back in node.

I'm looking into implementing a fake postgres server. It would essentially look like the other side of the mirror of pg-protocol, or more specifically for the rust version, this.... admittedly, it will be a more general solution to plug other libs/frameworks to pg-mem, but I was hoping not to implement such a low level solution 😑

oguimbal avatar Feb 02 '21 15:02 oguimbal

For the record, to solve this, I've started working on pg-server, a library that can fake a postgres database. I'm working on integrating it with pg-mem, which requires some refactoring to do things right.

Once this is done, it will be possible to expose a pg-mem instance via a random network port like any regular pg database. This will have the advantage of being compatible with any library (or any other tool, for that matter), but will add a network overhead.

I'll keep you posted when it is finished😁

The fun in all this is that pg-server is actually much more versatile that just a network interface to pg-mem... you could use it as a a db honeypot, a proxy which intercepts/inspects/modifies postgres requests on the fly (it works quite well in conjunction with pgsql-ast-parser, the syntax parser of pg-mem), or whatever !

oguimbal avatar Feb 15 '21 17:02 oguimbal

This is super exciting! Let me know if you would like me to try a beta build of the library with my codebase (it's relatively small but has some more complex operations)

nahtnam avatar Feb 16 '21 02:02 nahtnam

In case you want to try out, if Prisma Client would work with pg-mem, you can try out our integration tests in https://github.com/prisma/prisma/tree/master/src/packages/tests We also have a more extensive test suite written in Scala we use for Rust, but this one written in TypeScript should already get you quite far. Normally we run them with this docker-compose file: https://github.com/prisma/prisma/blob/master/src/docker/docker-compose.yml

You should "just" need to provide the env var TEST_POSTGRES_URI to point to your pg-mem instance and then in ./src/packages/tests you can do yarn test:postgresql

timsuchanek avatar Feb 16 '21 07:02 timsuchanek

any updates about this?

mark600211 avatar Mar 24 '21 17:03 mark600211

Hi, nothing new... I've worked on the refactoring I mentioned, but I've had a rough month at work, so I couldnt finish it yet.

Sorry 😶

This is definitely still in my pipe, though ! But I cant give you an ETA right now, unfortunately.

oguimbal avatar Mar 24 '21 19:03 oguimbal

Sorry to bump, but what's the status? Really want pg-mem integration for prisma.

jvvvch avatar Dec 01 '21 10:12 jvvvch

I'm also interested in this. Typically in integration tests in services using MongoDB, I use https://www.npmjs.com/package/mongodb-memory-server which allows connecting by URI. Having an in-memory postgres server would enable me to write quality tests for Prisma easily.

nukeop avatar Feb 15 '22 23:02 nukeop

Hi ! I had very little time to work on pg-mem last year, but that's changing, and Prisma support is one of the the two most important issues for me.

A milestone has been recently reached in the refactoring that will allow this, so hopefully I will find time to get that working in the upcoming few months 🤷‍♂️

oguimbal avatar Feb 16 '22 10:02 oguimbal

Any updates or help required with this matter? 😊

jclaessens97 avatar Jul 13 '22 08:07 jclaessens97

Really looking forward to this...

Asaf-S avatar Jul 30 '22 17:07 Asaf-S

+1

julioxavierr avatar Aug 02 '22 17:08 julioxavierr

+1, I think it's the most promising solution for in memory database working with Prisma

ixartz avatar Aug 23 '22 03:08 ixartz

Will keep in the loop! also looking forward to this :)

grusite avatar Aug 30 '22 11:08 grusite

+1 that would be great

charlesilieff avatar Oct 21 '22 13:10 charlesilieff

I've just started working on a fork to work with Prisma, but happy to collaborate!

auser avatar Oct 24 '22 23:10 auser

+1

Wellers0n avatar Dec 21 '22 17:12 Wellers0n

+1 on this one, would be extremely useful!

tmcallister92 avatar Jan 18 '23 03:01 tmcallister92

+1

Giovani-f avatar Mar 21 '23 15:03 Giovani-f

+1

nicholasess avatar Jun 02 '23 19:06 nicholasess

Do we have any updates on this?

jc-greenhouse avatar Jun 09 '23 14:06 jc-greenhouse

Small update from the Prisma side: https://github.com/prisma/prisma/issues/5419#issuecomment-1589665551

janpio avatar Jun 13 '23 16:06 janpio

Does pg-mem expose any kind of URL for integrating w/ Prisma? I tried looking into pg-server but it hasn't been updated in a while.

hnrq avatar Jun 30 '23 15:06 hnrq

+1

joaoh9 avatar Aug 14 '23 13:08 joaoh9