1use diesel::{prelude::*, sqlite::Sqlite};
2use serde_json::Value;
3
4use crate::{json_vec, models::types::PackageProvide, schema::core::*};
5
6#[derive(Debug, Selectable)]
7pub struct Package {
8 pub id: i32,
9 pub repo_name: String,
10 pub pkg_id: String,
11 pub pkg_name: String,
12 pub pkg_type: Option<String>,
13 pub version: String,
14 pub size: i64,
15 pub checksum: Option<String>,
16 pub installed_path: String,
17 pub installed_date: String,
18 pub profile: String,
19 pub pinned: bool,
20 pub is_installed: bool,
21 pub with_pkg_id: bool,
22 pub detached: bool,
23 pub unlinked: bool,
24 pub provides: Option<Vec<PackageProvide>>,
25 pub install_patterns: Option<Vec<String>>,
26}
27
28impl Queryable<packages::SqlType, Sqlite> for Package {
29 type Row = (
30 i32,
31 String,
32 String,
33 String,
34 Option<String>,
35 String,
36 i64,
37 Option<String>,
38 String,
39 String,
40 String,
41 bool,
42 bool,
43 bool,
44 bool,
45 bool,
46 Option<Value>,
47 Option<Value>,
48 );
49
50 fn build(row: Self::Row) -> diesel::deserialize::Result<Self> {
51 Ok(Self {
52 id: row.0,
53 repo_name: row.1,
54 pkg_id: row.2,
55 pkg_name: row.3,
56 pkg_type: row.4,
57 version: row.5,
58 size: row.6,
59 checksum: row.7,
60 installed_path: row.8,
61 installed_date: row.9,
62 profile: row.10,
63 pinned: row.11,
64 is_installed: row.12,
65 with_pkg_id: row.13,
66 detached: row.14,
67 unlinked: row.15,
68 provides: json_vec!(row.16),
69 install_patterns: json_vec!(row.17),
70 })
71 }
72}
73
74#[derive(Debug, Queryable, Selectable)]
75#[diesel(table_name = portable_package)]
76#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
77pub struct PortablePackage {
78 pub package_id: i32,
79 pub portable_path: Option<String>,
80 pub portable_home: Option<String>,
81 pub portable_config: Option<String>,
82 pub portable_share: Option<String>,
83 pub portable_cache: Option<String>,
84}
85
86#[derive(Default, Insertable)]
87#[diesel(table_name = packages)]
88pub struct NewPackage<'a> {
89 pub repo_name: &'a str,
90 pub pkg_id: &'a str,
91 pub pkg_name: &'a str,
92 pub pkg_type: Option<&'a str>,
93 pub version: &'a str,
94 pub size: i64,
95 pub checksum: Option<&'a str>,
96 pub installed_path: &'a str,
97 pub installed_date: &'a str,
98 pub profile: &'a str,
99 pub pinned: bool,
100 pub is_installed: bool,
101 pub with_pkg_id: bool,
102 pub detached: bool,
103 pub unlinked: bool,
104 pub provides: Option<Value>,
105 pub install_patterns: Option<Value>,
106}
107
108#[derive(Default, Insertable)]
109#[diesel(table_name = portable_package)]
110pub struct NewPortablePackage<'a> {
111 pub package_id: i32,
112 pub portable_path: Option<&'a str>,
113 pub portable_home: Option<&'a str>,
114 pub portable_config: Option<&'a str>,
115 pub portable_share: Option<&'a str>,
116 pub portable_cache: Option<&'a str>,
117}