Return the added items
This commit is contained in:
parent
45747f6069
commit
dc527e93de
|
@ -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() });
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue