diff --git a/integration_tests/client.zig b/integration_tests/client.zig index ddc52f1..c2dd114 100644 --- a/integration_tests/client.zig +++ b/integration_tests/client.zig @@ -241,11 +241,18 @@ test "prepare execute with result" { .c = 3, }; - var dest: MyType = undefined; while (try rows.next(allocator)) |row| { defer row.deinit(allocator); - try row.scan(&dest); - try std.testing.expectEqualDeep(expected, dest); + { + var dest: MyType = undefined; + try row.scan(&dest); + try std.testing.expectEqualDeep(expected, dest); + } + { + const dest = try row.scanAlloc(MyType, allocator); + defer allocator.destroy(dest); + try std.testing.expectEqualDeep(&expected, dest); + } } } } diff --git a/src/result.zig b/src/result.zig index 0178ea5..7a621a5 100644 --- a/src/result.zig +++ b/src/result.zig @@ -159,18 +159,12 @@ pub const BinaryResultRow = struct { } // returns a pointer to allocated struct object, caller must remember to call destroy on the object after use - pub fn scanAlloc(b: *const BinaryResultRow, allocator: std.mem.Allocator) !*b.structType() { - const S = b.structType(); + pub fn scanAlloc(b: *const BinaryResultRow, comptime S: type, allocator: std.mem.Allocator) !*S { const s = try allocator.create(S); _ = try b.scan(s); return s; } - fn structType(b: *const BinaryResultRow) type { - _ = b; - @panic("not implemente"); - } - pub fn deinit(text_result_set: *const BinaryResultRow, allocator: std.mem.Allocator) void { text_result_set.packet.deinit(allocator); }