1use diesel::{prelude::*, sqlite::Sqlite};
2use serde_json::Value;
3
4use crate::{json_vec, models::types::PackageProvide, schema::metadata::*};
5
6#[derive(Debug, Clone, Selectable)]
7pub struct Package {
8 pub id: i32,
9 pub pkg_id: String,
10 pub pkg_name: String,
11 pub pkg_type: Option<String>,
12 pub pkg_webpage: Option<String>,
13 pub app_id: Option<String>,
14 pub description: Option<String>,
15 pub version: String,
16 pub licenses: Option<Vec<String>>,
17 pub download_url: String,
18 pub size: Option<i64>,
19 pub ghcr_pkg: Option<String>,
20 pub ghcr_size: Option<i64>,
21 pub ghcr_blob: Option<String>,
22 pub ghcr_url: Option<String>,
23 pub bsum: Option<String>,
24 pub icon: Option<String>,
25 pub desktop: Option<String>,
26 pub appstream: Option<String>,
27 pub homepages: Option<Vec<String>>,
28 pub notes: Option<Vec<String>>,
29 pub source_urls: Option<Vec<String>>,
30 pub tags: Option<Vec<String>>,
31 pub categories: Option<Vec<String>>,
32 pub build_id: Option<String>,
33 pub build_date: Option<String>,
34 pub build_action: Option<String>,
35 pub build_script: Option<String>,
36 pub build_log: Option<String>,
37 pub provides: Option<Vec<PackageProvide>>,
38 pub snapshots: Option<Vec<String>>,
39 pub replaces: Option<Vec<String>>,
40 pub soar_syms: bool,
41 pub desktop_integration: Option<bool>,
42 pub portable: Option<bool>,
43 pub recurse_provides: Option<bool>,
44}
45
46impl Queryable<packages::SqlType, Sqlite> for Package {
47 type Row = (
48 i32,
49 String,
50 String,
51 Option<String>,
52 Option<String>,
53 Option<String>,
54 Option<String>,
55 String,
56 Option<Value>,
57 String,
58 Option<i64>,
59 Option<String>,
60 Option<i64>,
61 Option<String>,
62 Option<String>,
63 Option<String>,
64 Option<String>,
65 Option<String>,
66 Option<String>,
67 Option<Value>,
68 Option<Value>,
69 Option<Value>,
70 Option<Value>,
71 Option<Value>,
72 Option<String>,
73 Option<String>,
74 Option<String>,
75 Option<String>,
76 Option<String>,
77 Option<Value>,
78 Option<Value>,
79 Option<Value>,
80 bool,
81 Option<bool>,
82 Option<bool>,
83 Option<bool>,
84 );
85
86 fn build(row: Self::Row) -> diesel::deserialize::Result<Self> {
87 Ok(Self {
88 id: row.0,
89 pkg_id: row.1,
90 pkg_name: row.2,
91 pkg_type: row.3,
92 pkg_webpage: row.4,
93 app_id: row.5,
94 description: row.6,
95 version: row.7,
96 licenses: json_vec!(row.8),
97 download_url: row.9,
98 size: row.10,
99 ghcr_pkg: row.11,
100 ghcr_size: row.12,
101 ghcr_blob: row.13,
102 ghcr_url: row.14,
103 bsum: row.15,
104 icon: row.16,
105 desktop: row.17,
106 appstream: row.18,
107 homepages: json_vec!(row.19),
108 notes: json_vec!(row.20),
109 source_urls: json_vec!(row.21),
110 tags: json_vec!(row.22),
111 categories: json_vec!(row.23),
112 build_id: row.24,
113 build_date: row.25,
114 build_action: row.26,
115 build_script: row.27,
116 build_log: row.28,
117 provides: json_vec!(row.29),
118 snapshots: json_vec!(row.30),
119 replaces: json_vec!(row.31),
120 soar_syms: row.32,
121 desktop_integration: row.33,
122 portable: row.34,
123 recurse_provides: row.35,
124 })
125 }
126}
127
128#[derive(Debug, Clone, Queryable, Selectable)]
131#[diesel(table_name = packages)]
132#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
133pub struct PackageListing {
134 pub pkg_id: String,
135 pub pkg_name: String,
136 pub pkg_type: Option<String>,
137 pub version: String,
138}
139
140#[derive(Debug, Clone)]
143pub struct PackageWithRepo {
144 pub repo_name: String,
145 pub package: Package,
146}
147
148impl PackageWithRepo {
149 pub fn new(repo_name: String, package: Package) -> Self {
150 Self {
151 repo_name,
152 package,
153 }
154 }
155}
156
157#[derive(Debug, Queryable, Selectable)]
158#[diesel(table_name = maintainers)]
159#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
160pub struct Maintainer {
161 pub id: i32,
162 pub contact: String,
163 pub name: String,
164}
165
166#[derive(Debug, Queryable, Selectable)]
167#[diesel(table_name = package_maintainers)]
168#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
169pub struct PackageMaintainer {
170 pub maintainer_id: i32,
171 pub package_id: i32,
172}
173
174#[derive(Default, Insertable)]
175#[diesel(table_name = packages)]
176pub struct NewPackage<'a> {
177 pub pkg_id: &'a str,
178 pub pkg_name: &'a str,
179 pub pkg_type: Option<&'a str>,
180 pub pkg_webpage: Option<&'a str>,
181 pub app_id: Option<&'a str>,
182 pub description: Option<&'a str>,
183 pub version: &'a str,
184 pub licenses: Option<Value>,
185 pub download_url: &'a str,
186 pub size: Option<i64>,
187 pub ghcr_pkg: Option<&'a str>,
188 pub ghcr_size: Option<i64>,
189 pub ghcr_blob: Option<&'a str>,
190 pub ghcr_url: Option<&'a str>,
191 pub bsum: Option<&'a str>,
192 pub icon: Option<&'a str>,
193 pub desktop: Option<&'a str>,
194 pub appstream: Option<&'a str>,
195 pub homepages: Option<Value>,
196 pub notes: Option<Value>,
197 pub source_urls: Option<Value>,
198 pub tags: Option<Value>,
199 pub categories: Option<Value>,
200 pub build_id: Option<&'a str>,
201 pub build_date: Option<&'a str>,
202 pub build_action: Option<&'a str>,
203 pub build_script: Option<&'a str>,
204 pub build_log: Option<&'a str>,
205 pub provides: Option<Value>,
206 pub snapshots: Option<Value>,
207 pub replaces: Option<Value>,
208 pub soar_syms: bool,
209 pub desktop_integration: Option<bool>,
210 pub portable: Option<bool>,
211 pub recurse_provides: Option<bool>,
212}
213
214#[derive(Default, Insertable)]
215#[diesel(table_name = maintainers)]
216pub struct NewMaintainer<'a> {
217 pub contact: &'a str,
218 pub name: &'a str,
219}
220
221#[derive(Default, Insertable)]
222#[diesel(table_name = package_maintainers)]
223pub struct NewPackageMaintainer {
224 pub maintainer_id: i32,
225 pub package_id: i32,
226}
227
228#[derive(Debug, Queryable, Selectable)]
229#[diesel(table_name = repository)]
230#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
231pub struct Repository {
232 pub rowid: i32,
233 pub name: String,
234 pub etag: String,
235}
236
237#[derive(Default, Insertable)]
238#[diesel(table_name = repository)]
239pub struct NewRepository<'a> {
240 pub name: &'a str,
241 pub etag: &'a str,
242}