rethinkdb-client-driver 0.0.4 → 0.0.5
raw patch · 5 files changed
+23/−14 lines, 5 files
Files
- benchmark/Benchmark.hs +2/−2
- rethinkdb-client-driver.cabal +1/−1
- src/Database/RethinkDB.hs +8/−4
- src/Database/RethinkDB/Types.hs +11/−6
- test/Test.hs +1/−1
benchmark/Benchmark.hs view
@@ -18,7 +18,7 @@ db = Database "test" table :: Exp Table-table = Table "benchmark"+table = Table Nothing "benchmark" main :: IO ()@@ -35,7 +35,7 @@ prepare :: IO Handle prepare = do- h <- newHandle "localhost" defaultPort Nothing+ h <- newHandle "localhost" defaultPort Nothing (Database "test") void $ run h (CreateTable db "benchmark") void $ run h (InsertObject CRError table (HMS.singleton "id" (String "id")))
rethinkdb-client-driver.cabal view
@@ -1,5 +1,5 @@ name: rethinkdb-client-driver-version: 0.0.4+version: 0.0.5 license: MIT license-file: LICENSE author: Tomas Carnecky
src/Database/RethinkDB.hs view
@@ -49,6 +49,10 @@ data Handle = Handle { hSocket :: !Socket , hTokenRef :: !(IORef Token)++ , hDatabase :: !(Exp Database)+ -- ^ The database which should be used when the 'Table' expression+ -- doesn't specify one. } @@ -58,8 +62,8 @@ -- | Create a new handle to the RethinkDB server.-newHandle :: Text -> Int -> Maybe Text -> IO Handle-newHandle host port mbAuth = do+newHandle :: Text -> Int -> Maybe Text -> Exp Database -> IO Handle+newHandle host port mbAuth db = do sock <- createSocket host port -- Do the handshake dance. Note that we currently ignore the reply and@@ -71,7 +75,7 @@ -- one and then count up. ref <- newIORef 1 - return $ Handle sock ref+ return $ Handle sock ref db -- | Start a new query and wait for its (first) result. If the result is an@@ -128,7 +132,7 @@ return token where- msg = compileTerm $ do+ msg = compileTerm (hDatabase handle) $ do term' <- toTerm term options' <- toTerm emptyOptions return $ A.Array $ V.fromList
src/Database/RethinkDB/Types.hs view
@@ -48,13 +48,17 @@ -- is done using this as the context. data Context = Context- { varCounter :: Int+ { varCounter :: !Int -- ^ How many 'Var's have been allocated. See 'newVar'.++ , defaultDatabase :: !(Exp Database)+ -- ^ The default database for the case that the 'Table' expression+ -- doesn't specify one. } -compileTerm :: State Context A.Value -> A.Value-compileTerm e = evalState e (Context 0)+compileTerm :: Exp Database -> State Context A.Value -> A.Value+compileTerm db e = evalState e (Context 0 db) -- | Allocate a new var index from the context.@@ -365,7 +369,7 @@ Database :: Exp Text -> Exp Database- Table :: Exp Text -> Exp Table+ 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@@ -484,8 +488,9 @@ toTerm (Database name) = simpleTerm 14 [SomeExp name] - toTerm (Table name) =- simpleTerm 15 [SomeExp name]+ toTerm (Table mbDatabase name) = do+ db <- maybe (gets defaultDatabase) return mbDatabase+ simpleTerm 15 [SomeExp db, SomeExp name] toTerm (Filter f s) = simpleTerm 39 [SomeExp s, SomeExp (lift f)]
test/Test.hs view
@@ -55,7 +55,7 @@ main :: IO () main = do- h <- newHandle "localhost" defaultPort Nothing+ h <- newHandle "localhost" defaultPort Nothing (Database "test") hspec $ spec h