rethinkdb-client-driver 0.0.16 → 0.0.17
raw patch · 4 files changed
+80/−6 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Database.RethinkDB: MkArray :: [Exp a] -> Exp (Array a)
+ Database.RethinkDB: WaitDatabase :: Exp Database -> Exp Object
+ Database.RethinkDB: WaitTable :: Exp Table -> Exp Object
- Database.RethinkDB: CreateIndex :: Exp Table -> Exp Text -> (Exp Object -> Exp Datum) -> Exp Object
+ Database.RethinkDB: CreateIndex :: Exp Table -> Exp Text -> (Exp Object -> Exp a) -> Exp Object
- Database.RethinkDB: WaitIndex :: Exp Table -> [Exp Text] -> Exp Object
+ Database.RethinkDB: WaitIndex :: Exp Table -> [Exp Text] -> Exp (Array Object)
Files
- rethinkdb-client-driver.cabal +1/−1
- src/Database/RethinkDB/Types.hs +42/−5
- src/Database/RethinkDB/Types/Datum.hs +29/−0
- test/Test.hs +8/−0
rethinkdb-client-driver.cabal view
@@ -1,5 +1,5 @@ name: rethinkdb-client-driver-version: 0.0.16+version: 0.0.17 license: MIT license-file: LICENSE author: Tomas Carnecky
src/Database/RethinkDB/Types.hs view
@@ -1,10 +1,10 @@ {-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-}-{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeFamilies #-} module Database.RethinkDB.Types where @@ -128,7 +128,14 @@ parseResponse = responseAtomParser +instance FromResponse Char where+ parseResponse = responseAtomParser +instance FromResponse [Char] where+ parseResponse = responseAtomParser+++ ------------------------------------------------------------------------------ -- | For strings, we're using the Haskell 'Text' type. @@ -339,12 +346,18 @@ -- their values into constants. + MkArray :: [Exp a] -> Exp (Array a)+ -- Create an array from a list of expressions. This is an internal function,+ -- you should use 'lift' instead.++ -------------------------------------------------------------------------- -- Database administration ListDatabases :: Exp (Array Text) CreateDatabase :: Exp Text -> Exp Object DropDatabase :: Exp Text -> Exp Object+ WaitDatabase :: Exp Database -> Exp Object --------------------------------------------------------------------------@@ -353,6 +366,7 @@ 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 --------------------------------------------------------------------------@@ -360,13 +374,13 @@ ListIndices :: Exp Table -> Exp (Array Text) - CreateIndex :: Exp Table -> Exp Text -> (Exp Object -> Exp Datum) -> Exp Object+ CreateIndex :: (IsDatum a) => Exp Table -> Exp Text -> (Exp Object -> Exp a) -> Exp Object -- Create a new secondary index on the table. The index has a name and a -- projection function which is applied to every object which is added to the table. DropIndex :: Exp Table -> Exp Text -> Exp Object IndexStatus :: Exp Table -> [Exp Text] -> Exp (Array Object)- WaitIndex :: Exp Table -> [Exp Text] -> Exp Object+ WaitIndex :: Exp Table -> [Exp Text] -> Exp (Array Object) Database :: Exp Text -> Exp Database@@ -480,7 +494,10 @@ toTerm (Constant datum) = toTerm $ toDatum datum + toTerm (MkArray xs) =+ simpleTerm 2 (map SomeExp xs) + toTerm ListDatabases = noargTerm 59 @@ -490,7 +507,10 @@ toTerm (DropDatabase name) = simpleTerm 58 [SomeExp name] + toTerm (WaitDatabase db) =+ simpleTerm 177 [SomeExp db] + toTerm (ListTables db) = simpleTerm 62 [SomeExp db] @@ -500,7 +520,10 @@ toTerm (DropTable db name) = simpleTerm 61 [SomeExp db, SomeExp name] + toTerm (WaitTable table) =+ simpleTerm 177 [SomeExp table] + toTerm (ListIndices table) = simpleTerm 77 [SomeExp table] @@ -723,6 +746,14 @@ type Simplified Double = Double lift = Constant +instance Lift Exp Char where+ type Simplified Char = Char+ lift = Constant++instance Lift Exp String where+ type Simplified String = String+ lift = Constant+ instance Lift Exp Text where type Simplified Text = Text lift = Constant@@ -747,6 +778,10 @@ type Simplified (Array Datum) = (Array Datum) lift = Constant +instance Lift Exp [Exp a] where+ type Simplified [Exp a] = Array a+ lift = MkArray+ instance Lift Exp (Exp a -> Exp r) where type Simplified (Exp a -> Exp r) = Exp r lift f = Function $ do@@ -800,6 +835,8 @@ type instance Result Text = Text type instance Result Double = Double type instance Result Int = Int+type instance Result Char = Char+type instance Result String = String type instance Result Bool = Bool type instance Result ZonedTime = ZonedTime
src/Database/RethinkDB/Types/Datum.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleInstances #-}@@ -14,6 +15,7 @@ import Control.Monad import Data.Text (Text)+import qualified Data.Text as T import Data.Time import Data.Scientific import Data.Time.Clock.POSIX@@ -259,6 +261,33 @@ instance FromDatum Int where parseDatum (Number x) = pure $ floor x parseDatum _ = fail "Int"++++------------------------------------------------------------------------------+-- Char++instance ToDatum Char where+ toDatum = String . T.singleton++instance FromDatum Char where+ parseDatum (String x) =+ if T.compareLength x 1 == EQ+ then pure $ T.head x+ else fail "Expected a string of length 1"+ parseDatum _ = fail "Char"++++------------------------------------------------------------------------------+-- [Char] (aka String)++instance ToDatum [Char] where+ toDatum = String . T.pack++instance FromDatum [Char] where+ parseDatum (String x) = pure $ T.unpack x+ parseDatum _ = fail "String"
test/Test.hs view
@@ -74,6 +74,10 @@ -- and the server responds with what the driver expects. describe "roundtrips" $ do describe "primitive values" $ do+ it "Char" $ property $ \(x :: Char) ->+ monadic $ ((Right x)==) <$> run h (lift x)+ it "String" $ property $ \(x :: String) ->+ monadic $ ((Right x)==) <$> run h (lift x) it "Double" $ property $ \(x :: Double) -> monadic $ ((Right x)==) <$> run h (lift x) it "Text" $ property $ \(x :: Text) ->@@ -139,3 +143,7 @@ res <- run h $ call1 (3*) (lift a) return $ res == (Right $ a * 3)++ describe "lifts" $ do+ it "[Exp a]" $ property $ \(xs :: [Datum]) -> monadic $ do+ expectSuccess h (lift (map lift xs :: [Exp Datum])) (V.fromList xs)