packages feed

rethinkdb 1.8.0.3 → 1.8.0.4

raw patch · 4 files changed

+43/−9 lines, 4 files

Files

Database/RethinkDB.hs view
@@ -39,6 +39,7 @@    -- * Writing data +  WriteResponse(..),   insert, upsert,   update, replace, delete,   returnVals,
Database/RethinkDB/Driver.hs view
@@ -1,16 +1,21 @@+{-# LANGUAGE OverloadedStrings #-}+ module Database.RethinkDB.Driver (   run,   run',   Result(..),   runOpts,   RunOptions(..),+  WriteResponse(..)   ) where -import Data.Aeson (Value, FromJSON, fromJSON)+import Data.Aeson (Value(..), FromJSON(..), fromJSON, (.:), (.:?)) import qualified Data.Aeson (Result(Error, Success)) import Control.Monad import Control.Concurrent.MVar (MVar, takeMVar) import Data.Sequence ((|>))+import Data.Text (Text)+import Control.Applicative ((<$>), (<*>))  import Database.RethinkDB.Protobuf.Ql2.Query (Query(..)) import Database.RethinkDB.Protobuf.Ql2.Query.AssocPair (AssocPair(..))@@ -75,7 +80,7 @@  instance FromJSON a => Result [a] where   convertResult = collect <=< convertResult-  + instance FromJSON a => Result (Maybe a) where   convertResult r = do     c <- convertResult r@@ -87,3 +92,31 @@         case cadr of           Nothing -> return $ Just a           Just _ -> return Nothing++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+  } deriving Show++instance FromJSON WriteResponse where+  parseJSON (Data.Aeson.Object o) =+    WriteResponse+    <$> o .: "inserted"+    <*> o .: "deleted"+    <*> o .: "replaced"+    <*> o .: "unchanged"+    <*> o .: "skipped"+    <*> o .: "errors"+    <*> o .:? "first_error"+    <*> o .:? "generated_keys"+    <*> o .:? "old_val"+    <*> o .:? "new_val"+  parseJSON _ = mzero
Database/RethinkDB/Functions.hs view
@@ -273,29 +273,29 @@ tableList :: Database -> ReQL tableList (O.Database name) = op TABLE_LIST [name] () --- | Get a document by primary key +-- | Get a document by primary key get :: (Expr s, Expr k) => k -> s -> ReQL get k e = op GET (e, k) ()  -- | Insert a document or a list of documents into a table insert :: (Expr table, Expr object) => object -> table -> ReQL-insert a tb = op INSERT (tb, a) ()+insert a tb = canReturnVals $ op INSERT (tb, a) ()  -- | Like insert, but update existing documents with the same primary key upsert :: (Expr table, Expr object) => object -> table -> ReQL-upsert a tb = op INSERT (tb, a) ["upsert" := P.True]+upsert a tb = canReturnVals $ op INSERT (tb, a) ["upsert" := P.True]  -- | Add to or modify the contents of a document update :: (Expr selection) => (ReQL -> ReQL) -> selection -> ReQL-update f s = op UPDATE (s, f) ()+update f s = canReturnVals $ op UPDATE (s, f) ()  -- | Replace a document with another replace :: (Expr selection) => (ReQL -> ReQL) -> selection -> ReQL-replace f s = op REPLACE (s, f) ()+replace f s = canReturnVals $ op REPLACE (s, f) ()  -- | Delete the documents delete :: (Expr selection) => selection -> ReQL-delete s = op DELETE [s] ()+delete s = canReturnVals $ op DELETE [s] ()  -- | Convert a value to a different type coerceTo :: (Expr x) => ReQL -> x -> ReQL
rethinkdb.cabal view
@@ -1,5 +1,5 @@ name:                rethinkdb-version:             1.8.0.3+version:             1.8.0.4 description:         RethinkDB is a distributed document store with a powerful query language. synopsis:            RethinkDB driver for Haskell homepage:            http://github.com/atnnn/haskell-rethinkdb