Skip to content

Commit

Permalink
remove db.get() in favor of db.raw().get()
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomsik committed Nov 12, 2024
1 parent 811ec42 commit 4463b79
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/migrate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
8 changes: 2 additions & 6 deletions src/session.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 4463b79

Please sign in to comment.