forked from vieter-v/vieter
db: added BuildLog & required methods
This commit is contained in:
parent
230920576d
commit
58c1ecd25e
3 changed files with 49 additions and 1 deletions
47
src/db/logs.v
Normal file
47
src/db/logs.v
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
module db
|
||||
|
||||
import time
|
||||
|
||||
pub struct BuildLog {
|
||||
id int [primary; sql: serial]
|
||||
repo GitRepo [nonull]
|
||||
start_time time.Time [nonull]
|
||||
end_time time.Time [nonull]
|
||||
exit_code int [nonull]
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue