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

Add upsert support to Model.save, Document.save, and Document.saveAll #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

mstade
Copy link

@mstade mstade commented Nov 6, 2014

This adds a second (optional) parameter to Model.save, Document.save,
and Document.saveAll; which allows you to specify how conflicts should be
handled when inserting documents.

When options.conflict is set to either update or replace, documents
will be updated or replaced when inserted if they already exist in the
database. If the value is set to anything else it will revert to error.

The default conflict resolution is error, which is in line with how it
worked before since that's what RethinkDB defaults to.

This adds a second (optional) parameter to `Model.save`, which allows
you to specify how conflicts should be handled when inserting documents.

When `options.conflict` is set to either `update` or `replace`, documents
will be updated or replaced when inserted if they already exist in the
database. If the value is set to anything else it will revert to `error`.

The default conflict resolution is `error`, which is in line with how it
worked before since that's what RethinkDB defaults to.
@marshall007
Copy link
Contributor

It would also be great to have these same options on Model.saveAll().

@mstade
Copy link
Author

mstade commented Nov 7, 2014

Agreed @marshall007, I'm being bitten pretty hard by that at the moment. I'll see if I can get that working as well.

This adds a second (optional) parameter to `Document.save` and
`Document.saveAll`, which allows you to specify how conflicts should be
handled when inserting documents.

When `options.conflict` is set to either `update` or `replace`, documents
will be updated or replaced when inserted if they already exist in the
database. If the value is set to anything else it will revert to `error`.

The default conflict resolution is `error`, which is in line with how it
worked before since that's what RethinkDB defaults to.
@mstade mstade changed the title Add upsert support to Model.save Add upsert support to Model.save, Document.save, and Document.saveAll Nov 7, 2014
@mstade
Copy link
Author

mstade commented Nov 7, 2014

Ok so I hacked something in for Document.save and Document.saveAll as well. I'm not too pleased with this however, since it requires you to specify null for modelsToSave when calling Document.saveAll; i.e.:

myDocument.saveAll(null, { conflict: 'replace' })

Ain't pretty.

@neumino
Copy link
Owner

neumino commented Feb 23, 2015

Err I'm really sorry, I missed this pull request -_-

I'll add options for Model.save but I'm a bit more worried about Document.save because of the joined documents. I'll try to merge this, but since I've refactored Document.save, this seems hard.

Again, really sorry @mstade for missing your pull request :/

@xpepermint
Copy link

+1 (Document.save)

@mstade
Copy link
Author

mstade commented May 25, 2015

@neumino Don't worry about it buddy, it's easily done in all the noise! Since publishing this PR I've moved on to other things and am no longer actively using either RethinkDB and thus not thinky either. At the time, missing upsert was a big deal(tm) and a pretty big gotcha. Whether this is still true with current versions of thinky I wouldn't know, so you may want to consider just closing this PR or creating a new issue to deal with this for a more up-to-date code base.

Finally – thanks for your great efforts to bring better tools to the developer community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants