chore: cleaning & deref

This commit is contained in:
Per Stark
2024-11-07 08:30:55 +01:00
parent d2323a9262
commit 0cc4046cf5
4 changed files with 41 additions and 17 deletions
+19 -4
View File
@@ -1,4 +1,9 @@
use surrealdb::{engine::remote::ws::{Client, Ws}, opt::auth::Root, Surreal};
use std::ops::Deref;
use surrealdb::{
engine::remote::ws::{Client, Ws},
opt::auth::Root,
Surreal,
};
use thiserror::Error;
#[derive(Clone)]
@@ -10,11 +15,9 @@ pub struct SurrealDbClient {
pub enum SurrealError {
#[error("SurrealDb error: {0}")]
SurrealDbError(#[from] surrealdb::Error),
// Add more error variants as needed.
}
impl SurrealDbClient {
/// # Initialize a new datbase client
///
@@ -26,7 +29,11 @@ impl SurrealDbClient {
let db = Surreal::new::<Ws>("127.0.0.1:8000").await?;
// Sign in to database
db.signin(Root{username: "root_user", password: "root_password"}).await?;
db.signin(Root {
username: "root_user",
password: "root_password",
})
.await?;
// Set namespace
db.use_ns("test").use_db("test").await?;
@@ -34,3 +41,11 @@ impl SurrealDbClient {
Ok(SurrealDbClient { client: db })
}
}
impl Deref for SurrealDbClient {
type Target = Surreal<Client>;
fn deref(&self) -> &Self::Target {
&self.client
}
}