diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-08-05 22:20:19 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-08-05 22:20:46 +0200 |
commit | 8efa7cb0013aae1708e2d815b7fa65f055062159 (patch) | |
tree | 4b815a71d8d09b00a29d9435f5b52369fa482081 /src/duckdb/Result.zig | |
parent | 2c5149d5ca84b28d371dffa2c5ea3cae53c93a8e (diff) |
Results with proper conversion
Diffstat (limited to 'src/duckdb/Result.zig')
-rw-r--r-- | src/duckdb/Result.zig | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/duckdb/Result.zig b/src/duckdb/Result.zig index 61a30ce..87d9f6f 100644 --- a/src/duckdb/Result.zig +++ b/src/duckdb/Result.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const types = @import("Types.zig"); +const Column = @import("Column.zig").Column; const c = @cImport({ @cInclude("duckdb.h"); }); @@ -98,10 +98,7 @@ pub fn Result(comptime T: type) type{ inline for (fields, 0..) |field, i| { // TODO: check compatibility between the column type and // the struct provided as result container - // const column_type = c.duckdb_column_type(&self._res, i); - // std.debug.print("tipo => {any}\n", .{column_type}); - // std.debug.print("{any}\n", .{self._data}); // Check validity const entry_idx :usize = self._current_row / 64; @@ -115,21 +112,20 @@ pub fn Result(comptime T: type) type{ // Store the column in current row if (is_valid){ - // Unwrap the Optional + // Unwrap the output Optional const t = switch (@typeInfo(field.type)){ .Optional => |t| t.child, else => field.type }; - // Unpack the C array of duckdb_type - const col: [*]types.unpack_type(t) = @alignCast(@ptrCast(self._data[i])); - std.debug.assert(types.valid_unpack(column_type, t)); + // Obtain and convert column to something we can process + const column = Column.fromType(column_type, self._data[i].?); - // Convert to Zig data type - @field(result, field.name) = try types.cast(&col[self._current_row], t); + // Convert to Zig data type and store in output struct + @field(result, field.name) = try column.getAs(self._current_row, t); } else { // Got a NULL from the DB if (@typeInfo(field.type) != .Optional){ - // Cannot return it because it's not optional + // Cannot return it because output it's not optional return error.NullInNotOptional; } @field(result, field.name) = null; |