-
Notifications
You must be signed in to change notification settings - Fork 6
db: ordered migrations, user_items table, and shared inventory helpers #32
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
Open
Seltraeh
wants to merge
5
commits into
decompfrontier:dev
Choose a base branch
from
Seltraeh:split/03-schema-foundation
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6cee1e1
db: ordered migrations, user_items table, and shared inventory helpers
Seltraeh 010d603
db: add upsert + IN predicates so Common.hpp can drop its raw SQL
Seltraeh 1d62d46
db: one column per stat in user_units, rec/lvl vocabulary
Seltraeh 40071e7
db: stop persisting fe_bp/fe_max_usable_bp
Seltraeh 3971a96
db: stop persisting leader_skill_id, read it from the MST
Seltraeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,32 @@ class DatabaseInterface final | |
| const std::string table, | ||
| const Cells cells); | ||
|
|
||
| /*! | ||
| * Inserts a row, or merges into the existing one on key conflict. | ||
| * | ||
| * Exists because plain insert ignores conflicting rows, which cannot express | ||
| * "add to the stack I already own". Without it callers fall back to raw | ||
| * execSqlCoro and the typed layer stops seeing their queries. | ||
| * | ||
| * Data cells are the inserted columns. On conflict with `conflict`, columns | ||
| * named in `accumulate` are ADDED to (col = col + excluded.col) and every | ||
| * other non-key data column is replaced. With an empty `accumulate` this is | ||
| * a plain insert-or-replace. | ||
| * | ||
| * @param database Database client or transaction to use. | ||
| * @param table SQL table name. | ||
| * @param cells Data cells for the insert. | ||
| * @param conflict Columns forming the conflict target. | ||
| * @param accumulate Data columns to accumulate instead of replace. | ||
| * @return Number of affected rows. | ||
| */ | ||
| static drogon::Task<InterfaceResult<>> upsert( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this needs to exist. why do we need to merge into the existing one on key conflict can u explain the mechanism that would prompt this? i dont see the point of having this |
||
| const Database database, | ||
| const std::string table, | ||
| const Cells cells, | ||
| const Keys conflict, | ||
| const Keys accumulate = {}); | ||
|
|
||
| /*! | ||
| * Deletes rows from a table. | ||
| * | ||
|
|
@@ -129,6 +155,38 @@ class DatabaseInterface final | |
| } | ||
| } | ||
|
|
||
| /*! | ||
| * Builds a WHERE clause from lookup cells. | ||
| * | ||
| * Handles both equality (Lookup) and IN (LookupIn) predicates, numbering | ||
| * placeholders from `from` and appending the values to bind — one cell per | ||
| * placeholder, IN lists expanded — to `binds` in that same order. Callers | ||
| * then bind `binds` rather than the original lookup cells. | ||
| * | ||
| * @param lookup Lookup cells to turn into predicates. | ||
| * @param from First placeholder number to use. | ||
| * @param binds Receives the values to bind, in placeholder order. | ||
| * @return SQL predicate text, without the leading WHERE. | ||
| */ | ||
| static std::string buildWhere(const Cells& lookup, size_t from, Cells& binds); | ||
|
|
||
| /*! | ||
| * Collects every predicate cell — equality and IN alike — in caller order. | ||
| */ | ||
| static Cells getLookupCells(const Cells& cells) | ||
| { | ||
| Cells output; | ||
| for (const auto& cell : cells) | ||
| { | ||
| if (cell.use == Use::Lookup || cell.use == Use::LookupIn) | ||
| { | ||
| output.push_back(cell); | ||
| } | ||
| } | ||
|
|
||
| return output; | ||
| } | ||
|
|
||
| /*! | ||
| * Filters mixed cells down to either lookup predicates or data values. | ||
| */ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this just a for loop for the query?
we shouldnt add a new method then, lets just have the loop on the outside. The point of these methods is not efficiency, but rather readability.