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.
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.
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.
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 :)