Skip to content

Commit

Permalink
session: bring back sess.create(T, data)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomsik committed Aug 14, 2024
1 parent 138c810 commit e6db1d1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/session.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ pub const Session = struct {
return self.query(T).find(id);
}

/// Create a new record and return it.
pub fn create(self: *Session, comptime T: type, data: anytype) !T {
try self.insert(T, data);
return try self.find(T, @intCast(try self.conn.lastInsertRowId())) orelse error.NotFound;
}

/// Insert a new record.
pub fn insert(self: *Session, comptime T: type, data: anytype) !void {
comptime util.checkFields(T, @TypeOf(data));
Expand Down

0 comments on commit e6db1d1

Please sign in to comment.