Open expipiplus1 opened 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?
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.
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.
These would be pretty surprising to bump into!