Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re: Returning associated "_id" value from update functions. #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Database/MongoDB/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,17 @@ assignId doc = if X.any (("_id" ==) . label) doc

-- ** Update

save :: (MonadIO' m) => Collection -> Document -> Action m ()
save :: (MonadIO' m) => Collection -> Document -> Action m Value
-- ^ Save document to collection, meaning insert it if its new (has no \"_id\" field) or update it if its not new (has \"_id\" field)
save col doc = case look "_id" doc of
Nothing -> insert_ col doc
Just i -> repsert (Select ["_id" := i] col) doc
Nothing -> insert col doc
Just i -> repsert (Select ["_id" := i] col) doc >> return i

save_ :: (MonadIO' m) => Collection -> Document -> Action m ()
-- ^ Save document to collection, meaning insert it if its new (has no \"_id\" field) or update it if its not new (has \"_id\" field)
save_ col doc = case look "_id" doc of
Nothing -> insert_ col doc
Just i -> repsert (Select ["_id" := i] col) doc

replace :: (MonadIO m) => Selection -> Document -> Action m ()
-- ^ Replace first document in selection with given document
Expand Down
2 changes: 1 addition & 1 deletion mongoDB.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mongoDB
version: 1.2.0
version: 1.2.1
build-type: Simple
license: OtherLicense
license-file: LICENSE
Expand Down