luckyframework / avram

A Crystal database wrapper for reading, writing, and migrating Postgres databases.
https://luckyframework.github.io/avram/
MIT License
165 stars 64 forks source link

Rename current #upsert(!) methods #790

Open grepsedawk opened 2 years ago

grepsedawk commented 2 years ago

As presented in https://github.com/luckyframework/avram/pull/789 , the upserts in current avram are more of "find_or_create", instead of utilizing upsert from postgres: https://www.postgresql.org/docs/9.5/sql-insert.html (INSERT INTO ... ON CONFLICT UPDATE)

This can be confusing to newcomers expecting upsert to be a single UPSERT query.

jwoertink commented 2 years ago

The main issue I have with this is that an operation should never be used as a find. That's left to the query objects. I think even though this doesn't perform a DB level upsert, the name still works well since you're either updating a record or inserting a record.

We should look at getting the ON CONFLICT built in to the query builder directly so we can do this in a single query, but I'd like to keep the method name as upsert on this one.