lpsmith / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
206 stars 71 forks source link

Testing without a live DB connection? #217

Open saurabhnanda opened 7 years ago

saurabhnanda commented 7 years ago

Related to https://github.com/tomjaguarpaw/haskell-opaleye/issues/308

Most of the runtime errors with PG-Simple are related to incorrect DB (de)serialisation code. Is it possible to run the FromField, ToField, FromRow, ToRow converter functions with a set of string/bytestring obtained from a file, without involving the DB?

lpsmith commented 7 years ago

That is a good question. Unfortunately, there is not really a way to do this at the present time.

One possibility would be to use libpq to construct Result's that could then be used to test the (de)serializers, but the result construction functions are not currently available in the postgresql-libpq binding.

The other possibility that comes to my mind is refactoring the {To,From}{Field,Row} implementation, but I cannot say I am overly excited about that right now. The interface does need a breaking overhaul, but this alone cannot justify that. And maintaining the interace while not introducing too much additional overhead seems tricky.

creichert commented 7 years ago

@saurabhnanda This isn't a solution to your problem but if your queries use [sql| |] quasi-quoters you can at check the syntax of the query using https://github.com/joncfoo/postgresql-simple-query-validator. I generally use that in combination with manually written serialize/deserialize calls to the query.