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