zig-sqlite
zig-sqlite copied to clipboard
Reuse same field/bind a field twice?
Say I have a table entry structure something like the following:
const User = struct {
id: usize,
name: []const u8,
age: usize,
};
And I want to update it fully, something like:
const direct_user_instance = User {
.id = 1; // should be fetched from db,
.name = "UpdateName";
.age = updated_age;
};
const update_query = "UPDATE user SET id = $id, name = $name, age = $age WHERE id = $id"; // using `id` field twice
try db.exec(update_query, .{}, direct_user_instance);
The use case might seem very rare and inefficient, but sometimes when many fields of a table entry needs to be updated we might want to do something like the above, and since it's Zig we literally can generate the "update_query
" for anytype
during comptime
.