fix(db): return correct id when adding targets

pull/301/head
Jef Roosens 2022-12-13 13:46:07 +01:00
parent b6168a3060
commit e742d3de6d
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 9 additions and 4 deletions

View File

@ -84,6 +84,8 @@ pub fn (db &VieterDb) add_build_log(log BuildLog) int {
insert log into BuildLog
}
// Here, this does work because a log doesn't contain any foreign keys,
// meaning the ORM only has to do a single add
inserted_id := db.conn.last_id() as int
return inserted_id

View File

@ -38,14 +38,17 @@ pub fn (db &VieterDb) get_target(target_id int) ?Target {
}
// add_target inserts the given target into the database.
pub fn (db &VieterDb) add_target(repo Target) int {
pub fn (db &VieterDb) add_target(target Target) int {
sql db.conn {
insert repo into Target
insert target into Target
}
inserted_id := db.conn.last_id() as int
// ID of inserted target is the largest id
inserted_target := sql db.conn {
select from Target order by id desc limit 1
}
return inserted_id
return inserted_target.id
}
// delete_target deletes the target with the given id from the database.