1use rusqlite::{Statement, Transaction};
2
3pub struct DbStatements<'a> {
4 pub repo_insert: Statement<'a>,
5 pub package_insert: Statement<'a>,
6 pub maintainer_insert: Statement<'a>,
7 pub maintainer_check: Statement<'a>,
8 pub pkg_maintainer_insert: Statement<'a>,
9}
10
11impl<'a> DbStatements<'a> {
12 pub fn new(tx: &'a Transaction) -> rusqlite::Result<Self> {
13 Ok(Self {
14 repo_insert: tx.prepare(
15 "INSERT INTO repository (name, etag)
16 VALUES (?1, ?2)
17 ON CONFLICT (name) DO UPDATE SET etag = ?2",
18 )?,
19 maintainer_insert: tx
20 .prepare("INSERT INTO maintainers (name, contact) VALUES (?1, ?2)")?,
21 maintainer_check: tx.prepare("SELECT id FROM maintainers WHERE contact=?1 LIMIT 1")?,
22 pkg_maintainer_insert: tx.prepare(
23 "INSERT INTO package_maintainers (
24 maintainer_id, package_id
25 ) VALUES (?1, ?2)
26 ON CONFLICT (maintainer_id, package_id) DO NOTHING",
27 )?,
28 package_insert: tx.prepare(
29 "INSERT INTO packages (
30 disabled, disabled_reason, rank, pkg, pkg_id, pkg_name,
31 pkg_family, pkg_type, pkg_webpage, app_id, description,
32 version, version_upstream, licenses, download_url,
33 size, ghcr_pkg, ghcr_size, ghcr_files, ghcr_blob, ghcr_url,
34 bsum, shasum, icon, desktop, appstream, homepages, notes,
35 source_urls, tags, categories, build_id, build_date,
36 build_action, build_script, build_log, provides, snapshots,
37 repology, replaces, download_count, download_count_week,
38 download_count_month, bundle, bundle_type, soar_syms,
39 deprecated, desktop_integration, external, installable,
40 portable, recurse_provides, trusted, version_latest,
41 version_outdated
42 )
43 VALUES
44 (
45 ?1, jsonb(?2), ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12,
46 ?13, jsonb(?14), ?15, ?16, ?17, ?18, jsonb(?19), ?20, ?21,
47 ?22, ?23, ?24, ?25, ?26, jsonb(?27), jsonb(?28), jsonb(?29),
48 jsonb(?30), jsonb(?31), ?32, ?33, ?34, ?35, ?36, jsonb(?37),
49 jsonb(?38), jsonb(?39), jsonb(?40), ?41, ?42, ?43, ?44,
50 ?45, ?46, ?47, ?48, ?49, ?50, ?51, ?52, ?53, ?54, ?55
51 )
52 ON CONFLICT (pkg_id, pkg_name, version) DO NOTHING",
53 )?,
54 })
55 }
56}