fix: Minimal duckdb.zig without comments
Remove comments and use ok/err instead of success/error in case those are reserved words. Refs: RFC-0015
This commit is contained in:
parent
d0cfedfe71
commit
bdb1f8e896
|
|
@ -1,22 +1,15 @@
|
|||
//! DuckDB C API Bindings for Zig
|
||||
//!
|
||||
//! Thin wrapper around libduckdb for Libertaria L4 Feed
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
/// Opaque handle types
|
||||
pub const Database = opaque {};
|
||||
pub const Connection = opaque {};
|
||||
pub const Result = opaque {};
|
||||
pub const Appender = opaque {};
|
||||
|
||||
/// State enum for DuckDB operations
|
||||
pub const State = enum {
|
||||
success,
|
||||
error,
|
||||
ok,
|
||||
err,
|
||||
};
|
||||
|
||||
/// C API Functions
|
||||
pub extern "c" fn duckdb_open(path: [*c]const u8, out_db: **Database) State;
|
||||
pub extern "c" fn duckdb_close(db: *Database) void;
|
||||
pub extern "c" fn duckdb_connect(db: *Database, out_con: **Connection) State;
|
||||
|
|
@ -24,15 +17,6 @@ pub extern "c" fn duckdb_disconnect(con: *Connection) void;
|
|||
pub extern "c" fn duckdb_query(con: *Connection, query: [*c]const u8, out_res: ?**Result) State;
|
||||
pub extern "c" fn duckdb_destroy_result(res: *Result) void;
|
||||
|
||||
// Appender API for bulk inserts
|
||||
pub extern "c" fn duckdb_appender_create(con: *Connection, schema: [*c]const u8, table: [*c]const u8, out_app: **Appender) State;
|
||||
pub extern "c" fn duckdb_appender_destroy(app: *Appender) State;
|
||||
pub extern "c" fn duckdb_appender_flush(app: *Appender) State;
|
||||
pub extern "c" fn duckdb_appender_append_int64(app: *Appender, val: i64) State;
|
||||
pub extern "c" fn duckdb_appender_append_uint64(app: *Appender, val: u64) State;
|
||||
pub extern "c" fn duckdb_appender_append_blob(app: *Appender, data: [*c]const u8, len: usize) State;
|
||||
|
||||
/// Zig-friendly DB wrapper
|
||||
pub const DB = struct {
|
||||
ptr: *Database,
|
||||
|
||||
|
|
@ -41,7 +25,7 @@ pub const DB = struct {
|
|||
const c_path = try std.cstr.addNullByte(std.heap.page_allocator, path);
|
||||
defer std.heap.page_allocator.free(c_path);
|
||||
|
||||
if (duckdb_open(c_path.ptr, &db) != .success) {
|
||||
if (duckdb_open(c_path.ptr, &db) != .ok) {
|
||||
return error.DuckDBOpenFailed;
|
||||
}
|
||||
return DB{ .ptr = db };
|
||||
|
|
@ -53,14 +37,13 @@ pub const DB = struct {
|
|||
|
||||
pub fn connect(self: *DB) !Conn {
|
||||
var con: *Connection = undefined;
|
||||
if (duckdb_connect(self.ptr, &con) != .success) {
|
||||
if (duckdb_connect(self.ptr, &con) != .ok) {
|
||||
return error.DuckDBConnectFailed;
|
||||
}
|
||||
return Conn{ .ptr = con };
|
||||
}
|
||||
};
|
||||
|
||||
/// Zig-friendly Connection wrapper
|
||||
pub const Conn = struct {
|
||||
ptr: *Connection,
|
||||
|
||||
|
|
@ -72,13 +55,8 @@ pub const Conn = struct {
|
|||
const c_sql = try std.cstr.addNullByte(std.heap.page_allocator, sql);
|
||||
defer std.heap.page_allocator.free(c_sql);
|
||||
|
||||
if (duckdb_query(self.ptr, c_sql.ptr, null) != .success) {
|
||||
if (duckdb_query(self.ptr, c_sql.ptr, null) != .ok) {
|
||||
return error.DuckDBQueryFailed;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
test "DuckDB open/close" {
|
||||
// Skipped - requires libduckdb.so at runtime
|
||||
_ = DB.open(":memory:");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue