luckyframework / luckyframework/avram

Bulk increment/decrement columns

Open
#346 0 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

We have bulk updates, but we should also have bulk increment/decrement!

```crystal
UserQuery.new.update(increment_visits: 1)
```

I think the simple MVP solution here is to generate an `incremenet_*` and `decrement_*` for each column and not try to get too fancy and do it only or Int columns....unless it is easy to do. If it is then we should only do it for columns that *can* be incremeneted

Here is where we're generating columns for bulk update: https://github.com/luckyframework/avram/blob/45cf17d7b87b08d08f0816c3ac274796466aca0d/src/avram/base_query_template.cr#L39-L43

This may also require adding something to the QueryBuilder to allow incrementing, but if we're lucky we can just do this without touching it

We should also add an option to include a hash as a nice fallback, but that can come later if it is hard

Also may want to consider info here: https://medium.com/harrys-engineering/atomic-increment-decrement-operations-in-sql-and-fun-with-locks-f7b124d37873

Contributor guide

Open the contributing guide

Research direction

Start with src/avram/base_query_template.cr around lines 39-43, where bulk-update columns are generated, then inspect the QueryBuilder to determine whether it supports atomic increment and decrement expressions. Define the supported column scope and verify that bulk increment/decrement calls update the intended database values without requiring the later hash fallback.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.