47 lines
1.0 KiB
Zig
47 lines
1.0 KiB
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 = null },
|
|
};
|
|
|
|
var item = Item{ .id = null, .tags = &tags };
|
|
|
|
try item.persist(&db);
|
|
|
|
var jobj = json.Obj.newObject();
|
|
|
|
jobj.objectAdd("id", &json.Obj.newInt64(item.id.?));
|
|
|
|
var jtags = json.Obj.newObject();
|
|
jobj.objectAdd("tags", &jtags);
|
|
|
|
|
|
for (tags) |tag_i| {
|
|
const jtag = if (tag_i.value) |value|
|
|
&json.Obj.newString(value)
|
|
else
|
|
null;
|
|
|
|
jtags.objectAdd(tag_i.name, jtag);
|
|
}
|
|
|
|
defer jobj.deinit();
|
|
_ = alloc;
|
|
|
|
std.debug.print("{s}\n", .{jobj.toString()});
|
|
}
|