summaryrefslogtreecommitdiff
path: root/backend/src/Models/Description.zig
blob: a3774abbeacbf2c6071533cc7056973707561813 (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
32
33
34
35
36
const std = @import("std");
const pg = @import("pg");

// Is suitable for those tables:
// - RangedWeaponsDescriptions
pub const Description = struct {
    Id: []const u8,
    Language: []const u8,
    Contents: []const u8,

    // Parses the db row and returns the result. You are expected to use the
    // actual DB schema and use * as a fields selector
    pub fn Map(row: *const pg.Row) !Description {
        return Description {
            .Id = try row.get([]const u8, 0),
            .Language = try row.get([]const u8, 1),
            .Contents = try row.get([]const u8, 2),
        };
    }

    // Parses the db row and returns the result. You are expected to use the
    // actual DB schema and use * as a fields selector
    pub fn MapWithAlloc(allocator: std.mem.Allocator, row: *const pg.Row) !Description {
        return Description {
            .Id = try allocator.dupe(u8, try row.get([]const u8, 0)),
            .Language = try allocator.dupe(u8, try row.get([]const u8, 1)),
            .Contents = try allocator.dupe(u8, try row.get([]const u8, 2)),
        };
    }

};

pub const RequestBody = struct {
    Language: []const u8,
    Contents: []const u8,
};