tirbofish/kitgit · commit
74330dd2e702c19312674a028064e5d313f58876
merge: feat/better-search into integrate/all-features
Type: SSH
SSH Key Fingerprint:
Verified
SgQHY4vUORbJC3ZtdixCl62ek/4QGh/iG2FRSyjfGPc
@@ -812,6 +812,253 @@ pub async fn list_public_repos( .collect()) } +fn ilike_contains(term: &str) -> String { + format!("%{}%", term.replace('%', "\\%").replace('_', "\\_")) +} + +pub async fn search_repos( + pool: &PgPool, + query: &str, + viewer: Option<Uuid>, + limit: i64, +) -> Result<Vec<(Repository, String)>> { + #[derive(sqlx::FromRow)] + struct Row { + id: Uuid, + owner_id: Uuid, + name: String, + description: String, + visibility: String, + default_branch: String, + archived: bool, + issues_enabled: bool, + pulls_enabled: bool, + releases_enabled: bool, + allow_merge: bool, + allow_squash: bool, + allow_rebase: bool, + default_merge_style: String, + protect_default_branch: bool, + protect_block_force_push: bool, + fork_of_id: Option<Uuid>, + stars_count: i32, + watches_count: i32, + forks_count: i32, + created_at: DateTime<Utc>, + updated_at: DateTime<Utc>, + owner_username: String, + } + + let like = ilike_contains(query.trim()); + let rows: Vec<Row> = sqlx::query_as( + r#" + SELECT r.*, u.username AS owner_username + FROM repositories r
Large diffs are not rendered by default. Showing the first 50 of 653 lines. Show full diff