persistent-mongoDB 1.4.1 → 1.4.1.1
raw patch · 2 files changed
+30/−7 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Database/Persist/MongoDB.hs +29/−6
- persistent-mongoDB.cabal +1/−1
Database/Persist/MongoDB.hs view
@@ -631,25 +631,48 @@ FilterOr [] -> -- Michael decided to follow Haskell's semantics, which seems reasonable to me. -- in Haskell an empty or is a False -- Perhaps there is a less hacky way of creating a query that always returns false?- ["$not" DB.=: ["$exists" DB.=: _id]]- FilterOr fs -> multiFilter "$or" fs+ ["$not" DB.=: [existsDollar DB.=: _id]]+ FilterOr fs -> multiFilter orDollar fs -- usually $and is unecessary, but it makes query construction easier in special cases FilterAnd [] -> [] FilterAnd fs -> multiFilter "$and" fs BackendFilter mf -> mongoFilterToDoc mf where- multiFilter :: forall record. (PersistEntity record, PersistEntityBackend record ~ MongoBackend) => String -> [Filter record] -> [DB.Field]- multiFilter multi fs = [T.pack multi DB.:= DB.Array (map (DB.Doc . filterToDocument) fs)]+ multiFilter :: forall record. (PersistEntity record, PersistEntityBackend record ~ MongoBackend) => Text -> [Filter record] -> [DB.Field]+ multiFilter multi fs = [multi DB.:= DB.Array (map (DB.Doc . filterToDocument) fs)] +existsDollar, orDollar :: Text+existsDollar = "$exists"+orDollar = "$or"+ filterToBSON :: forall a. ( PersistField a) => Text -> Either a [a] -> PersistFilter -> DB.Field filterToBSON fname v filt = case filt of- Eq -> fname DB.:= toValue v- _ -> fname DB.=: [(showFilter filt) DB.:= toValue v]+ Eq -> nullEq+ Ne -> nullNeq+ _ -> notEquality where+ dbv = toValue v+ notEquality = fname DB.=: [showFilter filt DB.:= dbv]++ nullEq = case dbv of+ DB.Null -> orDollar DB.=:+ [ [fname DB.:= DB.Null]+ , [fname DB.:= DB.Doc [existsDollar DB.:= DB.Bool False]]+ ]+ _ -> fname DB.:= dbv++ nullNeq = case dbv of+ DB.Null ->+ fname DB.:= DB.Doc+ [ showFilter Ne DB.:= DB.Null+ , existsDollar DB.:= DB.Bool True+ ]+ _ -> notEquality+ showFilter Ne = "$ne" showFilter Gt = "$gt" showFilter Lt = "$lt"
persistent-mongoDB.cabal view
@@ -1,5 +1,5 @@ name: persistent-mongoDB-version: 1.4.1+version: 1.4.1.1 license: MIT license-file: LICENSE author: Greg Weber <greg@gregweber.info>