packages feed

persistent-mongoDB 1.2.2 → 1.2.3

raw patch · 2 files changed

+28/−3 lines, 2 files

Files

Database/Persist/MongoDB.hs view
@@ -37,6 +37,10 @@     , (->.), (~>.), (?->.), (?~>.)     , nestEq, multiEq +    -- * MongoDB specific PersistFields+    , Objectid+    , genObjectid+     -- * using connections     , withMongoDBConn     , withMongoDBPool@@ -74,6 +78,7 @@     ) where  import Database.Persist+import qualified Database.Persist.Sql as Sql  import qualified Control.Monad.IO.Class as Trans import Control.Exception (throw, throwIO)@@ -93,7 +98,7 @@ import Control.Monad.Trans.Class (lift) import Control.Monad.IO.Class (liftIO) import Data.Aeson (Value (Object, Number), (.:), (.:?), (.!=), FromJSON(..))-import Control.Monad (mzero)+import Control.Monad (mzero, liftM) import qualified Data.Conduit.Pool as Pool import Data.Time (NominalDiffTime) #ifdef HIGH_PRECISION_DATE@@ -150,6 +155,26 @@     _ -> Nothing  +-- | wrapper of 'ObjectId'+-- * avoids an orphan instance+-- * works around a Persistent naming issue+newtype Objectid = Objectid { unObjectId :: DB.ObjectId }+                   deriving (Show, Read, Eq, Ord)++-- | like 'genObjectId', but for 'Objectid'+genObjectid :: IO Objectid+genObjectid = Objectid `liftM` DB.genObjectId++instance PersistField Objectid where+    toPersistValue = oidToPersistValue . unObjectId+    fromPersistValue oid@(PersistObjectId _) = Right . Objectid $ persistObjectIdToDbOid oid+    fromPersistValue (PersistByteString bs) = fromPersistValue (PersistObjectId bs)+    fromPersistValue _ = Left $ T.pack "expected PersistObjectId"++instance Sql.PersistFieldSql Objectid where+    sqlType _ = Sql.SqlOther "doesn't make much sense for MongoDB"++ withMongoDBConn :: (Trans.MonadIO m, Applicative m)                 => Database -> HostName -> PortID                 -> Maybe MongoAuth -> NominalDiffTime@@ -620,7 +645,7 @@ assocListFromDoc = Prelude.map (\f -> ( (DB.label f), (fromJust . DB.cast') (DB.value f) ) )  oidToPersistValue :: DB.ObjectId -> PersistValue-oidToPersistValue =  PersistObjectId . Serialize.encode+oidToPersistValue = PersistObjectId . Serialize.encode  oidToKey :: (PersistEntity entity) => DB.ObjectId -> Key entity oidToKey = Key . oidToPersistValue
persistent-mongoDB.cabal view
@@ -1,5 +1,5 @@ name:            persistent-mongoDB-version:         1.2.2+version:         1.2.3 license:         MIT license-file:    LICENSE author:          Greg Weber <greg@gregweber.info>