Im using SQLite to store data for a Zig application. I'm trying to implement a ORM of sorts that takes a comptime T: type field that gets populated dynamically by the query:
pub fn run(query: *@This(), comptime T: type) ![]T {
var result = std.ArrayList(T).init(query.allocator);
errdefer result.deinit();
while(sqlite3_step(query.stmt)) == .row) {
const column_count = sqlite3.data_count(query.stmt);
if(column_count < 0) @panic("invalid column count");
var i: c_int = 0;
while(i < column_count):(i+=1) {
var column_name = sqlite3.column_name(query.stmt, i);
inline for (std.meta.fields(T)) |f| {
if(std.mem.eql(u8, std.mem.span(column_name), f.name)) {
std.log.info("matching column: {s} {any}", .{f.name, column_type});
// how to assign result here?
}
}
}
}
i'm hoping that insidde that inline for... section, i can assign result.FIELD_NAME. Is this possible?