diff --git a/src/client/logs.v b/src/client/logs.v index cdacab9b..3484f036 100644 --- a/src/client/logs.v +++ b/src/client/logs.v @@ -1,6 +1,6 @@ module client -import db { BuildLog } +import models { BuildLog } import net.http { Method } import response { Response } import time diff --git a/src/console/logs/logs.v b/src/console/logs/logs.v index 6400e801..1d0bb556 100644 --- a/src/console/logs/logs.v +++ b/src/console/logs/logs.v @@ -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()]) diff --git a/src/db/db.v b/src/db/db.v index a5756e6c..57b437e6 100644 --- a/src/db/db.v +++ b/src/db/db.v @@ -1,7 +1,7 @@ module db import sqlite -import models +import models { BuildLog, GitRepo } struct VieterDb { conn sqlite.DB diff --git a/src/db/git.v b/src/db/git.v index d8887ffe..8cc493f3 100644 --- a/src/db/git.v +++ b/src/db/git.v @@ -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) diff --git a/src/db/logs.v b/src/db/logs.v index 817db78b..129ec4e1 100644 --- a/src/db/logs.v +++ b/src/db/logs.v @@ -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 { diff --git a/src/models/logs.v b/src/models/logs.v new file mode 100644 index 00000000..173336f4 --- /dev/null +++ b/src/models/logs.v @@ -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 +} diff --git a/src/server/git.v b/src/server/git.v index ec433c76..c1bc6f34 100644 --- a/src/server/git.v +++ b/src/server/git.v @@ -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] diff --git a/src/server/logs.v b/src/server/logs.v index 21331e5b..af0b0812 100644 --- a/src/server/logs.v +++ b/src/server/logs.v @@ -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