byteally / dbrecord

7 stars 2 forks source link

Remove the orphan instance for `FromJSON ByteString` and `ToJSON ByteString` #14

Open expipiplus1 opened 7 years ago

expipiplus1 commented 7 years ago

These would be pretty surprising to bump into!

expipiplus1 commented 7 years ago

I can't seem to figure out what all the JSON machinery is doing in dbrecord, is it possible to spread some light on this?

mageshb commented 7 years ago

Expr scope a is typed representation of underlying db expression Ast PrimExpr Scope helps to refer to a column in type safe manner like

Consider for example,

type User a = Expr '[ "id" ::: Int
                    , "name" ::: Text
                    , "email" ::: Text
                    , "role" ::: UserRole
                    ] a

col @"name" .== "foobar" :: User Bool
-- or using OverloadedLabel, same thing could be written as
#name .== "foobar" :: User Bool

JSON (de-)serialiazation is exprimental attempt btw. Idea behind (de-)serialiazation instances for Expr type are

we can get the db expression as raw string (probably as rest api param) For Eg. name=="foobar" will successfully parse as User Bool but, id=="foobar" will not parse as User Bool as id column is of type Int

Regarding JSON ByteString instance, I agree it is problematic to keep such opinionated orphan instance in the library. I will probably replace it with the newtype wrapped definition.

expipiplus1 commented 7 years ago

Ok, so the intention was to allow users to write complex queries in a http query.

dbrecord does seem to have quite a wide scope!

Thanks for explaining.