summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-02 14:25:05 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-03 13:44:49 +0200
commit2e88e0825388b9122615f3bb32b0a8aec96dfd35 (patch)
treec078cb4a37860777467e87f6ede546b67c710ad4 /src
parentdabbb107d719cb753673e394fbd4da090f74d458 (diff)
Add connection.run
Diffstat (limited to 'src')
-rw-r--r--src/duckdb/db.zig28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/duckdb/db.zig b/src/duckdb/db.zig
index f662ee0..41cfe67 100644
--- a/src/duckdb/db.zig
+++ b/src/duckdb/db.zig
@@ -21,10 +21,17 @@ const Connection = struct {
c.duckdb_disconnect(&self._conn);
}
+ /// Query returning a result. Caller needs to call result.deinit()
pub fn query(self: *Connection, q: [:0]const u8, comptime res_type: type)
!Result(res_type) {
return try Result(res_type).init(self._conn, q);
}
+
+ /// Query with no results and autoclean
+ pub fn run(self: *Connection, q: [:0]const u8) !void{
+ var x = try Result(void).init(self._conn, q);
+ defer x.deinit();
+ }
};
@@ -66,10 +73,8 @@ test "Simple querying" {
segund: ?i32
};
- var x = try connection.query("CREATE TABLE integers (i INTEGER NOT NULL, j INTEGER);", void);
- x.deinit();
- var y = try connection.query("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);", void);
- y.deinit();
+ try connection.run("CREATE TABLE integers (i INTEGER NOT NULL, j INTEGER);");
+ try connection.run("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);");
var result = try connection.query("SELECT * FROM integers;", s);
defer result.deinit();
@@ -101,10 +106,8 @@ test "Checks if all fields are captured" {
tercer: ?i32,
};
- var x = try connection.query("CREATE TABLE integers (i INTEGER NOT NULL, j INTEGER);", void);
- x.deinit();
- var y = try connection.query("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);", void);
- y.deinit();
+ try connection.run("CREATE TABLE integers (i INTEGER NOT NULL, j INTEGER);");
+ try connection.run("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);");
try std.testing.expectError(error.QueryColumnCountCapture,
connection.query("SELECT * FROM integers;", s));
@@ -120,12 +123,9 @@ test "String queries" {
primer: []const u8
};
- var x = try connection.query("CREATE TABLE text (i VARCHAR NOT NULL );", void);
- x.deinit();
- var y = try connection.query("INSERT INTO text VALUES ('Inlined');", void);
- y.deinit();
- var z = try connection.query("INSERT INTO text VALUES ('A very long string that is not inlined');", void);
- z.deinit();
+ try connection.run("CREATE TABLE text (i VARCHAR NOT NULL );");
+ try connection.run("INSERT INTO text VALUES ('Inlined');");
+ try connection.run("INSERT INTO text VALUES ('A very long string that is not inlined');");
var result = try connection.query("SELECT * FROM text;", s);
defer result.deinit();