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

Add API that exposes the protocol response without parsing #80

Closed shadaj closed 2 months ago

shadaj commented 5 months ago

This can be useful when using pglite with code that already has its own parsing logic.

samwillis commented 5 months ago

Hey @shadaj

I considered this when first implementing the execProtocol method but we need to do some level of parsing for error handling internally and watching for the shutdown message. We should revisit this though as there is probably a more efficient route.

I will take a good look later this week.

shadaj commented 5 months ago

Ah, yeah. In my use case I am bridging this to a WASM module that only knows how to speak the wire protocol, so I ran into trouble when execProtocol throws an exception afte parsing out an error since I have no way of recovering the original bytes. So currently I am just patching pglite to not throw that exception, which works reasonably well.

Could there maybe be two layers to the API? One that deals directly at the protocol level and doesn't try to do anything smart wrt managing transactions and parsing errors, and one that layers the JS-friendly API on top?

samwillis commented 2 months ago

Closed with #127 which will be in v0.2