diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/db.zig | 28 |
1 files changed, 11 insertions, 17 deletions
@@ -4,29 +4,25 @@ const c = @cImport({ }); -const DataChunk = struct { +const Result = struct { + _res: c.duckdb_result, _chunk: c.duckdb_data_chunk, - pub fn deinit(self: * DataChunk) void { + pub fn deinit(self: *Result) void { + c.duckdb_destroy_result(&self._res); c.duckdb_destroy_data_chunk(&self._chunk); } - pub fn getSize(self: DataChunk) usize { + pub fn getSize(self: Result) usize { return c.duckdb_data_chunk_get_size(self._chunk); } -}; -const Result = struct { - _res: c.duckdb_result, - - pub fn deinit(self: *Result) void { - c.duckdb_destroy_result(&self._res); + pub fn fetchDataChunk(self: *Result) void{ + self._chunk = c.duckdb_fetch_chunk(self._res); } - pub fn fetchDataChunk(self: Result) ?DataChunk{ - var chunk : DataChunk = undefined; - chunk._chunk = c.duckdb_fetch_chunk(self._res); - return chunk; + pub fn exausted(self: Result) bool{ + return self._chunk != null; } }; @@ -52,6 +48,7 @@ const Connection = struct { if ( state == c.DuckDBError){ return error.DuckDBError; } + result.fetchDataChunk(); return result; } }; @@ -95,8 +92,5 @@ test "Query size" { var result = try connection.query("SELECT * FROM integers;"); defer result.deinit(); - var chunk = result.fetchDataChunk() orelse return error.DuckDBError; - defer chunk.deinit(); - - try std.testing.expect(3 == chunk.getSize()); + try std.testing.expect(3 == result.getSize()); } |