forked from vieter-v/vieter
fix(db): return correct id when adding targets
parent
b6168a3060
commit
e742d3de6d
|
@ -84,6 +84,8 @@ pub fn (db &VieterDb) add_build_log(log BuildLog) int {
|
||||||
insert log into BuildLog
|
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
|
inserted_id := db.conn.last_id() as int
|
||||||
|
|
||||||
return inserted_id
|
return inserted_id
|
||||||
|
|
|
@ -38,14 +38,17 @@ pub fn (db &VieterDb) get_target(target_id int) ?Target {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add_target inserts the given target into the database.
|
// 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 {
|
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.
|
// delete_target deletes the target with the given id from the database.
|
||||||
|
|
Loading…
Reference in New Issue