4 ms·
Check out my Haskell driver (https://github.com/wereHamster/rethinkdb-client-driver https://github.com/wereHamster/rethinkdb-client-driver). I think think the f
by wereHamster 12y ago
Check out my Haskell driver (https://github.com/wereHamster/rethinkdb-client-driver https://github.com/wereHamster/rethinkdb-client-driver). I think think the first paragraph of the readme describes the differences between my driver and atnnn's quite nicely:
> It differs from the other driver (rethinkdb) in that it uses advanced Haskell magic to properly type the terms, queries and responses.
For example the driver knows that this query returns a number, and tries to parse it as such:
call2 (lift (+)) (lift 1) (lift 2)
Here are a few more examples from my application:
-- | The primary key in all our documents is the default "id".
primaryKeyField :: Text
primaryKeyField = "id"
-- | Expression which represents the primary key field.
primaryKeyFieldE :: Exp Text
primaryKeyFieldE = lift primaryKeyField
-- | Expression which represents the value of a field inside of an Object.
objectFieldE :: (IsDatum a) => Text -> Exp Object -> Exp a
objectFieldE field obj = GetField (lift field) obj
-- | True if the object field matches the given value.
objectFieldEqE :: (ToDatum a) => Text -> a -> Exp Object -> Exp Bool
objectFieldEqE field value obj = Eq
(objectFieldE field obj :: Exp Datum)
(lift $ toDatum value)
-- | True if the object's primary key matches the given string.
primaryKeyEqE :: Text -> Exp Object -> Exp Bool
primaryKeyEqE = objectFieldEqE primaryKeyField
My driver doesn't include all commands of the query language, just those which I need in my product. And I haven't tested it with RethinkDB 2.0 yet.
- coffeemug 12y agoOh neat, thanks for pointing me to this!
- pka 12y agoStill, you are supplying the record fields to match on as T.Text. Check out [1] for a type-safer approach. I've been working on a typed expression builder for just this purpose, but due to lack of time haven't been able to finish it yet [2]. [1] http://hackage.haskell.org/package/structured-mongoDB-0.3 http://hackage.haskell.org/package/structured-mongoDB-0.3 [2] https://github.com/pkamenarsky/typesafe-query https://github.com/pkamenarsky/typesafe-query