Skip to content

Commit

Permalink
spi: add queryTyped
Browse files Browse the repository at this point in the history
  • Loading branch information
urso authored and urso committed Jun 25, 2024
1 parent a1f6f4c commit f252750
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pgzx/spi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ pub fn query(sql: [:0]const u8, options: ExecOptions) SPIError!Rows {
return Rows.init();
}

pub fn queryTyped(comptime T: type, sql: [:0]const u8, options: ExecOptions) SPIError!RowsOf(T) {
const rows = try query(sql, options);
return rows.typed(T);
}

pub fn scanProcessed(row: usize, values: anytype) !void {
if (pg.SPI_processed <= row) {
return err.PGError.SPIInvalidRowIndex;
Expand Down Expand Up @@ -141,6 +146,10 @@ pub const Rows = struct {
return .{};
}

fn typed(self: Self, comptime T: type) RowsOf(T) {
return RowsOf(T).init(self);
}

pub fn deinit(self: *Self) void {
pg.SPI_freetuptable(pg.SPI_tuptable);
self.row = -1;
Expand Down

0 comments on commit f252750

Please sign in to comment.