authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-09-20 02:29:40-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-09-20 02:29:40-07:00
log995110e5a71fc10d869d3f0b24bfe005405a9cf2
tree8e52421af761d2d8c7a880043ee38bf2c5efb296
parent1e98900cd5f33455b5fef767640f6669f7b3dc35
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add an Error decl


3 files changed, 15 insertions(+), 3 deletions(-)

src/lib.zig+8
......@@ -12,6 +12,14 @@ pub fn Driver(comptime etype: DriverType) type {
1212 };
1313}
1414
15pub const Error = blk: {
16 var Err: type = error{};
17 for (@typeInfo(DriverType).@"enum".fields) |f| {
18 Err = Err || Driver(@field(DriverType, f.name)).Error;
19 }
20 break :blk Err;
21};
22
1523pub fn connect(_type: DriverType, allocator: std.mem.Allocator, connection: [:0]const u8) !Engine {
1624 return switch (_type) {
1725 inline else => |t| @unionInit(Engine, @tagName(t), try .connect(allocator, connection)),
src/postgresql.zig+2
......@@ -19,6 +19,8 @@ const sys = switch (builtin.target.os.tag) {
1919
2020const Driver = @This();
2121
22pub const Error = error{};
23
2224conn: net.Stream,
2325bufw: nio.BufferedWriter(4096, net.Stream),
2426bufr: nio.BufferedReader(4096, net.Stream),
src/sqlite3.zig+5-3
......@@ -8,6 +8,8 @@ const Driver = @This();
88const SQLITE_STATIC: *allowzero anyopaque = @ptrFromInt(0);
99const SQLITE_TRANSIENT: *allowzero anyopaque = @ptrFromInt(std.math.maxInt(usize));
1010
11pub const Error = s.Error || error{Overflow};
12
1113db: *c.sqlite3,
1214
1315pub fn connect(allocator: std.mem.Allocator, path: [:0]const u8) !Driver {
......@@ -230,7 +232,7 @@ pub const s = struct {
230232 SQLITE_NOTICE,
231233 SQLITE_WARNING,
232234 };
233 pub fn rc2e(code: c_int) Error {
235 pub fn rc2e(code: c_int) s.Error {
234236 if (code == c.SQLITE_ERROR) return error.SQLITE_ERROR;
235237 if (code == c.SQLITE_INTERNAL) return error.SQLITE_INTERNAL;
236238 if (code == c.SQLITE_PERM) return error.SQLITE_PERM;
......@@ -261,7 +263,7 @@ pub const s = struct {
261263 if (code == c.SQLITE_WARNING) return error.SQLITE_WARNING;
262264 return error.Unexpected;
263265 }
264 pub fn rc2p(code: c_int) Error {
266 pub fn rc2p(code: c_int) s.Error {
265267 if (builtin.mode == .Debug) @panic(std.mem.sliceTo(c.sqlite3_errstr(code), 0));
266268 return rc2e(code);
267269 }
......@@ -273,7 +275,7 @@ pub const s = struct {
273275 if (code == c.SQLITE_OK) return;
274276 return rc2p(code);
275277 }
276 pub fn rc2p_d(db: *c.sqlite3, code: c_int) Error {
278 pub fn rc2p_d(db: *c.sqlite3, code: c_int) s.Error {
277279 if (builtin.mode == .Debug) @panic(std.mem.sliceTo(c.sqlite3_errmsg(db), 0));
278280 return rc2e(code);
279281 }