holochain_sqlite/db/
kind.rs1use holo_hash::DnaHash;
2use holochain_zome_types::cell::CellId;
3use std::path::PathBuf;
4use std::sync::Arc;
5
6#[derive(Clone, Debug, PartialEq, Eq, Hash, derive_more::Display)]
8pub enum DbKind {
9 #[display(fmt = "{:?}-{:?}", "_0.dna_hash()", "_0.agent_pubkey()")]
11 Authored(Arc<CellId>),
12 #[display(fmt = "{:?}", "_0")]
14 Dht(Arc<DnaHash>),
15 #[display(fmt = "{:?}", "_0")]
17 Cache(Arc<DnaHash>),
18 Conductor,
20 Wasm,
22 PeerMetaStore(Arc<DnaHash>),
24 #[cfg(feature = "test_utils")]
25 Test(String),
26}
27
28pub trait DbKindT: Clone + std::fmt::Debug + Send + Sync + 'static {
29 fn kind(&self) -> DbKind;
30
31 fn filename(&self) -> PathBuf {
33 self.filename_inner()
34 }
35
36 fn filename_inner(&self) -> PathBuf;
39
40 fn if_corrupt_wipe(&self) -> bool;
45}
46
47pub trait DbKindOp {}
48
49#[derive(Clone, Debug, PartialEq, Eq, Hash, derive_more::Display)]
50pub struct DbKindAuthored(pub Arc<CellId>);
52
53#[derive(Clone, Debug, PartialEq, Eq, Hash, derive_more::Display)]
54pub struct DbKindDht(pub Arc<DnaHash>);
56
57#[derive(Clone, Debug, PartialEq, Eq, Hash, derive_more::Display)]
58pub struct DbKindCache(pub Arc<DnaHash>);
60
61#[derive(Clone, Debug, PartialEq, Eq, Hash, derive_more::Display)]
62pub struct DbKindConductor;
64
65#[derive(Clone, Debug, PartialEq, Eq, Hash, derive_more::Display)]
66pub struct DbKindWasm;
68
69#[derive(Clone, Debug, PartialEq, Eq, Hash, derive_more::Display)]
71pub struct DbKindPeerMetaStore(pub Arc<DnaHash>);
72
73impl DbKindT for DbKindAuthored {
74 fn kind(&self) -> DbKind {
75 DbKind::Authored(self.0.clone())
76 }
77
78 fn filename_inner(&self) -> PathBuf {
79 [
80 "authored",
81 &format!("{}-{}", self.0.dna_hash(), self.0.agent_pubkey()),
82 ]
83 .iter()
84 .collect()
85 }
86
87 fn if_corrupt_wipe(&self) -> bool {
88 false
89 }
90}
91
92impl DbKindOp for DbKindAuthored {}
93
94impl DbKindAuthored {
95 pub fn dna_hash(&self) -> &DnaHash {
96 self.0.dna_hash()
97 }
98}
99
100impl DbKindT for DbKindDht {
101 fn kind(&self) -> DbKind {
102 DbKind::Dht(self.0.clone())
103 }
104
105 fn filename_inner(&self) -> PathBuf {
106 ["dht", &self.0.to_string()].iter().collect()
107 }
108
109 fn if_corrupt_wipe(&self) -> bool {
110 true
111 }
112}
113
114impl DbKindOp for DbKindDht {}
115
116impl DbKindDht {
117 pub fn dna_hash(&self) -> &DnaHash {
118 &self.0
119 }
120 pub fn to_dna_hash(&self) -> Arc<DnaHash> {
121 self.0.clone()
122 }
123}
124
125impl DbKindT for DbKindCache {
126 fn kind(&self) -> DbKind {
127 DbKind::Cache(self.0.clone())
128 }
129
130 fn filename_inner(&self) -> PathBuf {
131 ["cache", &self.0.to_string()].iter().collect()
132 }
133
134 fn if_corrupt_wipe(&self) -> bool {
135 true
136 }
137}
138
139impl DbKindCache {
140 pub fn dna_hash(&self) -> &DnaHash {
141 &self.0
142 }
143 pub fn to_dna_hash(&self) -> Arc<DnaHash> {
144 self.0.clone()
145 }
146}
147
148impl DbKindOp for DbKindCache {}
149
150impl DbKindT for DbKindConductor {
151 fn kind(&self) -> DbKind {
152 DbKind::Conductor
153 }
154
155 fn filename_inner(&self) -> PathBuf {
156 ["conductor", "conductor"].iter().collect()
157 }
158
159 fn if_corrupt_wipe(&self) -> bool {
160 false
161 }
162}
163
164impl DbKindT for DbKindWasm {
165 fn kind(&self) -> DbKind {
166 DbKind::Wasm
167 }
168
169 fn filename_inner(&self) -> PathBuf {
170 ["wasm", "wasm"].iter().collect()
171 }
172
173 fn if_corrupt_wipe(&self) -> bool {
174 false
175 }
176}
177
178impl DbKindT for DbKindPeerMetaStore {
179 fn kind(&self) -> DbKind {
180 DbKind::PeerMetaStore(self.0.clone())
181 }
182
183 fn filename_inner(&self) -> PathBuf {
184 ["p2p", &format!("peer-meta-{}", self.0)].iter().collect()
185 }
186
187 fn if_corrupt_wipe(&self) -> bool {
188 true
189 }
190}