From 4463b79f8d1da4f026ac86dac081646da14f34b9 Mon Sep 17 00:00:00 2001 From: Kamil Tomsik Date: Tue, 12 Nov 2024 19:29:59 +0100 Subject: [PATCH] remove db.get() in favor of db.raw().get() --- src/migrate.zig | 2 +- src/session.zig | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/migrate.zig b/src/migrate.zig index 5afb915..ea0bc05 100644 --- a/src/migrate.zig +++ b/src/migrate.zig @@ -63,7 +63,7 @@ fn migrateObjects(db: *Session, pristine: *Session, kind: []const u8) !void { // to know which columns are common to both and we need to do it in a // new block so it gets deinitialized and we can then drop and rename // the temp table - const cols = try db.get([]const u8, "SELECT GROUP_CONCAT(name) FROM (SELECT name FROM pragma_table_xinfo(?) INTERSECT SELECT name FROM pragma_table_info('temp'))", .{obj.name}); + const cols = try db.raw("SELECT GROUP_CONCAT(name) FROM (SELECT name FROM pragma_table_xinfo(?) INTERSECT SELECT name FROM pragma_table_info('temp'))", .{obj.name}).get([]const u8); // Copy data from old table to temp table const copy_sql = try std.fmt.allocPrint(db.arena, "INSERT INTO temp({0s}) SELECT {0s} FROM {1s}", .{ cols.?, obj.name }); diff --git a/src/session.zig b/src/session.zig index 9910271..069a950 100644 --- a/src/session.zig +++ b/src/session.zig @@ -59,10 +59,6 @@ pub const Session = struct { try stmt.exec(); } - pub fn get(self: *Session, comptime T: type, sql: []const u8, args: anytype) !?T { - return self.raw(sql, args).get(T); - } - pub fn raw(self: *Session, sql: []const u8, args: anytype) RawQuery { return RawQuery.raw(self, sql, args); } @@ -139,11 +135,11 @@ test "db.exec()" { try t.expectEqual(1, db.conn.rowsAffected()); } -test "db.get()" { +test "db.raw().get()" { var db = try createDb(ddl); defer db.deinit(); - try t.expectEqual(123, try db.get(u32, "SELECT ? + 23", .{100})); + try t.expectEqual(123, try db.raw("SELECT ? + 23", .{100}).get(u32)); } test "db.query(T).xxx() value methods" {