╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
309 comptime DB: type, 310 comptime hash_kind: hash.HashKind, 311 haxy_moment: DB.HashMap(.read_only), 312 user_id: []const u8, 313 ) !?DB.HashMap(.read_only) { 314 const event_id_to_user_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->user")) orelse return null; 315 const event_id_to_user = try DB.HashMap(.read_only).init(event_id_to_user_cursor); 316 const user_cursor = try event_id_to_user.getCursor(hash.hashInt(hash_kind, user_id)) orelse return null; 317 return try DB.HashMap(.read_only).init(user_cursor); 318 } 319 320 // read a user by name from the admin event store, or null if the admin repo or 321 // the user doesn't exist. field byte slices are allocated in `arena`. 322 pub fn readByName( 323 io: std.Io, 324 allocator: std.mem.Allocator, 325 admin_repo_path: []const u8, 326 arena: *std.heap.ArenaAllocator, 327 name: []const u8, 328 ) !?Record { 329 var repo = rp.Repo(.xit, evt.admin_repo_opts).open(io, allocator, .{ .path = admin_repo_path }) catch |err| switch (err) { 330 error.RepoNotFound => return null, 331 else => |e| return e, 332 }; 333 defer repo.deinit(io, allocator); 334 335 const moment = try evt.currentMoment(evt.admin_repo_opts, &repo); 336 337 const user_id = try readIdByName(evt.AdminDB, evt.admin_repo_opts.hash, moment, name) orelse return null; 338 339 return try readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, &user_id); 340 } 341