refactor: moved BuildLog to models

main
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,6 +1,6 @@
module client
import db { BuildLog }
import models { BuildLog }
import net.http { Method }
import response { Response }
import time

View File

@ -3,8 +3,8 @@ module logs
import cli
import env
import client
import db
import console
import models { BuildLog }
struct Config {
address string [required]
@ -67,7 +67,7 @@ pub fn cmd() cli.Command {
}
// print_log_list prints a list of logs.
fn print_log_list(logs []db.BuildLog) ? {
fn print_log_list(logs []BuildLog) ? {
data := logs.map([it.id.str(), it.repo_id.str(), it.start_time.str(),
it.exit_code.str()])

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 {

28
src/models/logs.v 100644
View File

@ -0,0 +1,28 @@
module models
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
}

View File

@ -4,7 +4,7 @@ import web
import net.http
import response { new_data_response, new_response }
import db
import models { GitRepoArch }
import models { GitRepo, GitRepoArch, GitRepoFilter }
// get_repos returns the current list of repos.
['/api/repos'; get]

View File

@ -8,6 +8,7 @@ import db
import time
import os
import util
import models { BuildLog }
// get_logs returns all build logs in the database. A 'repo' query param can
// optionally be added to limit the list of build logs to that repository.
@ -97,7 +98,7 @@ fn (mut app App) post_log() web.Result {
}
// Store log in db
log := db.BuildLog{
log := BuildLog{
repo_id: repo_id
start_time: start_time
end_time: end_time