coven_database/
row_key.rs1#[derive(Clone, Debug, PartialEq)]
5pub struct RowKey(pub(crate) Vec<sqlive::rusqlite::types::Value>);
6
7impl RowKey {
8 #[expect(
10 clippy::map_err_ignore,
11 reason = "a stored value that won't convert or decode is DamagedDatabase"
12 )]
13 pub(crate) fn decode(key: &[u8]) -> Result<Self, crate::DbError> {
14 Ok(Self(
15 coven_format::key::decode_key(key)
16 .map_err(|_| crate::DbError::DamagedDatabase)?
17 .iter()
18 .map(crate::write_encoding::sql_value)
19 .collect(),
20 ))
21 }
22
23 pub fn values(&self) -> &[sqlive::rusqlite::types::Value] {
25 &self.0
26 }
27}
28
29impl sqlive::rusqlite::types::FromSql for RowKey {
33 fn column_result(
34 value: sqlive::rusqlite::types::ValueRef<'_>,
35 ) -> sqlive::rusqlite::types::FromSqlResult<Self> {
36 Self::decode(value.as_blob()?)
37 .map_err(|error| sqlive::rusqlite::types::FromSqlError::Other(Box::new(error)))
38 }
39}
40
41impl From<&str> for RowKey {
42 fn from(value: &str) -> Self {
43 Self(vec![sqlive::rusqlite::types::Value::Text(value.into())])
44 }
45}
46
47impl From<coven_foundation::uuid_text::UuidText> for RowKey {
48 fn from(value: coven_foundation::uuid_text::UuidText) -> Self {
49 Self(vec![value.into()])
50 }
51}
52
53impl<A: Into<sqlive::rusqlite::types::Value>, B: Into<sqlive::rusqlite::types::Value>> From<(A, B)>
54 for RowKey
55{
56 fn from((first, second): (A, B)) -> Self {
57 Self(vec![first.into(), second.into()])
58 }
59}
60
61impl From<Vec<sqlive::rusqlite::types::Value>> for RowKey {
62 fn from(values: Vec<sqlive::rusqlite::types::Value>) -> Self {
63 Self(values)
64 }
65}