mgtzm/src/main.zig

41 lines
931 B
Zig

const std = @import("std");
const sqlite = @import("sqlite");
const json = @import("json.zig");
const Db = @import("Db.zig");
const Item = @import("Item.zig");
const Tag = @import("Tag.zig");
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const alloc = arena.allocator();
var db = try Db.init();
var tags = [2]Item.Tag{
.{ .name = "title", .value = "clean room" },
.{ .name = "task", .value = "explosion preventer" },
};
var item = Item{ .id = null, .tags = &tags };
try item.persist(&db);
var jobj = json.Obj.newObject();
for (tags) |tag_i| {
const jtag = if (tag_i.value) |value|
&json.Obj.newString(value)
else
null;
jobj.objectAdd(tag_i.name, jtag);
}
defer jobj.deinit();
_ = alloc;
std.debug.print("{s}\n", .{jobj.toString()});
}