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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an upsert! function #17

Open
camsaul opened this issue May 31, 2017 · 2 comments
Open

Add an upsert! function #17

camsaul opened this issue May 31, 2017 · 2 comments

Comments

@camsaul
Copy link
Member

camsaul commented May 31, 2017

Right now to do an "upsert" operation you have to do

(or (db/update! ...) ; update! returns truthy value iff something was updated
    (db/insert!))

However, that is subject to race conditions 馃檧

It would be nice to simplify this common pattern and avoid the race conditions with an upsert! function or something like that. (suggestion credit: @thearthur)

@RokLenarcic
Copy link

When using H2 I've just used MERGE statements, which does what you want.

@trinityXmontoya
Copy link

trinityXmontoya commented Aug 10, 2019

i'd be happy to try working on this, can you suggest an implementation that would avoid the race condition?
ex. a query for existence first by id & then an insert/update based on that?
i know upsert is available in a few databases ~Postgres's INSERT ON CONFLICT but imagine raw SQL isn't an option bc that command isn't supported by all the dbs that u can connect to w JDBC.

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

No branches or pull requests

3 participants