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