Safe Haskell | None |
---|
RethinkDB client library for Haskell
Modelled upon the official Javascript and Python API: http://www.rethinkdb.com/api/
How to use
>>>
import Database.RethinkDB
>>>
import qualified Database.RethinkDB.Functions as R
- data RethinkDBHandle
- openConnection :: HostName -> Maybe PortID -> Maybe String -> IO RethinkDBHandle
- closeConnection :: RethinkDBHandle -> IO ()
- use :: RethinkDBHandle -> Database -> RethinkDBHandle
- run :: ToQuery a v => RethinkDBHandle -> a -> IO v
- runMaybe :: ToQuery a v => RethinkDBHandle -> a -> IO (Maybe v)
- runEither :: ToQuery a v => RethinkDBHandle -> a -> IO (Either String v)
- runRaw :: (ToBuildQuery q, JSONQuery (BuildViewQuery q)) => RethinkDBHandle -> q -> IO Response
- runJSON :: (JSONQuery (BuildViewQuery q), ToBuildQuery q) => RethinkDBHandle -> q -> IO [Value]
- runBatch :: ToQuery q [a] => RethinkDBHandle -> q -> IO (Results a)
- next :: Results a -> IO (Maybe a)
- collect :: Results a -> IO [a]
- resultsError :: Results a -> IO (Maybe String)
- data Database = Database {}
- db :: String -> Database
- dbCreate :: String -> Query False Database
- dbDrop :: Database -> Query False ()
- dbList :: Query False [Database]
- data Table = Table {}
- tablePrimaryAttr :: Table -> String
- data TableCreateOptions = TableCreateOptions {}
- table :: String -> Table
- tableCreate :: Table -> TableCreateOptions -> Query False Table
- tableDrop :: Table -> Query False ()
- tableList :: Database -> Query False [Table]
- data Document = Document {}
- insert :: (ToValue a, ToValueType (ExprType a) ~ ObjectType) => Table -> a -> WriteQuery Document
- insertMany :: (ToValue a, ToValueType (ExprType a) ~ ObjectType) => Table -> [a] -> WriteQuery [Document]
- upsert :: (ToValue a, ToValueType (ExprType a) ~ ObjectType) => Table -> a -> WriteQuery Document
- upsertMany :: (ToValue a, ToValueType (ExprType a) ~ ObjectType) => Table -> [a] -> WriteQuery [Document]
- update :: (ToExpr sel, ExprType sel ~ StreamType True out, ToMapping map, MappingFrom map ~ out, MappingTo map ~ ObjectType) => sel -> map -> WriteQuery ()
- replace :: (ToExpr sel, ExprIsView sel ~ True, ToJSON a) => sel -> a -> WriteQuery ()
- delete :: (ToExpr sel, ExprIsView sel ~ True) => sel -> WriteQuery ()
- get :: (ToExpr e, ExprType e ~ StreamType True ObjectType, ToValue k) => e -> k -> ObjectExpr
- filter' :: (ToMapping m, ToStream e, MappingFrom m `HasToStreamValueOf` e) => m -> e -> Expr (ExprType e)
- between :: (ToJSON a, ToStream e, ObjectType `HasToStreamValueOf` e) => Maybe a -> Maybe a -> e -> Expr (ExprType e)
- innerJoin :: (ToStream a, l `HasToStreamValueOf` a, ToStream b, r `HasToStreamValueOf` b) => a -> b -> (ValueExpr l -> ValueExpr r -> BoolExpr) -> Expr (StreamType False ObjectType)
- outerJoin :: (ToStream a, l `HasToStreamValueOf` a, ToStream b, r `HasToStreamValueOf` b) => a -> b -> (ValueExpr l -> ValueExpr r -> BoolExpr) -> Expr (StreamType False ObjectType)
- eqJoin :: (ToStream a, ObjectType `HasToStreamValueOf` a, ToExpr b, ExprType b ~ ExprType Selection) => a -> String -> b -> Expr (StreamType False ObjectType)
- zip' :: (ToStream e, ObjectType `HasToStreamValueOf` e) => e -> Expr (StreamType False ObjectType)
- map' :: (ToMapping m, ToStream e, MappingFrom m `HasToStreamValueOf` e) => m -> e -> Expr (StreamType False (MappingTo m))
- concatMap' :: (ToMapping m, MappingTo m ~ ArrayType, ToStream e, MappingFrom m `HasToStreamValueOf` e) => m -> e -> Expr (StreamType False t)
- orderBy :: (ToOrder o, ToStream e, a `HasToStreamValueOf` e) => [o] -> e -> Expr (StreamType (ExprIsView e) a)
- skip :: (ToStream e, t `HasToStreamValueOf` e, ToExpr n, ExprType n ~ ValueType NumberType) => e -> n -> Expr (StreamType (ExprIsView e) t)
- limit :: (ToStream e, t `HasToStreamValueOf` e, ToExpr n, ExprType n ~ ValueType NumberType) => e -> n -> Expr (StreamType (ExprIsView e) t)
- slice :: (ToStream e, t `HasToStreamValueOf` e, ToExpr n, ExprType n ~ ValueType NumberType, ToExpr m, ExprType m ~ ValueType NumberType) => e -> n -> m -> Expr (StreamType (ExprIsView e) t)
- nth :: (ToStream e, t `HasToStreamValueOf` e, ToExpr n, ExprType n ~ ValueType NumberType) => e -> n -> ValueExpr t
- pluck :: (ToStream e, ObjectType `HasToStreamValueOf` e) => [String] -> e -> Expr (StreamType False ObjectType)
- without :: (ToStream e, ObjectType `HasToStreamValueOf` e) => [String] -> e -> Expr (StreamType False ObjectType)
- union' :: (ToStream a, t `HasToStreamValueOf` a, ToStream b, t `HasToStreamValueOf` b) => a -> b -> Expr (StreamType False t)
- reduce :: (ToValue z, ToValueType (ExprType z) ~ a, ToStream e, b `HasToStreamValueOf` e, ToExpr c, ExprIsView c ~ False) => e -> z -> (ValueExpr a -> ValueExpr b -> c) -> Expr (ExprType c)
- count :: (ToExpr e, Sequence (ExprType e)) => e -> NumberExpr
- distinct :: (ToStream e, v `HasToStreamValueOf` e) => e -> Expr (StreamType False v)
- groupedMapReduce :: (ToValue group, ToValue value, ToValue acc, ToValueType (ExprType acc) ~ b, ToValue acc', ToValueType (ExprType acc') ~ b, ToStream e, a `HasToStreamValueOf` e) => (ValueExpr a -> group) -> (ValueExpr a -> value) -> acc -> (ValueExpr b -> ValueExpr v -> acc') -> e -> Expr (StreamType False b)
- groupBy' :: (ToStream e, ObjectType `HasToStreamValueOf` e) => [String] -> MapReduce ObjectType b c d -> e -> Expr (StreamType False d)
- count' :: MapReduce ObjectType NoneType NumberType NumberType
- sum' :: String -> MapReduce ObjectType NumberType NumberType NumberType
- avg :: String -> MapReduce ObjectType ArrayType ArrayType NumberType
- pick :: HasValueType e ObjectType => [String] -> e -> ObjectExpr
- unpick :: HasValueType e ObjectType => [String] -> e -> ObjectExpr
- merge :: (ToExpr a, ExprType a ~ ValueType ObjectType, ToExpr b, ExprType b ~ ValueType ObjectType) => a -> b -> ObjectExpr
- append :: (HasValueType a ArrayType, HasValueType b x) => a -> b -> ArrayExpr
- (!) :: (ToExpr a, ExprValueType a ~ ObjectType) => a -> String -> ValueExpr t
- (!?) :: HasValueType a ObjectType => a -> String -> BoolExpr
- concat :: (HaveValueType a b v, CanConcat v) => a -> b -> Expr (ValueType v)
- add :: HaveValueType a b NumberType => a -> b -> NumberExpr
- sub :: HaveValueType a b NumberType => a -> b -> NumberExpr
- mul :: HaveValueType a b NumberType => a -> b -> NumberExpr
- div' :: HaveValueType a b NumberType => a -> b -> NumberExpr
- mod :: HaveValueType a b NumberType => a -> b -> NumberExpr
- and' :: HaveValueType a b BoolType => a -> b -> BoolExpr
- or' :: HaveValueType a b BoolType => a -> b -> BoolExpr
- eq :: (HasValueType a x, HasValueType b y) => a -> b -> BoolExpr
- ne :: (HasValueType a x, HasValueType b y) => a -> b -> BoolExpr
- gt :: (HaveValueType a b v, CanCompare v) => a -> b -> BoolExpr
- ge :: (HaveValueType a b v, CanCompare v) => a -> b -> BoolExpr
- lt :: (HaveValueType a b v, CanCompare v) => a -> b -> BoolExpr
- le :: (HaveValueType a b v, CanCompare v) => a -> b -> BoolExpr
- not' :: HasValueType a BoolType => a -> BoolExpr
- bind :: ToValue e => e -> (ValueExpr (ToValueType (ExprType e)) -> Expr t) -> Expr t
- let' :: [Attribute] -> Expr t -> Expr t
- var :: ExprIsView (Expr t) ~ False => String -> Expr t
- if' :: (ToValue e, ToValueType (ExprType e) ~ BoolType, ToExpr a, ExprTypeNoView (ExprType a) ~ x, ToExpr b, ExprTypeNoView (ExprType b) ~ x, ExprTypeIsView x ~ False) => e -> a -> b -> Expr x
- forEach :: (ToStream a, v `HasToStreamValueOf` a) => a -> (ValueExpr v -> WriteQuery b) -> WriteQuery ()
- error' :: ExprTypeIsView t ~ False => String -> Expr t
- js :: String -> Expr (ValueType any)
- jsfun :: ToValue e => String -> e -> Expr (ValueType y)
- streamToArray :: (ToExpr e, ExprType e ~ StreamType w t) => e -> Expr (ValueType ArrayType)
- arrayToStream :: (ToExpr e, ExprType e ~ ValueType ArrayType) => e -> Expr (StreamType False t)
- asArray :: ToExpr e => e -> ArrayExpr
- data Obj
- data Attribute = forall e . ToValue e => String := e
- obj :: [Attribute] -> Obj
- str :: String -> Text
- nil :: ValueExpr ArrayType
- data Query b a
- class ToBuildQuery a => ToQuery a b | a -> b where
- toQuery :: a -> Query (BuildViewQuery a) b
- data ValueTypeKind
- = NumberType
- | BoolType
- | ObjectType
- | ArrayType
- | StringType
- | NoneType
- | OtherValueType
- data ExprTypeKind
- type ExprIsView e = ExprTypeIsView (ExprType e)
- type family ExprValueType expr :: ValueTypeKind
- data Expr t where
- Expr :: QueryM (MaybeView (ExprIsView (Expr t)), Term) -> Expr t
- SpotExpr :: Document -> Expr (StreamType True ObjectType)
- class ToExpr o where
- type ExprType o :: ExprTypeKind
- toExpr :: o -> Expr (ExprType o)
- class ToValue e where
- toValue :: e -> Expr (ValueType (ToValueType (ExprType e)))
- type HasValueType a v = (ToValue a, ToValueType (ExprType a) ~ v)
- type HaveValueType a b v = (HasValueType a v, HasValueType b v)
- type NumberExpr = Expr (ValueType NumberType)
- type BoolExpr = Expr (ValueType BoolType)
- type ObjectExpr = Expr (ValueType ObjectType)
- type ArrayExpr = Expr (ValueType ArrayType)
- type StringExpr = Expr (ValueType StringType)
- type ValueExpr t = Expr (ValueType t)
- type NumberStream = Expr (StreamType False NumberType)
- type BoolStream = Expr (StreamType False BoolType)
- type ObjectStream = Expr (StreamType False ObjectType)
- type ArrayStream = Expr (StreamType False ArrayType)
- type StringStream = Expr (StreamType False StringType)
- type Selection = Expr (StreamType True ObjectType)
- class CanCompare a
- data Order
- class ToOrder a where
- class Sequence e where
- type SequenceType e t :: Constraint
- data Mapping from to = Mapping (QueryM Mapping)
- class ToMapping map where
- type MappingFrom map :: ValueTypeKind
- type MappingTo map :: ValueTypeKind
- toMapping :: map -> Mapping (MappingFrom map) (MappingTo map)
- data Results a
Accessing RethinkDB
data RethinkDBHandle Source
A connection to the database server
openConnection :: HostName -> Maybe PortID -> Maybe String -> IO RethinkDBHandleSource
Create a new connection to the database server
Example: connect using the default port (28015) and specifying the default database for all queries.
>>>
h <- openConnection "localhost" Nothing (Just "test")
closeConnection :: RethinkDBHandle -> IO ()Source
Close an open connection
>>>
closeConnection h
use :: RethinkDBHandle -> Database -> RethinkDBHandleSource
Set the default connection
The new handle is an alias for the old one. Calling closeConnection on either one will close both.
>>>
let h' = h `use` (db "players")
run :: ToQuery a v => RethinkDBHandle -> a -> IO vSource
Run a query on the connection
The return value depends on the type of the second argument.
When the return value is polymorphic, type annotations may be required.
>>>
run h $ table "fruits" :: IO [(Document, Value)]
runMaybe :: ToQuery a v => RethinkDBHandle -> a -> IO (Maybe v)Source
Run a query on the connection, returning Nothing on error
runEither :: ToQuery a v => RethinkDBHandle -> a -> IO (Either String v)Source
Run a query on the connection, returning (Left message) on error
runRaw :: (ToBuildQuery q, JSONQuery (BuildViewQuery q)) => RethinkDBHandle -> q -> IO ResponseSource
Run a query on the connection and return the raw response
runJSON :: (JSONQuery (BuildViewQuery q), ToBuildQuery q) => RethinkDBHandle -> q -> IO [Value]Source
Run a query on the connection and return the resulting JSON value
runBatch :: ToQuery q [a] => RethinkDBHandle -> q -> IO (Results a)Source
Run a query on the connection and a return a lazy result list
>>>
res <- runBatch h <- (arrayToStream [1,2,3] :: NumberStream)
>>>
next res
Just 1>>>
collect res
[2,3]
next :: Results a -> IO (Maybe a)Source
Read the next value from a lazy query. Fetch it from the server if needed.
resultsError :: Results a -> IO (Maybe String)Source
Get the last error from a lazy query.
If both next and resultsError return Nothing, then all results have been fetched without error.
Manipulating databases
A database, referenced by name
dbList :: Query False [Database]Source
List the databases on the server
>>>
run h $ dbList
[test, dev, prod]
Manipulating Tables
A table description
Table | |
|
data TableCreateOptions Source
Options used to create a table
table :: String -> TableSource
Create a simple table refence with no associated database or primary key
>>>
table "music"
Another way to create table references is to use the Table constructor:
>>>
Table (Just "mydatabase") "music" (Just "tuneid")
tableCreate :: Table -> TableCreateOptions -> Query False TableSource
Create a table on the server
def
can be imported from Data.Default
>>>
t <- run h $ tableCreate (table "fruits") def
Writing data
A reference to a document
Eq Document | |
Show Document | |
ToValue Document | |
ToExpr Document | |
ToStream Document | |
ToBuildQuery Document | |
(ToBuildQuery Document, FromJSON a) => ToQuery Document a | |
(ToBuildQuery Table, FromJSON a) => ToQuery Table [(Document, a)] | |
(ToBuildQuery (Expr (StreamType True v)), ExtractValue ValueTypeKind v a) => ToQuery (Expr (StreamType True v)) [(Document, a)] |
insert :: (ToValue a, ToValueType (ExprType a) ~ ObjectType) => Table -> a -> WriteQuery DocumentSource
Insert a document into a table
>>>
d <- run h $ insert t (object ["name" .= "banana", "color" .= "red"])
insertMany :: (ToValue a, ToValueType (ExprType a) ~ ObjectType) => Table -> [a] -> WriteQuery [Document]Source
Insert many documents into a table
upsert :: (ToValue a, ToValueType (ExprType a) ~ ObjectType) => Table -> a -> WriteQuery DocumentSource
Insert a document into a table, overwriting a document with the same primary key if one exists.
upsertMany :: (ToValue a, ToValueType (ExprType a) ~ ObjectType) => Table -> [a] -> WriteQuery [Document]Source
Insert many documents into a table, overwriting any existing documents with the same primary key.
update :: (ToExpr sel, ExprType sel ~ StreamType True out, ToMapping map, MappingFrom map ~ out, MappingTo map ~ ObjectType) => sel -> map -> WriteQuery ()Source
Update a table
>>>
t <- run h $ tableCreate (table "example") def
>>>
run h $ insertMany t [object ["a" .= 1, "b" .= 11], object ["a" .= 2, "b" .= 12]]
>>>
run h $ update t (object ["b" .= 20])
>>>
run h $ t
replace :: (ToExpr sel, ExprIsView sel ~ True, ToJSON a) => sel -> a -> WriteQuery ()Source
Replace documents in a table
delete :: (ToExpr sel, ExprIsView sel ~ True) => sel -> WriteQuery ()Source
Delete one or more documents from a table
Selecting data
get :: (ToExpr e, ExprType e ~ StreamType True ObjectType, ToValue k) => e -> k -> ObjectExprSource
Get a document by primary key
filter' :: (ToMapping m, ToStream e, MappingFrom m `HasToStreamValueOf` e) => m -> e -> Expr (ExprType e)Source
Get all the documents for which the given predicate is true
between :: (ToJSON a, ToStream e, ObjectType `HasToStreamValueOf` e) => Maybe a -> Maybe a -> e -> Expr (ExprType e)Source
Get all documents between two primary keys (both keys are inclusive)
Joins
innerJoin :: (ToStream a, l `HasToStreamValueOf` a, ToStream b, r `HasToStreamValueOf` b) => a -> b -> (ValueExpr l -> ValueExpr r -> BoolExpr) -> Expr (StreamType False ObjectType)Source
outerJoin :: (ToStream a, l `HasToStreamValueOf` a, ToStream b, r `HasToStreamValueOf` b) => a -> b -> (ValueExpr l -> ValueExpr r -> BoolExpr) -> Expr (StreamType False ObjectType)Source
eqJoin :: (ToStream a, ObjectType `HasToStreamValueOf` a, ToExpr b, ExprType b ~ ExprType Selection) => a -> String -> b -> Expr (StreamType False ObjectType)Source
zip' :: (ToStream e, ObjectType `HasToStreamValueOf` e) => e -> Expr (StreamType False ObjectType)Source
Transformations
map' :: (ToMapping m, ToStream e, MappingFrom m `HasToStreamValueOf` e) => m -> e -> Expr (StreamType False (MappingTo m))Source
concatMap' :: (ToMapping m, MappingTo m ~ ArrayType, ToStream e, MappingFrom m `HasToStreamValueOf` e) => m -> e -> Expr (StreamType False t)Source
orderBy :: (ToOrder o, ToStream e, a `HasToStreamValueOf` e) => [o] -> e -> Expr (StreamType (ExprIsView e) a)Source
skip :: (ToStream e, t `HasToStreamValueOf` e, ToExpr n, ExprType n ~ ValueType NumberType) => e -> n -> Expr (StreamType (ExprIsView e) t)Source
limit :: (ToStream e, t `HasToStreamValueOf` e, ToExpr n, ExprType n ~ ValueType NumberType) => e -> n -> Expr (StreamType (ExprIsView e) t)Source
slice :: (ToStream e, t `HasToStreamValueOf` e, ToExpr n, ExprType n ~ ValueType NumberType, ToExpr m, ExprType m ~ ValueType NumberType) => e -> n -> m -> Expr (StreamType (ExprIsView e) t)Source
nth :: (ToStream e, t `HasToStreamValueOf` e, ToExpr n, ExprType n ~ ValueType NumberType) => e -> n -> ValueExpr tSource
pluck :: (ToStream e, ObjectType `HasToStreamValueOf` e) => [String] -> e -> Expr (StreamType False ObjectType)Source
without :: (ToStream e, ObjectType `HasToStreamValueOf` e) => [String] -> e -> Expr (StreamType False ObjectType)Source
union' :: (ToStream a, t `HasToStreamValueOf` a, ToStream b, t `HasToStreamValueOf` b) => a -> b -> Expr (StreamType False t)Source
Aggregation
reduce :: (ToValue z, ToValueType (ExprType z) ~ a, ToStream e, b `HasToStreamValueOf` e, ToExpr c, ExprIsView c ~ False) => e -> z -> (ValueExpr a -> ValueExpr b -> c) -> Expr (ExprType c)Source
distinct :: (ToStream e, v `HasToStreamValueOf` e) => e -> Expr (StreamType False v)Source
groupedMapReduce :: (ToValue group, ToValue value, ToValue acc, ToValueType (ExprType acc) ~ b, ToValue acc', ToValueType (ExprType acc') ~ b, ToStream e, a `HasToStreamValueOf` e) => (ValueExpr a -> group) -> (ValueExpr a -> value) -> acc -> (ValueExpr b -> ValueExpr v -> acc') -> e -> Expr (StreamType False b)Source
groupBy' :: (ToStream e, ObjectType `HasToStreamValueOf` e) => [String] -> MapReduce ObjectType b c d -> e -> Expr (StreamType False d)Source
Reductions
Document manipulation
pick :: HasValueType e ObjectType => [String] -> e -> ObjectExprSource
unpick :: HasValueType e ObjectType => [String] -> e -> ObjectExprSource
merge :: (ToExpr a, ExprType a ~ ValueType ObjectType, ToExpr b, ExprType b ~ ValueType ObjectType) => a -> b -> ObjectExprSource
append :: (HasValueType a ArrayType, HasValueType b x) => a -> b -> ArrayExprSource
(!) :: (ToExpr a, ExprValueType a ~ ObjectType) => a -> String -> ValueExpr tSource
Get the value of the field of an object
When GHC thinks the result is ambiguous, it may have to be annotated.
>>>
run h $ (get (table "tea") "black" ! "water_temperature" :: NumberExpr)
95
(!?) :: HasValueType a ObjectType => a -> String -> BoolExprSource
Operators
add :: HaveValueType a b NumberType => a -> b -> NumberExprSource
sub :: HaveValueType a b NumberType => a -> b -> NumberExprSource
mul :: HaveValueType a b NumberType => a -> b -> NumberExprSource
div' :: HaveValueType a b NumberType => a -> b -> NumberExprSource
mod :: HaveValueType a b NumberType => a -> b -> NumberExprSource
and' :: HaveValueType a b BoolType => a -> b -> BoolExprSource
or' :: HaveValueType a b BoolType => a -> b -> BoolExprSource
eq :: (HasValueType a x, HasValueType b y) => a -> b -> BoolExprSource
ne :: (HasValueType a x, HasValueType b y) => a -> b -> BoolExprSource
gt :: (HaveValueType a b v, CanCompare v) => a -> b -> BoolExprSource
ge :: (HaveValueType a b v, CanCompare v) => a -> b -> BoolExprSource
lt :: (HaveValueType a b v, CanCompare v) => a -> b -> BoolExprSource
le :: (HaveValueType a b v, CanCompare v) => a -> b -> BoolExprSource
not' :: HasValueType a BoolType => a -> BoolExprSource
Control structures
if' :: (ToValue e, ToValueType (ExprType e) ~ BoolType, ToExpr a, ExprTypeNoView (ExprType a) ~ x, ToExpr b, ExprTypeNoView (ExprType b) ~ x, ExprTypeIsView x ~ False) => e -> a -> b -> Expr xSource
forEach :: (ToStream a, v `HasToStreamValueOf` a) => a -> (ValueExpr v -> WriteQuery b) -> WriteQuery ()Source
Execute a write query for each element of the stream
>>>
run h $ forEach [1,2,3::Int] (\x -> insert (table "fruits") (obj ["n" := x]))
js :: String -> Expr (ValueType any)Source
A javascript expression
It is often necessary to specify the result type:
>>>
run h $ (js "1 + 2" :: NumberExpr)
3
jsfun :: ToValue e => String -> e -> Expr (ValueType y)Source
A javascript function
>>>
let squareRoot = jsfun "Math.sqrt" :: NumberExpr -> NumberExpr
>>>
run h $ squareRoot 5 :: IO Double
2.23606797749979
Sequence conversion
streamToArray :: (ToExpr e, ExprType e ~ StreamType w t) => e -> Expr (ValueType ArrayType)Source
Convert a stream into an array
arrayToStream :: (ToExpr e, ExprType e ~ ValueType ArrayType) => e -> Expr (StreamType False t)Source
Convert an array into a stream
Short constructors
Types and type classes
A query returning a
Functor (Query w) | |
ToBuildQuery (Query w a) | |
ToBuildQuery (Query w a) => ToQuery (Query w a) a |
class ToBuildQuery a => ToQuery a b | a -> b whereSource
toQuery :: a -> Query (BuildViewQuery a) bSource
(ToBuildQuery Document, FromJSON a) => ToQuery Document a | |
(ToBuildQuery Table, FromJSON a) => ToQuery Table [(Document, a)] | |
(ToBuildQuery (Expr (ValueType v)), ExtractValue ValueTypeKind v a) => ToQuery (Expr (ValueType v)) a | |
ToBuildQuery (WriteQuery a) => ToQuery (WriteQuery a) a | |
(ToBuildQuery (Expr (StreamType False v)), ExtractValue ValueTypeKind v a) => ToQuery (Expr (StreamType False v)) [a] | |
(ToBuildQuery (Expr (StreamType True v)), ExtractValue ValueTypeKind v a) => ToQuery (Expr (StreamType True v)) [(Document, a)] | |
ToBuildQuery (Query w a) => ToQuery (Query w a) a |
data ValueTypeKind Source
The types of values
FromJSON a => ExtractValue ValueTypeKind OtherValueType a | |
ExtractValue ValueTypeKind NoneType () | |
(IsString a, FromJSON a) => ExtractValue ValueTypeKind StringType a | |
FromJSON a => ExtractValue ValueTypeKind ArrayType a | |
FromJSON a => ExtractValue ValueTypeKind ObjectType a | |
ExtractValue ValueTypeKind BoolType Bool | |
(Num a, FromJSON a) => ExtractValue ValueTypeKind NumberType a |
data ExprTypeKind Source
The type of a RQL expression
The type hierarchy has 3 branches:
- A read-only sequence:
StreamType False
- A selection (also called a view):
StreamType True
- A value (a JSON object, array or primitive type):
ExprType
StreamType Bool ValueTypeKind | When the flag is true, it can be updated or deleted |
ValueType ValueTypeKind |
type ExprIsView e = ExprTypeIsView (ExprType e)Source
type family ExprValueType expr :: ValueTypeKindSource
The type of the value of an Expr
An RQL expression
Expr :: QueryM (MaybeView (ExprIsView (Expr t)), Term) -> Expr t | |
SpotExpr :: Document -> Expr (StreamType True ObjectType) |
Fractional (Expr (ValueType NumberType)) | |
Num (Expr (ValueType NumberType)) | |
ToValue (Expr (ValueType t)) | |
ToValue (Expr (StreamType w t)) | |
ToExpr (Expr t) | |
ToMapping (Expr (ValueType t)) | |
ToStream (Expr (ValueType ArrayType)) | |
ToExpr (Expr (StreamType w t)) => ToStream (Expr (StreamType w t)) | |
ToBuildQuery (Expr (ValueType v)) | |
ToBuildQuery (Expr (StreamType False v)) | |
ToBuildQuery (Expr (StreamType True v)) | |
(ToBuildQuery (Expr (ValueType v)), ExtractValue ValueTypeKind v a) => ToQuery (Expr (ValueType v)) a | |
(ToBuildQuery (Expr (StreamType False v)), ExtractValue ValueTypeKind v a) => ToQuery (Expr (StreamType False v)) [a] | |
(ToBuildQuery (Expr (StreamType True v)), ExtractValue ValueTypeKind v a) => ToQuery (Expr (StreamType True v)) [(Document, a)] |
Convert something into an Expr
type ExprType o :: ExprTypeKindSource
Convert something into a value Expr
type HasValueType a v = (ToValue a, ToValueType (ExprType a) ~ v)Source
Aliases for type constraints on expressions
type HaveValueType a b v = (HasValueType a v, HasValueType b v)Source
type NumberExpr = Expr (ValueType NumberType)Source
Simple aliases for different Expr types
type ObjectExpr = Expr (ValueType ObjectType)Source
type StringExpr = Expr (ValueType StringType)Source
type NumberStream = Expr (StreamType False NumberType)Source
type BoolStream = Expr (StreamType False BoolType)Source
type ObjectStream = Expr (StreamType False ObjectType)Source
type ArrayStream = Expr (StreamType False ArrayType)Source
type StringStream = Expr (StreamType False StringType)Source
type Selection = Expr (StreamType True ObjectType)Source
class CanCompare a Source
What values can be compared with eq, ne, lt, gt, le and ge
A sequence is either a stream or an array
type SequenceType e t :: ConstraintSource
~ ValueTypeKind a ArrayType => Sequence (ValueType a) | |
Sequence (StreamType w t) |
class ToMapping map whereSource
Convert objects into mappings
type MappingFrom map :: ValueTypeKindSource
type MappingTo map :: ValueTypeKindSource
toMapping :: map -> Mapping (MappingFrom map) (MappingTo map)Source