forked from vieter-v/vieter
				
			doc: added docstrings to all db/git functions
							parent
							
								
									204144cee8
								
							
						
					
					
						commit
						5781796e99
					
				| 
						 | 
					@ -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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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) ?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								src/db/git.v
								
								
								
								
							
							
						
						
									
										10
									
								
								src/db/git.v
								
								
								
								
							| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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,
 | 
				
			||||||
		{}) ?
 | 
							{}) ?
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue