doc: added docstrings to all db/git functions

cron-docs
Jef Roosens 2022-05-03 19:55:52 +02:00
parent 204144cee8
commit 5781796e99
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
5 changed files with 15 additions and 2 deletions

View File

@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
* Switched from compiler fork to fully vanilla compiler mirror * Switched from compiler fork to fully vanilla compiler mirror
* `download_dir`, `repos_file` & `repos_dir` config values have been replaced
with `data_dir`
* Storage of metadata (e.g. Git repositories) is now done using Sqlite
### Added ### Added

View File

@ -8,7 +8,7 @@ pub:
log_level string = 'WARN' log_level string = 'WARN'
api_key string api_key string
address string address string
data_dir string data_dir string
base_image string = 'archlinux:base-devel' base_image string = 'archlinux:base-devel'
max_concurrent_builds int = 1 max_concurrent_builds int = 1
api_update_frequency int = 15 api_update_frequency int = 15

View File

@ -6,6 +6,7 @@ struct VieterDb {
conn sqlite.DB conn sqlite.DB
} }
// init initializes a database & adds the correct tables.
pub fn init(db_path string) ?VieterDb { pub fn init(db_path string) ?VieterDb {
conn := sqlite.connect(db_path) ? conn := sqlite.connect(db_path) ?

View File

@ -7,6 +7,7 @@ pub:
value string [nonull] value string [nonull]
} }
// str returns a string representation.
pub fn (gra &GitRepoArch) str() string { pub fn (gra &GitRepoArch) str() string {
return gra.value return gra.value
} }
@ -27,6 +28,7 @@ pub mut:
arch []GitRepoArch [fkey: 'repo_id'] arch []GitRepoArch [fkey: 'repo_id']
} }
// str returns a string representation.
pub fn (gr &GitRepo) str() string { pub fn (gr &GitRepo) str() string {
mut parts := [ mut parts := [
'id: $gr.id', 'id: $gr.id',
@ -57,7 +59,7 @@ pub fn (mut r GitRepo) patch_from_params(params map[string]string) {
} }
} }
// repo_from_params creates a GitRepo from a map[string]string, usually // git_repo_from_params creates a GitRepo from a map[string]string, usually
// provided from a web.App's params // provided from a web.App's params
pub fn git_repo_from_params(params map[string]string) ?GitRepo { pub fn git_repo_from_params(params map[string]string) ?GitRepo {
mut repo := GitRepo{} mut repo := GitRepo{}
@ -74,6 +76,7 @@ pub fn git_repo_from_params(params map[string]string) ?GitRepo {
return repo return repo
} }
// get_git_repos returns all GitRepo's in the database.
pub fn (db &VieterDb) get_git_repos() []GitRepo { pub fn (db &VieterDb) get_git_repos() []GitRepo {
res := sql db.conn { res := sql db.conn {
select from GitRepo order by id select from GitRepo order by id
@ -82,6 +85,7 @@ pub fn (db &VieterDb) get_git_repos() []GitRepo {
return res return res
} }
// get_git_repo tries to return a specific GitRepo.
pub fn (db &VieterDb) get_git_repo(repo_id int) ?GitRepo { pub fn (db &VieterDb) get_git_repo(repo_id int) ?GitRepo {
res := sql db.conn { res := sql db.conn {
select from GitRepo where id == repo_id select from GitRepo where id == repo_id
@ -97,12 +101,14 @@ pub fn (db &VieterDb) get_git_repo(repo_id int) ?GitRepo {
return res return res
} }
// add_git_repo inserts the given GitRepo into the database.
pub fn (db &VieterDb) add_git_repo(repo GitRepo) { pub fn (db &VieterDb) add_git_repo(repo GitRepo) {
sql db.conn { sql db.conn {
insert repo into GitRepo insert repo into GitRepo
} }
} }
// delete_git_repo deletes the repo with the given ID from the database.
pub fn (db &VieterDb) delete_git_repo(repo_id int) { pub fn (db &VieterDb) delete_git_repo(repo_id int) {
sql db.conn { sql db.conn {
delete from GitRepo where id == repo_id delete from GitRepo where id == repo_id
@ -110,6 +116,7 @@ pub fn (db &VieterDb) delete_git_repo(repo_id int) {
} }
} }
// update_git_repo updates any non-array values for a given GitRepo.
pub fn (db &VieterDb) update_git_repo(repo_id int, params map[string]string) { pub fn (db &VieterDb) update_git_repo(repo_id int, params map[string]string) {
// sql db.conn { // sql db.conn {
// update GitRepo set repo // update GitRepo set repo
@ -130,6 +137,7 @@ pub fn (db &VieterDb) update_git_repo(repo_id int, params map[string]string) {
db.conn.exec_none(query) db.conn.exec_none(query)
} }
// update_git_repo_archs updates a given GitRepo's arch value.
pub fn (db &VieterDb) update_git_repo_archs(repo_id int, archs []GitRepoArch) { pub fn (db &VieterDb) update_git_repo_archs(repo_id int, archs []GitRepoArch) {
archs_with_id := archs.map(GitRepoArch{ archs_with_id := archs.map(GitRepoArch{
...it ...it

View File

@ -34,6 +34,7 @@ pub fn get_repos(address string, api_key string) ?[]db.GitRepo {
return data.data return data.data
} }
// get_repo returns the repo for a specific ID.
pub fn get_repo(address string, api_key string, id int) ?db.GitRepo { pub fn get_repo(address string, api_key string, id int) ?db.GitRepo {
data := send_request<db.GitRepo>(http.Method.get, address, '/api/repos/$id', api_key, data := send_request<db.GitRepo>(http.Method.get, address, '/api/repos/$id', api_key,
{}) ? {}) ?