2022-05-07 14:16:30 +02:00
|
|
|
module db
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
pub struct BuildLog {
|
2022-05-07 15:41:49 +02:00
|
|
|
pub:
|
2022-05-07 14:16:30 +02:00
|
|
|
id int [primary; sql: serial]
|
2022-05-07 15:31:01 +02:00
|
|
|
repo_id int [nonull]
|
2022-05-07 14:16:30 +02:00
|
|
|
start_time time.Time [nonull]
|
|
|
|
end_time time.Time [nonull]
|
2022-05-07 19:38:28 +02:00
|
|
|
arch string [nonull]
|
2022-05-07 14:16:30 +02:00
|
|
|
exit_code int [nonull]
|
|
|
|
}
|
|
|
|
|
2022-05-07 21:50:20 +02:00
|
|
|
pub fn (bl &BuildLog) str() string {
|
|
|
|
mut parts := [
|
|
|
|
'id: $bl.id',
|
|
|
|
'repo id: $bl.repo_id',
|
|
|
|
'start time: $bl.start_time',
|
|
|
|
'end time: $bl.end_time',
|
|
|
|
'arch: $bl.arch',
|
|
|
|
'exit code: $bl.exit_code',
|
|
|
|
]
|
|
|
|
str := parts.join('\n')
|
|
|
|
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
2022-05-07 14:16:30 +02:00
|
|
|
// get_build_logs returns all BuildLog's in the database.
|
|
|
|
pub fn (db &VieterDb) get_build_logs() []BuildLog {
|
|
|
|
res := sql db.conn {
|
|
|
|
select from BuildLog order by id
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2022-05-07 15:31:01 +02:00
|
|
|
// get_build_logs_for_repo returns all BuildLog's in the database for a given
|
|
|
|
// repo.
|
|
|
|
pub fn (db &VieterDb) get_build_logs_for_repo(repo_id int) []BuildLog {
|
|
|
|
res := sql db.conn {
|
|
|
|
select from BuildLog where repo_id == repo_id order by id
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2022-05-07 14:16:30 +02:00
|
|
|
// get_build_log tries to return a specific BuildLog.
|
|
|
|
pub fn (db &VieterDb) get_build_log(id int) ?BuildLog {
|
|
|
|
res := sql db.conn {
|
|
|
|
select from BuildLog where id == id
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.id == 0 {
|
|
|
|
return none
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// add_build_log inserts the given BuildLog into the database.
|
|
|
|
pub fn (db &VieterDb) add_build_log(log BuildLog) {
|
|
|
|
sql db.conn {
|
|
|
|
insert log into BuildLog
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete_build_log delete the BuildLog with the given ID from the database.
|
|
|
|
pub fn (db &VieterDb) delete_build_log(id int) {
|
|
|
|
sql db.conn {
|
|
|
|
delete from BuildLog where id == id
|
|
|
|
}
|
|
|
|
}
|