go-reform / reform

A better ORM for Go, based on non-empty interfaces and code generation.
https://gopkg.in/reform.v1
MIT License
1.45k stars 73 forks source link

UPSERT with single database statement #14

Open AlekSi opened 8 years ago

AlekSi commented 8 years ago

Several RDBMS support UPSERT (INSERT or UPDATE with a single statement):

We should add Upsert method to reform. It should use a single RDBMS-specific statement. Behaviour could be RDBMS-specific too but well documented (see PostgreSQL wiki link for the good overview). It should not try to emulate it in unsupported RDBMS with several queries and/or transactions, it will return an error instead.

WIP branch that could be useful: https://github.com/go-reform/reform/tree/upsert.

AlekSi commented 7 years ago

@AlphaB What is your usecase?

AlphaB commented 7 years ago

@AlekSi I have a table with id (pk), user_id (reference to users table), entity_id and some other columns. There is a unique index on user_id and entity_id columns and I want to be able to upsert records into this table by user_id and entity_id instead of making SELECT and INSERT/UPDATE. That's it.