Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma support #27

Open
oguimbal opened this issue Jan 6, 2021 · 34 comments
Open

Prisma support #27

oguimbal opened this issue Jan 6, 2021 · 34 comments

Comments

@oguimbal
Copy link
Owner

oguimbal commented Jan 6, 2021

Investigate Prisma support

@nahtnam
Copy link

nahtnam commented Jan 16, 2021

Would love to see this as well

@BjoernRave
Copy link

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

@oguimbal
Copy link
Owner Author

oguimbal commented Feb 2, 2021

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

@nahtnam
Copy link

nahtnam commented Feb 2, 2021

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

@oguimbal
Copy link
Owner Author

oguimbal commented Feb 2, 2021

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.

@flybayer
Copy link

flybayer commented Feb 2, 2021

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 🤔

@oguimbal
Copy link
Owner Author

oguimbal commented Feb 2, 2021

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
Copy link
Owner Author

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 !

@nahtnam
Copy link

nahtnam commented Feb 16, 2021

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)

@timsuchanek
Copy link

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

@mark600211
Copy link

any updates about this?

@oguimbal
Copy link
Owner Author

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.

@jvvvch
Copy link

jvvvch commented Dec 1, 2021

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

@nukeop
Copy link

nukeop commented Feb 15, 2022

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.

@oguimbal
Copy link
Owner Author

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 🤷‍♂️

@jclaessens97
Copy link

Any updates or help required with this matter? 😊

@Asaf-S
Copy link

Asaf-S commented Jul 30, 2022

Really looking forward to this...

@julioxavierr
Copy link

+1

@ixartz
Copy link

ixartz commented Aug 23, 2022

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

@grusite
Copy link

grusite commented Aug 30, 2022

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

@charlesilieff
Copy link

+1 that would be great

@auser
Copy link

auser commented Oct 24, 2022

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

@Wellers0n
Copy link

+1

@tmcallister92
Copy link

+1 on this one, would be extremely useful!

@Giovani-f
Copy link

+1

1 similar comment
@nicholasess
Copy link

+1

@jc-greenhouse
Copy link

Do we have any updates on this?

@janpio
Copy link

janpio commented Jun 13, 2023

Small update from the Prisma side: prisma/prisma#5419 (comment)

@hnrq
Copy link

hnrq commented Jun 30, 2023

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.

@joaoh9
Copy link

joaoh9 commented Aug 14, 2023

+1

2 similar comments
@SilvioLucasDev
Copy link

+1

@pitazzo
Copy link

pitazzo commented Nov 16, 2023

+1

@janpio
Copy link

janpio commented Nov 17, 2023

Another update over at the Prisma issue: prisma/prisma#5419 (comment)

@oguimbal
Copy link
Owner Author

oguimbal commented Aug 6, 2024

Hi !

Any PG protocol nerd out there that might know the answer to this 🙂 ?

Once this is solved, me might have a real shot at closing this issue that has been there for far too long

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests