const c = @cImport({ @cInclude("duckdb.h"); }); const Result = @import("Result.zig").Result; const PreparedStatement = @import("PreparedStatement.zig"); _conn: c.duckdb_connection, const Self = @This(); pub fn init(conn: c.duckdb_connection) Self { return .{ ._conn = conn }; } pub fn deinit(self: *Self) void { c.duckdb_disconnect(&self._conn); } /// Query returning a result. Caller needs to call result.deinit() pub fn query(self: *Self, q: [:0]const u8, comptime res_type: type) !Result(res_type) { var result: c.duckdb_result = undefined; const state = c.duckdb_query(self._conn, q, &result); if ( state == c.DuckDBError ){ return error.DuckDBError; } return try Result(res_type).init(result); } /// Query with no results and autoclean pub fn run(self: *Self, q: [:0]const u8) !void{ var x = try self.query(q, void); defer x.deinit(); } /// Make a prepared query. Caller needs to call prepared_query.deinit() pub fn prepareStatement(self: *Self, q: [:0]const u8) !PreparedStatement { var stmt: c.duckdb_prepared_statement = undefined; const state = c.duckdb_prepare(self._conn, q, &stmt); if ( state == c.DuckDBError ){ return error.DuckDBError; } return PreparedStatement.init(stmt); }