Skip to content

Commit

Permalink
zig/db- add zigmod and upgrade Version deps cols type from string
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Dec 13, 2021
1 parent 60995cf commit 14b51ec
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/db/Version.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const std = @import("std");
const string = []const u8;
const ulid = @import("ulid");
const zigmod = @import("zigmod");

const _db = @import("./_db.zig");
const Time = _db.Time;
const User = _db.User;

const _internal = @import("./_internal.zig");
const db = &_internal.db;
Expand All @@ -22,8 +24,10 @@ pub const Version = struct {
approved_by: string, // TODO remove this column, app design changed
real_major: u32,
real_minor: u32,
deps: string,
dev_deps: string,
deps: DepList, // TODO remove this column, no longer used in upstream Zigmod
dev_deps: DepList,
root_deps: DepList,
build_deps: DepList,

pub const table_name = "versions";

Expand All @@ -45,3 +49,48 @@ pub const Version = struct {
try self.updateColumn(alloc, .real_minor, minor);
}
};

const DepList = struct {
deps: []const zigmod.Dep,

const Self = @This();
pub const BaseType = string;

pub fn readField(alloc: *std.mem.Allocator, value: BaseType) !Self {
var res = std.ArrayList(zigmod.Dep).init(alloc);
var iter = std.mem.split(u8, value, "\n");
while (iter.next()) |line| {
if (line.len == 0) continue;
var seq = std.mem.split(u8, line, " ");
try res.append(.{
.type = std.meta.stringToEnum(zigmod.DepType, seq.next().?).?,
.path = seq.next().?,
.version = seq.next().?,
//
.alloc = alloc,
.id = "",
.name = "",
.main = "",
.deps = &.{},
.yaml = null,
});
}
return DepList{ .deps = res.toOwnedSlice() };
}

pub fn bindField(self: Self, alloc: *std.mem.Allocator) !BaseType {
var res = std.ArrayList(u8).init(alloc);
defer res.deinit();
const w = res.writer();
// since list.items is initialized with `&[_]T{}`
// this and the `[1..]` at the end are blocked on https://github.com/ziglang/zig/issues/6706
// this workaround forces `.ptr` to not be `@0` when no other data has been written
try w.writeAll("w");

for (self.deps) |item, i| {
if (i > 0) try w.writeAll("\n");
try w.print("{s} {s} {s}", .{ @tagName(item.type), item.path, item.version });
}
return res.toOwnedSlice()[1..];
}
};
4 changes: 4 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const oauth2 = @import("oauth2");
const flag = @import("flag");
const ulid = @import("ulid");
const zfetch = @import("zfetch");
const zigmod = @import("zigmod");

const git = @import("./git.zig");
const docker = @import("./docker.zig");
Expand Down Expand Up @@ -58,6 +59,9 @@ pub fn main() !void {
try zfetch.init();
defer zfetch.deinit();

try zigmod.init();
defer zigmod.deinit();

try handler.init(alloc);

var clients = std.ArrayList(oauth2.Client).init(alloc);
Expand Down
1 change: 1 addition & 0 deletions zig.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ root_dependencies:
- src: git https://github.com/nektro/zig-ulid
- src: git https://github.com/nektro/zig-time
- src: git https://github.com/truemedian/zfetch
- src: git https://github.com/nektro/zigmod
11 changes: 11 additions & 0 deletions zigmod.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ git https://github.com/nektro/zig-json commit-7f0e661371d41cfdc8b1649ed00e7a750c
git https://github.com/nektro/zig-flag commit-ed7f7186cdafaeb3c257c5de14a8d7662c8a8237
git https://github.com/nektro/zig-ulid commit-140bf8a8b9f2f66b277642f34c6573f91361957e
git https://github.com/nektro/zig-time commit-88e83395f79e1aa2b8188e934c4a8894f6d6bc5f
git https://github.com/nektro/zigmod commit-1995ca2face963c0bc23cf2dfb7f1e8db1b26c9c
git https://github.com/yaml/libyaml tag-0.2.5
git https://github.com/nektro/zig-ansi commit-d4a53bcac5b87abecc65491109ec22aaf5f3dc2f
git https://github.com/ziglibs/known-folders commit-f299244d787a02dd49bc8b10b8c2722a13655c48
git https://github.com/nektro/zig-licenses commit-c9b8cbf3565675a056ad4e9b57cb4f84020e7680
git https://github.com/nektro/zig-detect-license commit-d4544410f811c402b866f21f63588d1aae1b2d90
git https://github.com/nektro/zig-licenses-text commit-3c07c6e4eb0965dafd0b029c632f823631b3169c
git https://github.com/nektro/zig-leven commit-8e9f827117ab1418578b692a2325754cc3ee692d
git https://github.com/nektro/zig-fs-check commit-dcd8da90fcb8bf3c9887e713bf0ec072bc897dd5
git https://github.com/nektro/zig-inquirer commit-9a068122c59ac2785f330c37bf4412aed644ed37
git https://github.com/arqv/ini commit-0880475514e8b73dee515843cb4db3ee663174e8

0 comments on commit 14b51ec

Please sign in to comment.