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

Safe HaskellNone
LanguageHaskell2010

Database.RethinkDB

Contents

Synopsis

Documentation

data Handle #

defaultPort :: Int #

The default port where RethinkDB accepts client driver connections.

newHandle :: Text -> Int -> Maybe Text -> Exp Database -> IO Handle #

Create a new handle to the RethinkDB server.

handleDatabase :: Handle -> Exp Database #

The Database which some expressions will use when not explicitly given one (eg. Table).

close :: Handle -> IO () #

Close the given handle. You MUST NOT use the handle after this.

serverInfo :: Handle -> IO (Either Error ServerInfo) #

High-level query API

run :: FromResponse (Result a) => Handle -> Exp a -> IO (Res a) #

Start a new query and wait for its (first) result. If the result is an single value (Datum), then there 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)) #

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

collect :: FromDatum a => Handle -> Sequence a -> IO (Either Error (Vector a)) #

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

Low-level query API

start :: Handle -> Exp a -> IO Token #

Start a new query. Returns the Token which can be used to track its progress.

continue :: Handle -> Token -> IO () #

Let the server know that it can send the next response corresponding to the given token.

stop :: Handle -> Token -> IO () #

Stop (abort?) a query.

wait :: Handle -> Token -> IO () #

Wait until a previous query (which was started with the noreply option) finishes.

type Token = Word64 #

A token is used to refer to queries and the corresponding responses. This driver uses a monotonically increasing counter.

data Error #

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
Eq Error # 
Instance details

Defined in Database.RethinkDB.Types

Methods

(==) :: Error -> Error -> Bool #

(/=) :: Error -> Error -> Bool #

Show Error # 
Instance details

Defined in Database.RethinkDB.Types

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

data Response #

Constructors

Response 

Fields

Instances
Eq Response # 
Instance details

Defined in Database.RethinkDB.Types

Show Response # 
Instance details

Defined in Database.RethinkDB.Types

The Datum type

data Datum #

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

It is similar to the aeson Value type, except that RethinkDB has a few more types (like Time), which have a special encoding in JSON.

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.

Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

(==) :: Datum -> Datum -> Bool #

(/=) :: Datum -> Datum -> Bool #

Show Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

showsPrec :: Int -> Datum -> ShowS #

show :: Datum -> String #

showList :: [Datum] -> ShowS #

Generic Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Associated Types

type Rep Datum :: Type -> Type #

Methods

from :: Datum -> Rep Datum x #

to :: Rep Datum x -> Datum #

ToJSON Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromJSON Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Object # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

ToDatum Object # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Object -> Datum #

ToDatum Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Datum -> Datum #

FromResponse Object # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse Datum # 
Instance details

Defined in Database.RethinkDB.Types

IsObject Object # 
Instance details

Defined in Database.RethinkDB.Types

IsDatum Object # 
Instance details

Defined in Database.RethinkDB.Types

IsDatum Datum # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse (Maybe Datum) # 
Instance details

Defined in Database.RethinkDB.Types

type Rep Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

type Result Object # 
Instance details

Defined in Database.RethinkDB.Types

type Result Datum # 
Instance details

Defined in Database.RethinkDB.Types

type Array a = Vector a #

Arrays are vectors of Datum.

type Object = HashMap Text Datum #

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

class ToDatum a where #

Types which can be converted to or from a Datum.

Methods

toDatum :: a -> Datum #

Instances
ToDatum Bool # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Bool -> Datum #

ToDatum Char # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Char -> Datum #

ToDatum Double # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Double -> Datum #

ToDatum Float # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Float -> Datum #

ToDatum Int # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Int -> Datum #

ToDatum () # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: () -> Datum #

ToDatum Text # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Text -> Datum #

ToDatum UTCTime # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: UTCTime -> Datum #

ToDatum Value # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Value -> Datum #

ToDatum ZonedTime # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: ZonedTime -> Datum #

ToDatum Object # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Object -> Datum #

ToDatum Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Datum -> Datum #

ToDatum ConflictResolutionStrategy # 
Instance details

Defined in Database.RethinkDB.Types

ToDatum [Char] # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: [Char] -> Datum #

ToDatum a => ToDatum [a] # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: [a] -> Datum #

ToDatum a => ToDatum (Maybe a) # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Maybe a -> Datum #

ToDatum a => ToDatum (Array a) # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: Array a -> Datum #

(ToDatum a, ToDatum b) => ToDatum (a, b) # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: (a, b) -> Datum #

(ToDatum a, ToDatum b, ToDatum c) => ToDatum (a, b, c) # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

toDatum :: (a, b, c) -> Datum #

class FromDatum a where #

Methods

parseDatum :: Datum -> Parser a #

Instances
FromDatum Bool # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Char # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Double # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Float # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Int # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

parseDatum :: Datum -> Parser Int #

FromDatum () # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

parseDatum :: Datum -> Parser () #

FromDatum Text # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum UTCTime # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Value # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum ZonedTime # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Object # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum Datum # 
Instance details

