forked from vieter-v/vieter
Compare commits
3 Commits
a39c1aa5eb
...
546d79ed2e
| Author | SHA1 | Date |
|---|---|---|
|
|
546d79ed2e | |
|
|
a374924ea1 | |
|
|
74baccb507 |
|
|
@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
* Database migrations
|
* Database migrations
|
||||||
|
* Query parameters for GitRepo API to filter responses
|
||||||
|
* Respective CLI flags for new GitRepo API parameters
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Refactor of main types into `models` module
|
||||||
|
|
||||||
## [0.3.0-alpha.2](https://git.rustybever.be/vieter/vieter/src/tag/0.3.0-alpha.2)
|
## [0.3.0-alpha.2](https://git.rustybever.be/vieter/vieter/src/tag/0.3.0-alpha.2)
|
||||||
|
|
||||||
|
|
|
||||||
19
src/db/db.v
19
src/db/db.v
|
|
@ -1,6 +1,7 @@
|
||||||
module db
|
module db
|
||||||
|
|
||||||
import sqlite
|
import sqlite
|
||||||
|
import time
|
||||||
|
|
||||||
struct VieterDb {
|
struct VieterDb {
|
||||||
conn sqlite.DB
|
conn sqlite.DB
|
||||||
|
|
@ -66,3 +67,21 @@ pub fn init(db_path string) ?VieterDb {
|
||||||
conn: conn
|
conn: conn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn row_into<T>(row sqlite.Row) T {
|
||||||
|
mut i := 0
|
||||||
|
mut out := T{}
|
||||||
|
|
||||||
|
$for field in T.fields {
|
||||||
|
$if field.typ is string {
|
||||||
|
out.$(field.name) = row.vals[i]
|
||||||
|
} $else $if field.typ is int {
|
||||||
|
out.$(field.name) = row.vals[i].int()
|
||||||
|
} $else $if field.typ is time.Time {
|
||||||
|
out.$(field.name) = time.unix(row.vals[i].int())
|
||||||
|
}
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,38 @@
|
||||||
module db
|
module db
|
||||||
|
|
||||||
import models { BuildLog }
|
import models { BuildLog, BuildLogFilter }
|
||||||
|
import time
|
||||||
|
|
||||||
// get_build_logs returns all BuildLog's in the database.
|
// get_build_logs returns all BuildLog's in the database.
|
||||||
pub fn (db &VieterDb) get_build_logs() []BuildLog {
|
pub fn (db &VieterDb) get_build_logs(filter BuildLogFilter) []BuildLog {
|
||||||
res := sql db.conn {
|
mut where_parts := []string{}
|
||||||
select from BuildLog order by id
|
|
||||||
|
if filter.repo != 0 {
|
||||||
|
where_parts << 'repo_id == $filter.repo'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filter.before != time.Time{} {
|
||||||
|
where_parts << 'start_time < $filter.before.unix_time()'
|
||||||
|
}
|
||||||
|
|
||||||
|
if filter.after != time.Time{} {
|
||||||
|
where_parts << 'start_time < $filter.after.unix_time()'
|
||||||
|
}
|
||||||
|
|
||||||
|
mut where_str := ''
|
||||||
|
|
||||||
|
if where_parts.len > 0 {
|
||||||
|
where_str = ' where ' + where_parts.map('($it)').join(' and ')
|
||||||
|
}
|
||||||
|
|
||||||
|
query := 'select from BuildLog' + where_str
|
||||||
|
rows, _ := db.conn.exec(query)
|
||||||
|
res := rows.map(row_into<BuildLog>(it))
|
||||||
|
|
||||||
|
// res := sql db.conn {
|
||||||
|
// select from BuildLog where filter.repo == 0 || repo_id == filter.repo order by id
|
||||||
|
// }
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ module models
|
||||||
import time
|
import time
|
||||||
|
|
||||||
pub struct BuildLog {
|
pub struct BuildLog {
|
||||||
pub:
|
pub mut:
|
||||||
id int [primary; sql: serial]
|
id int [primary; sql: serial]
|
||||||
repo_id int [nonull]
|
repo_id int [nonull]
|
||||||
start_time time.Time [nonull]
|
start_time time.Time [nonull]
|
||||||
|
|
@ -26,3 +26,16 @@ pub fn (bl &BuildLog) str() string {
|
||||||
|
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[params]
|
||||||
|
pub struct BuildLogFilter {
|
||||||
|
pub mut:
|
||||||
|
limit u64 = 25
|
||||||
|
offset u64
|
||||||
|
repo int
|
||||||
|
before time.Time
|
||||||
|
after time.Time
|
||||||
|
exit_codes_whitelist []u8
|
||||||
|
exit_codes_blacklist []u8
|
||||||
|
arch string
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue