rethinkdb-client-driver-0.0.0.2: Client driver for RethinkDB

Safe HaskellNone

Database.RethinkDB

Synopsis

Documentation

defaultPort :: IntSource

The default port where RethinkDB accepts cliend driver connections.

newHandle :: Text -> Int -> Maybe Text -> IO HandleSource

Create a new handle to the RethinkDB server.

run :: (Term a, FromResponse (Result a)) => Handle -> Exp a -> IO (Res a)Source

Start a new query and wait for its (first) result. If the result is an single value (Datum), then three will be no further results. If it is a sequence, then you must consume results until the sequence ends.

nextChunk :: FromResponse (Sequence a) => Handle -> Sequence a -> IO (Either Error (Sequence a))Source

Get the next chunk of a sequence. It is an error to request the next chunk if the sequence is already Done,

collect :: FromResponse (Sequence a) => Handle -> Sequence a -> IO (Either Error (Vector a))Source

Collect all the values in a sequence and make them available as a 'Vector a'.

data Error Source

Errors include a plain-text description which includes further details. The RethinkDB protocol also includes a backtrace which we currently don't parse.

Constructors

ProtocolError !Text

An error on the protocol level. Perhaps the socket was closed unexpectedly, or the server sent a message which the driver could not parse.

ClientError !Text

Means the client is buggy. An example is if the client sends a malformed protobuf, or tries to send [CONTINUE] for an unknown token.

CompileError !Text

Means the query failed during parsing or type checking. For example, if you pass too many arguments to a function.

RuntimeError !Text

Means the query failed at runtime. An example is if you add together two values from a table, but they turn out at runtime to be booleans rather than numbers.

Instances

class Term a Source

A Term is a JSON expression which can be sent to the server. Building a term is a stateful operation, so the whole process happens inside a State monad.

data Exp a whereSource

Constructors

Constant :: ToRSON a => a -> Exp a 
ListDatabases :: Exp (Array Text) 
CreateDatabase :: Exp Text -> Exp Object 
DropDatabase :: Exp Text -> Exp Object 
ListTables :: Exp Database -> Exp (Array Text) 
CreateTable :: Exp Database -> Exp Text -> Exp Object 
DropTable :: Exp Database -> Exp Text -> Exp Object 
ListIndices :: Exp Table -> Exp (Array Text) 
CreateIndex :: Exp Table -> Exp Text -> (Exp Object -> Exp Datum) -> Exp Object 
DropIndex :: Exp Table -> Exp Text -> Exp Object 
IndexStatus :: Exp Table -> [Exp Text] -> Exp (Array Object) 
WaitIndex :: Exp Table -> [Exp Text] -> Exp Object 
Database :: Exp Text -> Exp Database 
Table :: Exp Text -> Exp Table 
Coerce :: (Term a, Term b) => Exp a -> Exp Text -> Exp b 
Eq :: (IsDatum a, IsDatum b) => Exp a -> Exp b -> Exp Bool 
Ne :: (IsDatum a, IsDatum b) => Exp a -> Exp b -> Exp Bool 
Match :: Exp Text -> Exp Text -> Exp Datum 
Get :: Exp Table -> Exp Text -> Exp SingleSelection 
GetAll :: IsDatum a => Exp Table -> [Exp a] -> Exp (Array Datum) 
GetAllIndexed :: IsDatum a => Exp Table -> [Exp a] -> Text -> Exp (Sequence Datum) 
Add :: Num a => [Exp a] -> Exp a 
Multiply :: Num a => [Exp a] -> Exp a 
All :: [Exp Bool] -> Exp Bool 
Any :: [Exp Bool] -> Exp Bool 
ObjectField :: (IsObject a, IsDatum r) => Exp a -> Exp Text -> Exp r 
ExtractField :: IsSequence a => Exp a -> Exp Text -> Exp a 
Take :: IsSequence s => Exp Double -> Exp s -> Exp s 
Append :: IsDatum a => Exp (Array a) -> Exp a -> Exp (Array a) 
Prepend :: IsDatum a => Exp (Array a) -> Exp a -> Exp (Array a) 
IsEmpty :: IsSequence a => Exp a -> Exp Bool 
Delete :: Term a => Exp a -> Exp Object 
InsertObject :: Exp Table -> Object -> Exp Object 
InsertSequence :: IsSequence s => Exp Table -> Exp s -> Exp Object 
Filter :: (IsSequence s, Term a) => (Exp a -> Exp Bool) -> Exp s -> Exp s 
Map :: (IsSequence s, Term a, Term b) => (Exp a -> Exp b) -> Exp s -> Exp s 
Between :: IsSequence s => Exp s -> (Bound, Bound) -> Exp s 
BetweenIndexed :: IsSequence s => Exp s -> (Bound, Bound) -> Text -> Exp s 
OrderBy :: IsSequence s => [Order] -> Exp s -> Exp s 
Keys :: IsObject a => Exp a -> Exp (Array Text) 
Var :: Int -> Exp a 
Function :: Term a => State Context ([Int], Exp a) -> Exp f 
Call :: Term f => Exp f -> [SomeExp] -> Exp r 

