refactoring: working macro and generics

This commit is contained in:
Per Stark
2024-11-20 22:44:30 +01:00
parent 7222223c31
commit 41134cfa49
11 changed files with 198 additions and 167 deletions
+2 -10
View File
@@ -2,22 +2,14 @@ use std::ops::Deref;
use surrealdb::{
engine::remote::ws::{Client, Ws},
opt::auth::Root,
Surreal,
Error, Surreal,
};
use thiserror::Error;
#[derive(Clone)]
pub struct SurrealDbClient {
pub client: Surreal<Client>,
}
#[derive(Error, Debug)]
pub enum SurrealError {
#[error("SurrealDb error: {0}")]
SurrealDbError(#[from] surrealdb::Error),
// Add more error variants as needed.
}
impl SurrealDbClient {
/// # Initialize a new datbase client
///
@@ -25,7 +17,7 @@ impl SurrealDbClient {
///
/// # Returns
/// * `SurrealDbClient` initialized
pub async fn new() -> Result<Self, SurrealError> {
pub async fn new() -> Result<Self, Error> {
let db = Surreal::new::<Ws>("127.0.0.1:8000").await?;
// Sign in to database