Return the added items

This commit is contained in:
Dendy 2022-10-27 03:26:14 +02:00
parent 45747f6069
commit dc527e93de
1 changed files with 10 additions and 2 deletions

View File

@ -20,15 +20,23 @@ pub fn process(jobj: *json.Obj, db: *sqlite.Db) !void {
pub fn add(jobj: *json.Obj, db: *sqlite.Db, allocator: std.mem.Allocator) !void {
// TODO: Maybe return error when no items in the array?
var jret = json.Obj.newArray();
defer jret.deinit();
var iter = jobj.arrayGetIterator();
while(iter.next()) |*jtags| {
var item = Item {
.id = null,
.tags = try Item.tagsFromJson(jtags, allocator),
};
defer item.deinit();
item.deinit();
// TODO: Return the things that have been added with ID
// Insert new items into the DB
try item.persist(db);
// Add item to new json array (Makes a deep copy, freed with jret.deinit())
jret.arrayAdd(&item.toJson());
}
std.debug.print("{s}", .{ jret.toString() });
}