aboutsummaryrefslogtreecommitdiff
path: root/database/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-06 19:10:37 +0100
committermetamuffin <metamuffin@disroot.org>2026-01-06 19:10:37 +0100
commitffa6b5c4ae2cdd3e07426ed0330f3f66e90ee57b (patch)
tree79a03bc7ed938a3698ece0878f0ce5337ff6db23 /database/src
parentffbdb9ce397a6408d5a91cbdcbaf4e13b0c3ba0b (diff)
downloadjellything-ffa6b5c4ae2cdd3e07426ed0330f3f66e90ee57b.tar
jellything-ffa6b5c4ae2cdd3e07426ed0330f3f66e90ee57b.tar.bz2
jellything-ffa6b5c4ae2cdd3e07426ed0330f3f66e90ee57b.tar.zst
tag registry
Diffstat (limited to 'database/src')
-rw-r--r--database/src/indices/key.rs26
-rw-r--r--database/src/indices/mod.rs11
-rw-r--r--database/src/indices/order.rs21
-rw-r--r--database/src/table.rs24
4 files changed, 44 insertions, 38 deletions
diff --git a/database/src/indices/key.rs b/database/src/indices/key.rs
index ab38d71..2790220 100644
--- a/database/src/indices/key.rs
+++ b/database/src/indices/key.rs
@@ -8,18 +8,18 @@ use crate::{
backends::{ReadTransaction, WriteTransaction},
indices::Index,
prefix_iterator::PrefixIterator,
- table::{RowNum, Table, TableNum},
+ table::{RowNum, TableNum},
};
use anyhow::Result;
+use jellycommon::jellyobject::{Object, Tag};
-pub struct KeyIndex<T> {
+pub struct KeyIndex {
id: TableNum,
- key: fn(&T) -> &[u8],
+ key: Vec<Tag>,
}
-impl<T: 'static> KeyIndex<T> {
- pub fn new(table: &mut Table<T>, id: TableNum, key: fn(&T) -> &[u8]) -> Self {
- table.indices.push(Box::new(Self { id, key }));
+impl KeyIndex {
+ pub fn new(id: TableNum, key: Vec<Tag>) -> Self {
Self { id, key }
}
pub fn key(&self, id: RowNum, key: &[u8]) -> Vec<u8> {
@@ -43,15 +43,15 @@ impl<T: 'static> KeyIndex<T> {
})
}
}
-impl<T: 'static> Index<T> for KeyIndex<T> {
- fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: &T) -> Result<()> {
- db.set(&self.key(id, (self.key)(val)), &[])
+impl Index for KeyIndex {
+ fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> {
+ // db.set(&self.key(id, (self.key)(val)), &[])
}
- fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: &T) -> Result<()> {
- db.del(&self.key(id, (self.key)(val)))
+ fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> {
+ // db.del(&self.key(id, (self.key)(val)))
}
- fn compare(&self, before: &T, after: &T) -> bool {
- (self.key)(before) == (self.key)(after)
+ fn compare(&self, before: Object, after: Object) -> bool {
+ // (self.key)(before) == (self.key)(after)
}
}
diff --git a/database/src/indices/mod.rs b/database/src/indices/mod.rs
index ab37589..ad3d00f 100644
--- a/database/src/indices/mod.rs
+++ b/database/src/indices/mod.rs
@@ -6,14 +6,15 @@
use crate::{backends::WriteTransaction, table::RowNum};
use anyhow::Result;
+use jellycommon::jellyobject::Object;
-pub mod order;
pub mod key;
+pub mod order;
-pub trait Index<T> {
- fn add(&self, db: &mut dyn WriteTransaction, row: RowNum, val: &T) -> Result<()>;
- fn remove(&self, db: &mut dyn WriteTransaction, row: RowNum, val: &T) -> Result<()>;
- fn compare(&self, before: &T, after: &T) -> bool {
+pub trait Index {
+ fn add(&self, db: &mut dyn WriteTransaction, row: RowNum, val: Object) -> Result<()>;
+ fn remove(&self, db: &mut dyn WriteTransaction, row: RowNum, val: Object) -> Result<()>;
+ fn compare(&self, before: Object, after: Object) -> bool {
let _ = (before, after);
true
}
diff --git a/database/src/indices/order.rs b/database/src/indices/order.rs
index 9163681..911ec37 100644
--- a/database/src/indices/order.rs
+++ b/database/src/indices/order.rs
@@ -7,34 +7,35 @@
use crate::{
backends::WriteTransaction,
indices::Index,
- table::{RowNum, Table, TableNum},
+ table::{RowNum, TableNum},
};
use anyhow::Result;
use bytemuck::{NoUninit, bytes_of};
+use jellycommon::jellyobject::{Object, Tag};
-pub struct OrderIndex<T> {
+#[derive(Clone)]
+pub struct OrderIndex {
id: TableNum,
- value: fn(&T) -> [u8; 8],
+ key: Vec<Tag>,
}
#[repr(C)]
#[derive(NoUninit, Clone, Copy)]
struct Key(TableNum, [u8; 8], RowNum);
-impl<T: 'static> OrderIndex<T> {
- pub fn new(table: &mut Table<T>, id: TableNum, value: fn(&T) -> [u8; 8]) -> Self {
- table.indices.push(Box::new(Self { id, value }));
+impl OrderIndex {
+ pub fn new(id: TableNum, value: fn(Object) -> [u8; 8]) -> Self {
Self { id, value }
}
}
-impl<T: 'static> Index<T> for OrderIndex<T> {
- fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: &T) -> Result<()> {
+impl Index for OrderIndex {
+ fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> {
db.set(bytes_of(&Key(self.id, (self.value)(val), id)), &[])
}
- fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: &T) -> Result<()> {
+ fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> {
db.del(bytes_of(&Key(self.id, (self.value)(val), id)))
}
- fn compare(&self, before: &T, after: &T) -> bool {
+ fn compare(&self, before: Object, after: Object) -> bool {
(self.value)(before) == (self.value)(after)
}
}
diff --git a/database/src/table.rs b/database/src/table.rs
index ba95f8e..42e03a3 100644
--- a/database/src/table.rs
+++ b/database/src/table.rs
@@ -4,21 +4,23 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
+use std::sync::Arc;
+
use crate::{
backends::{ReadTransaction, WriteTransaction},
indices::Index,
};
use anyhow::Result;
-use serde::{Serialize, de::DeserializeOwned};
+use jellycommon::jellyobject::{Object, ObjectBuffer};
pub type TableNum = u64;
pub type RowNum = u64;
-pub struct Table<T> {
+pub struct Table {
id: u32,
- pub(crate) indices: Vec<Box<dyn Index<T>>>,
+ pub(crate) indices: Vec<Box<dyn Index>>,
}
-impl<T: Serialize + DeserializeOwned> Table<T> {
+impl Table {
pub fn new(id: u32) -> Self {
Self {
id,
@@ -49,18 +51,20 @@ impl<T: Serialize + DeserializeOwned> Table<T> {
Ok(id_counter)
}
- pub fn get(&self, db: &dyn ReadTransaction, row: RowNum) -> Result<Option<T>> {
- Ok(db
- .get(&self.key(row))?
- .map(|v| serde_json::from_slice(&v))
- .transpose()?)
+ pub fn add_index<T: Index + Clone + 'static>(&mut self, index: T) -> T {
+ self.indices.push(Box::new(index.clone()));
+ index
+ }
+ pub fn get(&self, db: &dyn ReadTransaction, row: RowNum) -> Result<Option<ObjectBuffer>> {
+ Ok(db.get(&self.key(row))?.map(ObjectBuffer::from))
}
pub fn remove(&self, db: &mut dyn WriteTransaction, row: RowNum) -> Result<bool> {
let Some(entry) = self.get(db, row)? else {
return Ok(false);
};
+ let ob = entry.as_object();
for idx in &self.indices {
- idx.remove(db, row, &entry)?;
+ idx.remove(db, row, ob)?;
}
db.del(&self.key(row))?;
Ok(true)