From 5781796e99543f2f16d24bd210acb26d937d3684 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 3 May 2022 19:55:52 +0200 Subject: [PATCH] doc: added docstrings to all db/git functions --- CHANGELOG.md | 3 +++ src/cron/cli.v | 2 +- src/db/db.v | 1 + src/db/git.v | 10 +++++++++- src/git/client.v | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abbdc740..f40ce526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed * 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 diff --git a/src/cron/cli.v b/src/cron/cli.v index 9536c37c..15bc9867 100644 --- a/src/cron/cli.v +++ b/src/cron/cli.v @@ -8,7 +8,7 @@ pub: log_level string = 'WARN' api_key string address string - data_dir string + data_dir string base_image string = 'archlinux:base-devel' max_concurrent_builds int = 1 api_update_frequency int = 15 diff --git a/src/db/db.v b/src/db/db.v index b62fa3b7..a75c34c4 100644 --- a/src/db/db.v +++ b/src/db/db.v @@ -6,6 +6,7 @@ struct VieterDb { conn sqlite.DB } +// init initializes a database & adds the correct tables. pub fn init(db_path string) ?VieterDb { conn := sqlite.connect(db_path) ? diff --git a/src/db/git.v b/src/db/git.v index f4a66f0b..2fb2a92e 100644 --- a/src/db/git.v +++ b/src/db/git.v @@ -7,6 +7,7 @@ pub: value string [nonull] } +// str returns a string representation. pub fn (gra &GitRepoArch) str() string { return gra.value } @@ -27,6 +28,7 @@ pub mut: arch []GitRepoArch [fkey: 'repo_id'] } +// str returns a string representation. pub fn (gr &GitRepo) str() string { mut parts := [ '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 pub fn git_repo_from_params(params map[string]string) ?GitRepo { mut repo := GitRepo{} @@ -74,6 +76,7 @@ pub fn git_repo_from_params(params map[string]string) ?GitRepo { return repo } +// get_git_repos returns all GitRepo's in the database. pub fn (db &VieterDb) get_git_repos() []GitRepo { res := sql db.conn { select from GitRepo order by id @@ -82,6 +85,7 @@ pub fn (db &VieterDb) get_git_repos() []GitRepo { return res } +// get_git_repo tries to return a specific GitRepo. pub fn (db &VieterDb) get_git_repo(repo_id int) ?GitRepo { res := sql db.conn { select from GitRepo where id == repo_id @@ -97,12 +101,14 @@ pub fn (db &VieterDb) get_git_repo(repo_id int) ?GitRepo { return res } +// add_git_repo inserts the given GitRepo into the database. pub fn (db &VieterDb) add_git_repo(repo GitRepo) { sql db.conn { 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) { sql db.conn { 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) { // sql db.conn { // 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) } +// update_git_repo_archs updates a given GitRepo's arch value. pub fn (db &VieterDb) update_git_repo_archs(repo_id int, archs []GitRepoArch) { archs_with_id := archs.map(GitRepoArch{ ...it diff --git a/src/git/client.v b/src/git/client.v index f34d2ffd..b5f8e9fd 100644 --- a/src/git/client.v +++ b/src/git/client.v @@ -34,6 +34,7 @@ pub fn get_repos(address string, api_key string) ?[]db.GitRepo { 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 { data := send_request(http.Method.get, address, '/api/repos/$id', api_key, {}) ?