mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 18:48:33 -04:00
feat: zig-sqlite.
This commit is contained in:
26
src/db.zig
Normal file
26
src/db.zig
Normal file
@@ -0,0 +1,26 @@
|
||||
const std = @import("std");
|
||||
const sqlite = @import("sqlite");
|
||||
|
||||
test "simple database can be opened" {
|
||||
var db = try sqlite.Db.init(.{
|
||||
.mode = sqlite.Db.Mode{ .File = "./fixtures/example.db" },
|
||||
.open_flags = .{
|
||||
.write = false,
|
||||
.create = false,
|
||||
},
|
||||
.threading_mode = .MultiThread,
|
||||
});
|
||||
|
||||
var stmt = try db.prepare("SELECT * FROM hello");
|
||||
defer stmt.deinit();
|
||||
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
if (try stmt.oneAlloc(struct { text: []const u8 }, alloc, .{}, .{})) |got| {
|
||||
defer alloc.free(got.text);
|
||||
|
||||
try std.testing.expectEqualSlices(u8, "world!", got.text);
|
||||
} else {
|
||||
return error.TestUnexpectedResult;
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,10 @@ pub const root: Command = .new(.{
|
||||
},
|
||||
});
|
||||
|
||||
test {
|
||||
std.testing.refAllDecls(@import("db.zig"));
|
||||
}
|
||||
|
||||
test "enum type" {
|
||||
const got: root.Type = @enumFromInt(2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user