mirror of
https://github.com/perstarkse/minne.git
synced 2026-09-16 23:11:20 +02:00
chore: cleaning & deref
This commit is contained in:
+19
-4
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user