blob: ca4119794999be3a1e6bdf41ded0b05ab77f7ea8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// You are not supposed to include this file. To access this you should use
// Connection.RangedWeapons.
const conn = @import("Connection.zig");
const std = @import("std");
const pg = @import("pg");
const model = @import("../Models/RangedWeapon.zig");
pub fn GetAll(alloc: std.mem.Allocator) !std.ArrayList(model.RangedWeaponType) {
const query = "SELECT * FROM RangedWeapons";
var result = try conn.pool.query(query, .{});
defer _ = result.deinit();
var outp: std.ArrayList(model.RangedWeaponType) = .empty;
while (try result.next()) |row| {
const newRW = try model.RangedWeaponType.MapWithAlloc(alloc, &row);
try outp.append(alloc, newRW);
}
return outp;
}
pub fn GetByDisplayName(allocator: std.mem.Allocator, displayName: []const u8) !model.RangedWeaponType {
const query = "SELECT * FROM RangedWeapons WHERE Id = $1";
var row = try conn.pool.row(query, .{displayName}) orelse {
return conn.ResultErrors.NotFound;
};
const outp = try model.RangedWeaponType.MapWithAlloc(allocator, &row.row);
try row.deinit();
return outp;
}
|