helper functions

This commit is contained in:
Per Stark
2024-11-21 12:03:40 +01:00
parent ca598d52c3
commit 8df215d6c3

View File

@@ -5,6 +5,8 @@ use surrealdb::{
Error, Surreal,
};
use crate::storage::types::StoredObject;
#[derive(Clone)]
pub struct SurrealDbClient {
pub client: Surreal<Client>,
@@ -32,6 +34,24 @@ impl SurrealDbClient {
Ok(SurrealDbClient { client: db })
}
pub async fn rebuild_indexes(&self) -> Result<(), Error> {
self.client
.query("REBUILD INDEX IF EXISTS idx_embedding ON text_chunk")
.await?;
self.client
.query("REBUILD INDEX IF EXISTS embeddings ON knowledge_entity")
.await?;
Ok(())
}
pub async fn drop_table<T>(&self) -> Result<(), Error>
where
T: StoredObject + Send + Sync + 'static,
{
let _deleted: Vec<T> = self.client.delete(T::table_name()).await?;
Ok(())
}
}
impl Deref for SurrealDbClient {