4 ms·
When 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
by Dowwie 3y ago
When 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 :)