Instances

Num (Exp Double) 
IsString (Exp Text)

Convenience to for automatically converting a Text to a constant expression.

Term a => Term (Exp a) 

data SomeExp whereSource

Because the arguments to functions are polymorphic (the individual arguments can, and often have, different types).

Constructors

SomeExp :: Term a => Exp a -> SomeExp 

Instances

class FromRSON a whereSource

A class describing a type which can be converted to the RethinkDB-specific wire protocol. It is based on JSON, but certain types use a presumably more efficient encoding.

type Array a = Vector aSource

Arrays are vectors of Datum.

type Object = HashMap Text DatumSource

Objects are maps from Text to Datum. Like Aeson, we're using HashMap.

data Datum Source

A sumtype covering all the primitive types which can appear in queries or responses.

Instances

Eq Datum

We can't automatically derive Eq because ZonedTime does not have an instance of Eq. See the eqTime function for why we can compare times.

Show Datum 
Generic Datum 
FromResponse Object 
FromResponse Datum 
IsObject Object 
IsDatum Object 
IsDatum Datum 
ToRSON Object 
ToRSON Datum 
FromRSON Object 
FromRSON Datum 
Term Object 
Term Datum 

data Bound Source

Bounds are used in Between.

Constructors

Open !Datum 
Closed !Datum 

data Order Source

Used in OrderBy.

Constructors

Ascending !Text 
Descending !Text 

Instances

data Sequence a Source

Sequences are a bounded list of items. The server may split the sequence into multiple chunks when sending it to the client. When the response is a partial sequence, the client may request additional chunks until it gets a Done.

data Table Source

Tables are something you can select objects from.

This type is not exported, and merely serves as a sort of phantom type. On the client tables are converted to a Sequence.

data Database Source

A Database is something which contains tables. It is a server-only type.

Instances

data SingleSelection Source

SingleSelection is essentially a 'Maybe Object', where Nothing is represented with Null in the network protocol.

type Res a = Either Error (Result a)Source

The result of a query. It is either an error or a result (which depends on the type of the query expression). This type is named to be symmetrical to Exp, so we get this nice type for run.

 run :: Handle -> Exp a -> IO (Res a)

type family Result a Source

The type of result you get when executing a query of 'Exp a'.

class FromResponse a Source

A value which can be converted from a Response. All types which are defined as being a 'Result a' should have a 'FromResponse a'. Because, uhm.. you really want to be able to extract the result from the response.

There are two parsers defined here, one for atoms and the other for sequences. These are the only two implementations of parseResponse which should be used.

eqTime :: ZonedTime -> ZonedTime -> BoolSource

Comparing two times is done on the local time, regardless of the timezone. This is exactly how the RethinkDB server does it.

lift :: Lift c e => e -> c (Simplified e)Source

call1 :: (Term a, Term r) => (Exp a -> Exp r) -> Exp a -> Exp rSource

Call an unary function with the given argument.

call2 :: (Term a, Term b, Term r) => (Exp a -> Exp b -> Exp r) -> Exp a -> Exp b -> Exp rSource

Call an binary function with the given arguments.

class Term a => IsDatum a Source

Instances

IsDatum Bool

For a boolean type, we're reusing the standard Haskell Bool type.

IsDatum Double

Numbers are Double (unlike Aeson, which uses Scientific). No particular reason.

IsDatum Text

For strings, we're using the Haskell Text type.

IsDatum UTCTime 
IsDatum ZonedTime

Time in RethinkDB is represented similar to the ZonedTime type. Except that the JSON representation on the wire looks different from the default used by Aeson. Therefore we have a custom FromRSON and ToRSON instances.

IsDatum SingleSelection 
IsDatum Object 
IsDatum Datum 
IsDatum a => IsDatum (Array a)