refactor: moved BuildLog to models

This commit is contained in:
Jef Roosens 2022-05-19 08:20:11 +02:00
parent 6bd5b7cb48
commit 2fc25f1afe
Signed by untrusted user: Jef Roosens
GPG key ID: B580B976584B5F30
8 changed files with 37 additions and 32 deletions

View file

@ -1,7 +1,7 @@
module db
import sqlite
import models
import models { BuildLog, GitRepo }
struct VieterDb {
conn sqlite.DB

View file

@ -66,6 +66,7 @@ pub fn (db &VieterDb) update_git_repo(repo_id int, params map[string]string) {
}
}
values_str := values.join(', ')
// I think this is actual SQL & not the ORM language
query := 'update GitRepo set $values_str where id == $repo_id'
db.conn.exec_none(query)

View file

@ -1,31 +1,6 @@
module db
import time
pub struct BuildLog {
pub:
id int [primary; sql: serial]
repo_id int [nonull]
start_time time.Time [nonull]
end_time time.Time [nonull]
arch string [nonull]
exit_code int [nonull]
}
// str returns a string representation.
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
}
import models { BuildLog }
// get_build_logs returns all BuildLog's in the database.
pub fn (db &VieterDb) get_build_logs() []BuildLog {