Defined in Database.RethinkDB.Types.Datum

FromDatum ChangeNotification # 
Instance details

Defined in Database.RethinkDB.Types

FromDatum [Char] # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

parseDatum :: Datum -> Parser [Char] #

FromDatum a => FromDatum [a] # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

parseDatum :: Datum -> Parser [a] #

FromDatum a => FromDatum (Maybe a) # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

parseDatum :: Datum -> Parser (Maybe a) #

FromDatum a => FromDatum (Array a) # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

parseDatum :: Datum -> Parser (Array a) #

FromDatum a => FromDatum (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types

Methods

parseDatum :: Datum -> Parser (Sequence a) #

(FromDatum a, FromDatum b) => FromDatum (a, b) # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

parseDatum :: Datum -> Parser (a, b) #

(FromDatum a, FromDatum b, FromDatum c) => FromDatum (a, b, c) # 
Instance details

Defined in Database.RethinkDB.Types.Datum

Methods

parseDatum :: Datum -> Parser (a, b, c) #

(.=) :: ToDatum a => Text -> a -> (Text, Datum) #

object :: [(Text, Datum)] -> Datum #

data Exp a where #

Constructors

Constant :: ToDatum a => a -> Exp a 
MkArray :: [Exp a] -> Exp (Array a) 
ListDatabases :: Exp (Array Text) 
CreateDatabase :: Exp Text -> Exp Object 
DropDatabase :: Exp Text -> Exp Object 
WaitDatabase :: Exp Database -> Exp Object 
ListTables :: Exp Database -> Exp (Array Text) 
CreateTable :: Exp Database -> Exp Text -> Exp Object 
DropTable :: Exp Database -> Exp Text -> Exp Object 
WaitTable :: Exp Table -> Exp Object 
ListIndices :: Exp Table -> Exp (Array Text) 
CreateIndex :: IsDatum a => Exp Table -> Exp Text -> (Exp Object -> Exp a) -> Exp Object 
DropIndex :: Exp Table -> Exp Text -> Exp Object 
IndexStatus :: Exp Table -> [Exp Text] -> Exp (Array Object) 
WaitIndex :: Exp Table -> [Exp Text] -> Exp (Array Object) 
Database :: Exp Text -> Exp Database 
Table :: Maybe (Exp Database) -> Exp Text -> Exp Table 
Coerce :: 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 
Lt :: (IsDatum a, IsDatum b) => Exp a -> Exp b -> Exp Bool 
Le :: (IsDatum a, IsDatum b) => Exp a -> Exp b -> Exp Bool 
Gt :: (IsDatum a, IsDatum b) => Exp a -> Exp b -> Exp Bool 
Ge :: (IsDatum a, IsDatum b) => Exp a -> Exp b -> Exp Bool 
Not :: Exp Bool -> 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 
Sub :: Num a => [Exp a] -> Exp a 
Multiply :: Num a => [Exp a] -> Exp a 
All :: [Exp Bool] -> Exp Bool 
Any :: [Exp Bool] -> Exp Bool 
GetField :: (IsObject a, IsDatum r) => Exp Text -> Exp a -> Exp r 
HasFields :: IsObject a => [Text] -> Exp a -> Exp Bool 
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 :: Exp a -> Exp Object 
InsertObject :: ConflictResolutionStrategy -> Exp Table -> Object -> Exp Object 
InsertSequence :: IsSequence s => Exp Table -> Exp s -> Exp Object 
Filter :: IsSequence s => (Exp a -> Exp Bool) -> Exp s -> Exp s 
Map :: IsSequence s => (Exp a -> Exp b) -> Exp s -> Exp (Sequence b) 
Between :: IsSequence s => (Bound, Bound) -> Exp s -> Exp s 
BetweenIndexed :: IsSequence s => Text -> (Bound, Bound) -> Exp s -> Exp s 
OrderBy :: IsSequence s => [Order] -> Exp s -> Exp s 
OrderByIndexed :: IsSequence s => Order -> Exp s -> Exp s 
Keys :: IsObject a => Exp a -> Exp (Array Text) 
Var :: Int -> Exp a 
Function :: State Context ([Int], Exp a) -> Exp f 
Call :: Exp f -> [SomeExp] -> Exp r 
Limit :: IsSequence s => Double -> Exp s -> Exp s 
Nth :: (IsSequence s, IsDatum r) => Double -> Exp s -> Exp r 
UUID :: Exp Text 
Now :: Exp ZonedTime 
Timezone :: Exp ZonedTime -> Exp Text 
RandomInteger :: Exp Int -> Exp Int -> Exp Int 
RandomFloat :: Exp Double -> Exp Double -> Exp Double 
Info :: Exp a -> Exp Object 
Default :: Exp a -> Exp a -> Exp a 
Error :: Exp Text -> Exp a 
SequenceChanges :: IsSequence s => Exp s -> Exp (Sequence ChangeNotification) 
SingleSelectionChanges :: IsDatum a => Exp a -> Exp (Sequence ChangeNotification) 
Instances
Num (Exp Double) # 
Instance details

Defined in Database.RethinkDB.Types

IsString (Exp Text) #

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

Instance details

Defined in Database.RethinkDB.Types

Methods

fromString :: String -> Exp Text #

data SomeExp where #

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

Constructors

SomeExp :: Exp a -> SomeExp 

data Bound #

Bounds are used in Between.

Constructors

Open !Datum 
Closed !Datum 

data Order #

Used in OrderBy.

Constructors

Ascending !Text 
Descending !Text 

data Sequence a #

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.

Constructors

Done !(Vector a) 
Partial !Token !(Vector a) 
Instances
Show (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types

Methods

showsPrec :: Int -> Sequence a -> ShowS #

show :: Sequence a -> String #

showList :: [Sequence a] -> ShowS #

FromDatum a => FromDatum (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types

Methods

parseDatum :: Datum -> Parser (Sequence a) #

FromDatum a => FromResponse (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types

IsSequence (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types

type Result (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types

type Result (Sequence a) = Sequence a

data Table #

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.

Instances
IsSequence Table # 
Instance details

Defined in Database.RethinkDB.Types

type Result Table # 
Instance details

Defined in Database.RethinkDB.Types

data Database #

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

data SingleSelection #

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

type Res a = Either Error (Result a) #

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 #

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

Instances
type Result Bool # 
Instance details

Defined in Database.RethinkDB.Types

type Result Char # 
Instance details

Defined in Database.RethinkDB.Types

type Result Double # 
Instance details

Defined in Database.RethinkDB.Types

type Result Int # 
Instance details

Defined in Database.RethinkDB.Types

type Result Int = Int
type Result Text # 
Instance details

Defined in Database.RethinkDB.Types

type Result String # 
Instance details

Defined in Database.RethinkDB.Types

type Result ZonedTime # 
Instance details

Defined in Database.RethinkDB.Types

type Result Object # 
Instance details

Defined in Database.RethinkDB.Types

type Result Datum # 
Instance details

Defined in Database.RethinkDB.Types

type Result SingleSelection # 
Instance details

Defined in Database.RethinkDB.Types

type Result Table # 
Instance details

Defined in Database.RethinkDB.Types

type Result (Array a) # 
Instance details

Defined in Database.RethinkDB.Types

type Result (Array a) = Array a
type Result (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types

type Result (Sequence a) = Sequence a

class FromResponse a #

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.

Minimal complete definition

parseResponse

Instances
FromResponse Bool # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse Char # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse Double # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse Int # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse Text # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse UTCTime # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse ZonedTime # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse Object # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse Datum # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse [Char] # 
Instance details

Defined in Database.RethinkDB.Types

FromResponse (Maybe Datum) # 
Instance details

Defined in Database.RethinkDB.Types

FromDatum a => FromResponse (Array a) # 
Instance details

Defined in Database.RethinkDB.Types

FromDatum a => FromResponse (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types

data ConflictResolutionStrategy #

ConflictResolutionStrategy

How conflicts should be resolved.

Constructors

CRError

Do not insert the new document and record the conflict as an error. This is the default.

CRReplace

Replace the old document in its entirety with the new one.

CRUpdate

Update fields of the old document with fields from the new one.

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

call1 :: (Exp a -> Exp r) -> Exp a -> Exp r #

Call an unary function with the given argument.

call2 :: (Exp a -> Exp b -> Exp r) -> Exp a -> Exp b -> Exp r #

Call an binary function with the given arguments.

class IsDatum a #

Instances
IsDatum Bool #

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

Instance details

Defined in Database.RethinkDB.Types

IsDatum Double #

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

Instance details

Defined in Database.RethinkDB.Types

IsDatum Text #

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

Instance details

Defined in Database.RethinkDB.Types

IsDatum UTCTime # 
Instance details

Defined in Database.RethinkDB.Types

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.

Instance details

Defined in Database.RethinkDB.Types

IsDatum Object # 
Instance details

Defined in Database.RethinkDB.Types

IsDatum Datum # 
Instance details

Defined in Database.RethinkDB.Types

IsDatum SingleSelection # 
Instance details

Defined in Database.RethinkDB.Types

IsDatum a => IsDatum (Array a) #

Arrays are vectors of Datum.

Instance details

Defined in Database.RethinkDB.Types

class IsDatum a => IsObject a #

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

Instances
IsObject UTCTime # 
Instance details

Defined in Database.RethinkDB.Types

IsObject ZonedTime # 
Instance details

Defined in Database.RethinkDB.Types

IsObject Object # 
Instance details

Defined in Database.RethinkDB.Types

IsObject SingleSelection # 
Instance details

Defined in Database.RethinkDB.Types

class IsSequence a #

Instances
IsSequence Table # 
Instance details

Defined in Database.RethinkDB.Types

IsDatum a => IsSequence (Array a) # 
Instance details

Defined in Database.RethinkDB.Types

IsSequence (Sequence a) # 
Instance details

Defined in Database.RethinkDB.Types