diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-07-29 21:18:40 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-07-29 21:18:40 +0200 |
commit | a392744cc995d7c26730d2f1626612ad4739ca9b (patch) | |
tree | 68faf77b9c64995e99436d92b4905d6c40e0dda7 /src/db.zig |
First commit with working DuckDB connection
Diffstat (limited to 'src/db.zig')
-rw-r--r-- | src/db.zig | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/db.zig b/src/db.zig new file mode 100644 index 0000000..425629d --- /dev/null +++ b/src/db.zig @@ -0,0 +1,40 @@ +const c = @cImport({ + @cInclude("duckdb.h"); +}); + +const Connection = struct { + _conn: c.duckdb_connection, + + pub fn init(db: Self) !Connection{ + var conn: Connection = undefined; + if( c.duckdb_connect(db._db, &conn._conn) == c.DuckDBError ){ + return error.DuckDBError; + } + return conn; + } + + pub fn deinit(self: *Connection) void{ + c.duckdb_disconnect(&self._conn); + } +}; + + +pub const Self = @This(); + +_db: c.duckdb_database, + +pub fn init(file: [*c]const u8) !Self{ + var db : Self = undefined; + if (c.duckdb_open(file, &db._db) == c.DuckDBError) { + return error.DuckDBError; + } + return db; +} + +pub fn deinit(self: *Self) void{ + c.duckdb_close(&self._db); +} + +pub fn connect(self: Self) !Connection { + return Connection.init(self); +} |