Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
expipiplus1 opened this issue Jan 7, 2017 · 3 comments

Comments

@expipiplus1
Copy link

These would be pretty surprising to bump into!

@expipiplus1
Copy link
Author

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
Copy link
Contributor

mageshb commented Jan 7, 2017

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants