persistent-mongoDB 2.0.2 → 2.0.3
raw patch · 2 files changed
+15/−12 lines, 2 filesdep ~persistent
Dependency ranges changed: persistent
Files
- Database/Persist/MongoDB.hs +13/−10
- persistent-mongoDB.cabal +2/−2
Database/Persist/MongoDB.hs view
@@ -374,7 +374,7 @@ (Multiply, _) -> error "expected PersistInt64 or PersistDouble for a subtraction" -- Obviously this could be supported for floats by multiplying with 1/x (Divide, _) -> throw $ PersistMongoDBUnsupported "divide not supported"-updateToMongoField (BackendUpdate _) = error "no backend updates implemented yet"+updateToMongoField (BackendUpdate {}) = error "no backend updates implemented yet" -- | convert a unique key into a MongoDB document@@ -588,18 +588,19 @@ -} -_id :: T.Text-_id = "_id"+-- | It would make more sense to call this _id, but GHC treats leading underscore in special ways+id_ :: T.Text+id_ = "_id" -- _id is always the primary key in MongoDB -- but _id can contain any unique value keyToMongoDoc :: (PersistEntity record, PersistEntityBackend record ~ DB.MongoContext) => Key record -> DB.Document keyToMongoDoc k = case entityPrimary $ entityDefFromKey k of- Nothing -> zipToDoc [DBName _id] values- Just pdef -> [_id DB.=: zipToDoc (primaryNames pdef) values]+ Nothing -> zipToDoc [DBName id_] values+ Just pdef -> [id_ DB.=: zipToDoc (primaryNames pdef) values] where- primaryNames = map fieldDB . primaryFields+ primaryNames = map fieldDB . compositeFields values = keyToValues k entityDefFromKey :: PersistEntity record => Key record -> EntityDef@@ -659,7 +660,7 @@ context <- ask let make = do cursor <- liftIO $ flip runReaderT context $ DB.find $ (makeQuery filts opts) {- DB.project = [_id DB.=: (1 :: Int)]+ DB.project = [id_ DB.=: (1 :: Int)] } pull context cursor return $ return make@@ -807,8 +808,10 @@ Right vs -> DB.val $ map toPersistValue vs fieldName :: forall record typ. (PersistEntity record) => EntityField record typ -> DB.Label-fieldName = idfix . unDBName . fieldDB . persistFieldDef- where idfix f = if f == "id" then _id else f+fieldName f | fieldHaskell fd == HaskellName "Id" = id_+ | otherwise = unDBName $ fieldDB $ fd+ where+ fd = persistFieldDef f docToEntityEither :: forall record. (PersistEntity record) => DB.Document -> Either T.Text (Entity record)@@ -837,7 +840,7 @@ eitherFromPersistValues entDef doc = let castDoc = assocListFromDoc doc -- normally _id is the first field- mKey = lookup _id castDoc+ mKey = lookup id_ castDoc in case mKey of Nothing -> Left "could not find _id field" Just kpv -> fromPersistValues (map snd $ orderPersistValues (toEmbedEntityDef entDef) castDoc)
persistent-mongoDB.cabal view
@@ -1,5 +1,5 @@ name: persistent-mongoDB-version: 2.0.2+version: 2.0.3 license: MIT license-file: LICENSE author: Greg Weber <greg@gregweber.info>@@ -19,7 +19,7 @@ library build-depends: base >= 4 && < 5- , persistent >= 2.0.2 && < 2.1+ , persistent >= 2.0.3 && < 2.1 , text >= 0.8 , transformers >= 0.2.1 , containers >= 0.2