dylex / postgresql-typed

Haskell PostgreSQL library with compile-time type inference
http://hackage.haskell.org/package/postgresql-typed
Other
83 stars 12 forks source link

hasql API integration #26

Open avanov opened 2 years ago

avanov commented 2 years ago

Hi!

I see that the current version of the project already depends on postgresql-binary, and I wonder to what extent it could integrate with hasql Connections and Sessions. As my projects already use hasql, I'd like to extend the existing API rather than replace it. Ideally I see it as something like hasql-th but implemented as postgresql-typed under the hood.

dylex commented 2 years ago

I've been thinking about this but it's a little tricky. hasql uses postgresql-libpq, the binding to postgres's client libpq library to talk to postgres, while postgresql-typed talks the postgresql protocol directly, because some of the query details were not available through libpq. It looks like they may be now, though using them might be a bit cumbersome. Regardless, it would take a significant rewrite to switch to the higher-level interface rather than the direct protocol (essentially switching out the Protocol module). It might be possible to do this in a partial way, using postgresql-typed's raw protocol for the TH-compile-time queries, and generating hasql-compatible run-time queries, but even that would take some work. I could point you in the right direction to try to do some of this, but I'm not sure I'm up for it at the moment.

avanov commented 2 years ago

Hi @dylex! I've linked a relevant hasql ticket that points to a dev-version Postgres protocol implementation in hasql. Maybe you could share a bit of information regarding GC handling?

It might be possible to do this in a partial way, using postgresql-typed's raw protocol for the TH-compile-time queries, and generating hasql-compatible run-time queries, but even that would take some work. I could point you in the right direction to try to do some of this, but I'm not sure I'm up for it at the moment.

I'd appreciate any guideline.