4 ms·
Either do a patch with a new struct, or do full updates (what I typically do). I have a few dynamic queries, but for the most what I'm doing is relatively stra
by shpongled 3y ago
Either do a patch with a new struct, or do full updates (what I typically do).
I have a few dynamic queries, but for the most what I'm doing is relatively straightforward. I still prefer this over using an ORM, personally.
- Dowwie 3y agoWhen you partially update a table record, you need to determine which columns you want to update and prepare them as parameters, only including those that need to be changed. This is straightforward work for an ORM and/or query builder but not parameterized SQL. What does your implementation look like, as I can't follow your explanation. I found that both the parameterized SQL and ORM/QB have an important role to play due to the partial updates and occasionally query building exercise. None is ideal for every situation.
- shpongled 3y agoYeah, sorry that wasn't very clear. One option for a partial update is do define a new `Update` struct: struct Bar { id: Uuid, column_1: i64, column_2: i64, column_3: String, column_4: Uuid, } struct UpdateBar { column_1: Option<i64>, column_2: Option<i64>, column_3: Option<String>, column_4: Option<Uuid>, } UPDATE some_table SET column_1 = COALESCE($1, column_1), column_2 = COALESCE($2, column_2), column_3 = COALESCE($3, column_3), column_4 = COALESCE($4, column_4), WHERE id = some_id; Or, you just never do partial updates :)