Safe Haskell | None |
---|
Haskell client driver for RethinkDB
Based upon the official Javascript, Python and Ruby API: http://www.rethinkdb.com/api/
How to use
{-# LANGUAGE OverloadedStrings #-} import qualified Database.RethinkDB as R import qualified Database.RethinkDB.NoClash
- data RethinkDBHandle
- connect :: HostName -> Integer -> Maybe String -> IO RethinkDBHandle
- close :: RethinkDBHandle -> IO ()
- use :: RethinkDBHandle -> Database -> RethinkDBHandle
- run :: (Expr query, Result r) => RethinkDBHandle -> query -> IO r
- run' :: Expr query => RethinkDBHandle -> query -> IO [Value]
- runOpts :: (Expr query, Result r) => RethinkDBHandle -> [RunOptions] -> query -> IO r
- next :: Cursor a -> IO (Maybe a)
- collect :: Cursor a -> IO [a]
- data RunOptions
- = UseOutdated
- | NoReply
- | SoftDurability Bool
- data Cursor a
- data Response
- class Result r where
- convertResult :: MVar Response -> IO r
- data RethinkDBError = RethinkDBError {}
- data SuccessCode
- data ErrorCode
- data ReQL
- data Database = Database {
- databaseName :: Text
- db :: Text -> Database
- dbCreate :: String -> ReQL
- dbDrop :: Database -> ReQL
- dbList :: ReQL
- data Table = Table {
- tableDatabase :: Maybe Database
- tableName :: Text
- tablePrimaryKey :: Maybe Key
- data TableCreateOptions = TableCreateOptions {
- tableDataCenter :: Maybe Text
- tableCacheSize :: Maybe Int64
- table :: Text -> Table
- tableCreate :: Table -> TableCreateOptions -> ReQL
- tableDrop :: Table -> ReQL
- tableList :: Database -> ReQL
- indexCreate :: Expr fun => String -> fun -> Table -> ReQL
- indexDrop :: Key -> Table -> ReQL
- indexList :: Table -> ReQL
- data WriteResponse = WriteResponse {
- writeResponseInserted :: Int
- writeResponseDeleted :: Int
- writeResponseReplaced :: Int
- writeResponseUnchanged :: Int
- writeResponseSkipped :: Int
- writeResponseErrors :: Int
- writeResponseFirstError :: Maybe Text
- writeResponseGeneratedKeys :: Maybe [Text]
- writeResponseOldVal :: Maybe Value
- writeResponseNewVal :: Maybe Value
- insert :: (Expr table, Expr object) => object -> table -> ReQL
- upsert :: (Expr table, Expr object) => object -> table -> ReQL
- update :: Expr selection => (ReQL -> ReQL) -> selection -> ReQL
- replace :: Expr selection => (ReQL -> ReQL) -> selection -> ReQL
- delete :: Expr selection => selection -> ReQL
- returnVals :: ReQL -> ReQL
- get :: (Expr s, Expr k) => k -> s -> ReQL
- filter :: (Expr predicate, Expr seq) => predicate -> seq -> ReQL
- between :: (Expr left, Expr right, Expr seq) => Key -> left -> right -> seq -> ReQL
- getAll :: Expr value => Key -> [value] -> Table -> ReQL
- innerJoin :: (Expr a, Expr b, Expr c) => (ReQL -> ReQL -> c) -> a -> b -> ReQL
- outerJoin :: (Expr a, Expr b, Expr c) => (ReQL -> ReQL -> c) -> a -> b -> ReQL
- eqJoin :: (Expr a, Expr b) => Key -> a -> Key -> b -> ReQL
- mergeRightLeft :: Expr a => a -> ReQL
- map :: (Expr a, Expr b) => (ReQL -> b) -> a -> ReQL
- withFields :: (Expr paths, Expr seq) => [paths] -> seq -> ReQL
- concatMap :: (Expr a, Expr b) => (ReQL -> b) -> a -> ReQL
- drop :: (Expr a, Expr b) => a -> b -> ReQL
- take :: (Expr n, Expr seq) => n -> seq -> ReQL
- (!!) :: Expr a => a -> ReQL -> ReQL
- slice :: (Expr a, Expr b, Expr c) => a -> b -> c -> ReQL
- orderBy :: Expr s => [Order] -> s -> ReQL
- data Order
- indexesOf :: (Expr fun, Expr seq) => fun -> seq -> ReQL
- isEmpty :: Expr seq => seq -> ReQL
- (++) :: (Expr a, Expr b) => a -> b -> ReQL
- sample :: (Expr n, Expr seq) => n -> seq -> ReQL
- reduce :: (Expr base, Expr seq, Expr a) => (ReQL -> ReQL -> a) -> base -> seq -> ReQL
- reduce1 :: (Expr a, Expr s) => (ReQL -> ReQL -> a) -> s -> ReQL
- distinct :: Expr s => s -> ReQL
- groupBy :: (Expr group, Expr reduction, Expr seq) => (ReQL -> group) -> (ReQL -> reduction) -> seq -> ReQL
- member :: Expr o => [ReQL] -> o -> ReQL
- length :: Expr a => a -> ReQL
- sum :: Expr s => s -> ReQL
- avg :: Expr s => s -> ReQL
- pluck :: Expr o => [ReQL] -> o -> ReQL
- without :: Expr o => [ReQL] -> o -> ReQL
- merge :: (Expr a, Expr b) => a -> b -> ReQL
- append :: (Expr a, Expr b) => a -> b -> ReQL
- prepend :: (Expr datum, Expr array) => datum -> array -> ReQL
- (\\) :: (Expr a, Expr b) => a -> b -> ReQL
- setInsert :: (Expr datum, Expr array) => datum -> array -> ReQL
- setUnion :: (Expr a, Expr b) => a -> b -> ReQL
- setIntersection :: (Expr a, Expr b) => a -> b -> ReQL
- setDifference :: (Expr set, Expr remove) => remove -> set -> ReQL
- (!) :: Expr s => s -> ReQL -> ReQL
- hasFields :: (Expr obj, Expr paths) => paths -> obj -> ReQL
- insertAt :: (Expr n, Expr datum, Expr array) => n -> datum -> array -> ReQL
- spliceAt :: (Expr n, Expr replace, Expr array) => n -> replace -> array -> ReQL
- deleteAt :: (Expr n, Expr array) => n -> array -> ReQL
- changeAt :: (Expr n, Expr datum, Expr array) => n -> datum -> array -> ReQL
- keys :: Expr obj => obj -> ReQL
- (+) :: (Expr a, Expr b) => a -> b -> ReQL
- (-) :: (Expr a, Expr b) => a -> b -> ReQL
- (*) :: (Expr a, Expr b) => a -> b -> ReQL
- (/) :: (Expr a, Expr b) => a -> b -> ReQL
- mod :: (Expr a, Expr b) => a -> b -> ReQL
- (&&) :: (Expr a, Expr b) => a -> b -> ReQL
- (||) :: (Expr a, Expr b) => a -> b -> ReQL
- (==) :: (Expr a, Expr b) => a -> b -> ReQL
- (/=) :: (Expr a, Expr b) => a -> b -> ReQL
- (>) :: (Expr a, Expr b) => a -> b -> ReQL
- (<) :: (Expr a, Expr b) => a -> b -> ReQL
- (<=) :: (Expr a, Expr b) => a -> b -> ReQL
- (>=) :: (Expr a, Expr b) => a -> b -> ReQL
- not :: Expr a => a -> ReQL
- (=~) :: Expr string => string -> ReQL -> ReQL
- newtype UTCTime = UTCTime UTCTime
- newtype ZonedTime = ZonedTime ZonedTime
- now :: ReQL
- time :: ReQL -> ReQL -> ReQL -> ReQL -> ReQL -> ReQL -> ReQL -> ReQL
- epochTime :: ReQL -> ReQL
- iso8601 :: ReQL -> ReQL
- inTimezone :: Expr time => ReQL -> time -> ReQL
- during :: (Expr left, Expr right, Expr time) => Bound left -> Bound right -> time -> ReQL
- timezone :: Expr time => time -> ReQL
- date :: Expr time => time -> ReQL
- timeOfDay :: Expr time => time -> ReQL
- year :: Expr time => time -> ReQL
- month :: Expr time => time -> ReQL
- day :: Expr time => time -> ReQL
- dayOfWeek :: Expr time => time -> ReQL
- dayOfYear :: Expr time => time -> ReQL
- hours :: Expr time => time -> ReQL
- minutes :: Expr time => time -> ReQL
- seconds :: Expr time => time -> ReQL
- toIso8601 :: Expr t => t -> ReQL
- toEpochTime :: Expr t => t -> ReQL
- apply :: (Expr fun, Expr arg) => fun -> [arg] -> ReQL
- class Javascript r where
- if' :: (Expr a, Expr b, Expr c) => a -> b -> c -> ReQL
- forEach :: (Expr s, Expr a) => s -> (ReQL -> a) -> ReQL
- error :: Expr s => s -> ReQL
- handle :: (Expr handler, Expr reql) => handler -> reql -> ReQL
- class Expr e where
- coerceTo :: Expr x => ReQL -> x -> ReQL
- asArray :: Expr x => x -> ReQL
- asString :: Expr x => x -> ReQL
- asNumber :: Expr x => x -> ReQL
- asObject :: Expr x => x -> ReQL
- asBool :: Expr x => x -> ReQL
- typeOf :: Expr a => a -> ReQL
- info :: Expr a => a -> ReQL
- json :: Expr string => string -> ReQL
- class Obj o where
- data Object
- data Attribute = forall e . Expr e => Text := e
- str :: String -> ReQL
- num :: Double -> ReQL
- (.) :: (Expr a, Expr b, Expr c) => (ReQL -> b) -> (ReQL -> a) -> c -> ReQL
- (#) :: (Expr a, Expr b) => a -> (ReQL -> b) -> ReQL
- def :: Default a => a
Accessing RethinkDB
connect :: HostName -> Integer -> Maybe String -> IO RethinkDBHandleSource
Create a new connection to the database server
Example: connect using the default port with no passphrase
>>>
h <- connect "localhost" 28015 Nothing
close :: RethinkDBHandle -> IO ()Source
Close an open connection
use :: RethinkDBHandle -> Database -> RethinkDBHandleSource
Set the default database
The new handle is an alias for the old one. Calling close on either one will close both.
run :: (Expr query, Result r) => RethinkDBHandle -> query -> IO rSource
Run a given query and return a Result
run' :: Expr query => RethinkDBHandle -> query -> IO [Value]Source
Run a given query and return a Value
runOpts :: (Expr query, Result r) => RethinkDBHandle -> [RunOptions] -> query -> IO rSource
Run a query with the given options
Convert the raw query response into useful values
convertResult :: MVar Response -> IO rSource
data RethinkDBError Source
An RQL term
Manipulating databases
A database, referenced by name
Database | |
|
Manipulating Tables
A table description
Table | |
|
data TableCreateOptions Source
Options used to create a table
TableCreateOptions | |
|
tableCreate :: Table -> TableCreateOptions -> ReQLSource
Create a table on the server
indexCreate :: Expr fun => String -> fun -> Table -> ReQLSource
Create an index on the table from the given function
Writing data
data WriteResponse Source
insert :: (Expr table, Expr object) => object -> table -> ReQLSource
Insert a document or a list of documents into a table
upsert :: (Expr table, Expr object) => object -> table -> ReQLSource
Like insert, but update existing documents with the same primary key
update :: Expr selection => (ReQL -> ReQL) -> selection -> ReQLSource
Add to or modify the contents of a document
replace :: Expr selection => (ReQL -> ReQL) -> selection -> ReQLSource
Replace a document with another
returnVals :: ReQL -> ReQLSource
Include the value of single write operations in the returned object
Selecting data
filter :: (Expr predicate, Expr seq) => predicate -> seq -> ReQLSource
Filter a sequence given a predicate
between :: (Expr left, Expr right, Expr seq) => Key -> left -> right -> seq -> ReQLSource
Query all the documents whose value for the given index is in a given range
getAll :: Expr value => Key -> [value] -> Table -> ReQLSource
Retreive documents by their indexed value
Joins
innerJoin :: (Expr a, Expr b, Expr c) => (ReQL -> ReQL -> c) -> a -> b -> ReQLSource
SQL-like join of two sequences. Returns each pair of rows that satisfy the 2-ary predicate.
outerJoin :: (Expr a, Expr b, Expr c) => (ReQL -> ReQL -> c) -> a -> b -> ReQLSource
SQL-like join of two sequences. Returns each pair of rows that satisfy the 2-ary predicate.
eqJoin :: (Expr a, Expr b) => Key -> a -> Key -> b -> ReQLSource
An efficient iner_join that uses a key for the first table and an index for the left table.
mergeRightLeft :: Expr a => a -> ReQLSource
Transformations
withFields :: (Expr paths, Expr seq) => [paths] -> seq -> ReQLSource
Like hasFields followed by pluck
concatMap :: (Expr a, Expr b) => (ReQL -> b) -> a -> ReQLSource
Map a function of a sequence and concat the results
drop :: (Expr a, Expr b) => a -> b -> ReQLSource
Drop elements from the head of a sequence. Called skip in the official drivers
take :: (Expr n, Expr seq) => n -> seq -> ReQLSource
Limit the size of a sequence. Called limit in the official drivers
indexesOf :: (Expr fun, Expr seq) => fun -> seq -> ReQLSource
The position in the sequence of the elements that match the predicate
(++) :: (Expr a, Expr b) => a -> b -> ReQLSource
Join two sequences. Called union in the official drivers
sample :: (Expr n, Expr seq) => n -> seq -> ReQLSource
Select a given number of elements from a sequence with uniform random distribution
Aggregation
reduce :: (Expr base, Expr seq, Expr a) => (ReQL -> ReQL -> a) -> base -> seq -> ReQLSource
Reduce a sequence to a single value
reduce1 :: (Expr a, Expr s) => (ReQL -> ReQL -> a) -> s -> ReQLSource
Reduce a non-empty sequence to a single value
groupBy :: (Expr group, Expr reduction, Expr seq) => (ReQL -> group) -> (ReQL -> reduction) -> seq -> ReQLSource
Turn a grouping function and a reduction function into a grouped map reduce operation
member :: Expr o => [ReQL] -> o -> ReQLSource
Test if an object contains the given attribute. Called contains in the official drivers
Aggregators
length :: Expr a => a -> ReQLSource
The size of a sequence or an array. Called count in the official drivers
Document manipulation
setInsert :: (Expr datum, Expr array) => datum -> array -> ReQLSource
Insert a datum into an array if it is not yet present
setIntersection :: (Expr a, Expr b) => a -> b -> ReQLSource
The intersection of two sets
setDifference :: (Expr set, Expr remove) => remove -> set -> ReQLSource
The difference of two sets
hasFields :: (Expr obj, Expr paths) => paths -> obj -> ReQLSource
Test if an object has the given fields
insertAt :: (Expr n, Expr datum, Expr array) => n -> datum -> array -> ReQLSource
Insert a datum at the given position in an array
spliceAt :: (Expr n, Expr replace, Expr array) => n -> replace -> array -> ReQLSource
Splice an array at a given position inside another array
changeAt :: (Expr n, Expr datum, Expr array) => n -> datum -> array -> ReQLSource
Change an element in an array
Math and logic
String manipulation
(=~) :: Expr string => string -> ReQL -> ReQLSource
Match a string to a regular expression. Called match in the official drivers
Dates and times
Time with no time zone The default FromJSON instance for Data.Time.UTCTime is incompatible with ReQL's time type
Time with a time zone The default FromJSON instance for Data.Time.ZonedTime is incompatible with ReQL's time type
time :: ReQL -> ReQL -> ReQL -> ReQL -> ReQL -> ReQL -> ReQL -> ReQLSource
Build a time object from the year, month, day, hour, minute, second and timezone fields
inTimezone :: Expr time => ReQL -> time -> ReQLSource
The same time in a different timezone
during :: (Expr left, Expr right, Expr time) => Bound left -> Bound right -> time -> ReQLSource
Test if a time is between two other times
toEpochTime :: Expr t => t -> ReQLSource
Convert a time to another representation
Control structures
apply :: (Expr fun, Expr arg) => fun -> [arg] -> ReQLSource
Apply a function to a list of arguments. Called do in the official drivers
class Javascript r whereSource
Create a javascript expression
Javascript ReQL | |
Javascript (ReQL -> ReQL -> ReQL) | |
Javascript (ReQL -> ReQL) |
handle :: (Expr handler, Expr reql) => handler -> reql -> ReQLSource
Catch some expections inside the query. Called default in the official drivers
Convert other types into ReqL expressions
Expr Bool | |
Expr Double | |
Expr Int | |
Expr Int64 | |
Expr Integer | |
Expr Rational | |
Expr () | |
Expr Text | |
Expr UTCTime | |
Expr Value | |
Expr ZonedTime | |
Expr Datum | |
Expr Table | |
Expr Database | |
Expr Object | |
Expr BaseReQL | |
Expr ReQL | |
Expr ZonedTime | |
Expr UTCTime | |
Expr a => Expr [a] | |
Expr x => Expr (Vector x) | |
Expr (ReQL -> ReQL -> ReQL) | |
Expr (ReQL -> ReQL) | |
Expr e => Expr (HashMap Text e) |
info :: Expr a => a -> ReQLSource
Get information on a given expression. Useful for tables and databases.
Helpers
Convert into a ReQL object
A key/value pair used for building objects
A shortcut for inserting strings into ReQL expressions Useful when OverloadedStrings makes the type ambiguous