pub struct DatabaseClient { /* private fields */ }Expand description
Async SurrealDB client with connection + retry management.
This is a thin wrapper over surrealdb::Surreal bound to the
dynamic Any engine. All methods are async and cancellation-safe
at the tokio level.
The client is Clone-able: every clone shares the same underlying
connection (the surrealdb SDK holds its own Arc).
Implementations§
Source§impl DatabaseClient
impl DatabaseClient
Sourcepub fn new(config: ConnectionConfig) -> Result<Self>
pub fn new(config: ConnectionConfig) -> Result<Self>
Build a new client. Does not open a network connection; call
DatabaseClient::connect for that.
Sourcepub fn config(&self) -> &ConnectionConfig
pub fn config(&self) -> &ConnectionConfig
Borrow the underlying configuration.
Sourcepub fn inner(&self) -> &Surreal<Any>
pub fn inner(&self) -> &Surreal<Any>
Borrow the underlying SurrealDB SDK handle (advanced usage).
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Return true if DatabaseClient::connect has completed successfully.
Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Establish the connection and select the configured namespace / database.
Retries with exponential backoff up to
ConnectionConfig::retry_max_attempts times; each attempt is
bounded by ConnectionConfig::timeout.
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Close the underlying connection. Safe to call even if not connected.
Sourcepub async fn signin<C: Credentials + ?Sized>(
&self,
creds: &C,
) -> Result<TokenAuth>
pub async fn signin<C: Credentials + ?Sized>( &self, creds: &C, ) -> Result<TokenAuth>
Sign in using one of the four auth levels.
Sourcepub async fn signup(&self, creds: &ScopeCredentials) -> Result<TokenAuth>
pub async fn signup(&self, creds: &ScopeCredentials) -> Result<TokenAuth>
Sign up a scope user (record access).
Sourcepub async fn authenticate(&self, token: &str) -> Result<()>
pub async fn authenticate(&self, token: &str) -> Result<()>
Authenticate using a previously-issued JWT.
Sourcepub async fn invalidate(&self) -> Result<()>
pub async fn invalidate(&self) -> Result<()>
Invalidate the current session.
Sourcepub async fn query(&self, surql: &str) -> Result<Value>
pub async fn query(&self, surql: &str) -> Result<Value>
Execute a raw SurrealQL query and return every statement’s result as a JSON array (one entry per statement).
Sourcepub async fn query_with_vars(
&self,
surql: &str,
vars: BTreeMap<String, Value>,
) -> Result<Value>
pub async fn query_with_vars( &self, surql: &str, vars: BTreeMap<String, Value>, ) -> Result<Value>
Execute a raw SurrealQL query with bound variables.
Sourcepub async fn select<T: DeserializeOwned>(&self, target: &str) -> Result<Vec<T>>
pub async fn select<T: DeserializeOwned>(&self, target: &str) -> Result<Vec<T>>
Typed SELECT against a table or record ID ("user" / "user:alice").
Internally routes through raw SurrealQL + serde_json::Value
so callers only need serde::de::DeserializeOwned; the 3.x
SDK’s typed select would force a SurrealValue bound on
T, which would be a breaking change for existing users.
Sourcepub async fn create<T>(&self, target: &str, data: T) -> Result<T>
pub async fn create<T>(&self, target: &str, data: T) -> Result<T>
Typed CREATE. Returns the created record.
Sourcepub async fn update<T>(&self, target: &str, data: T) -> Result<T>
pub async fn update<T>(&self, target: &str, data: T) -> Result<T>
Typed UPDATE. Returns the updated record.
Sourcepub async fn merge<D, T>(&self, target: &str, data: D) -> Result<T>
pub async fn merge<D, T>(&self, target: &str, data: D) -> Result<T>
Typed MERGE. Returns the merged record.
The input (D) is a partial patch; the output (T) is the full
merged record. Pass a serde_json::Value or a dedicated patch
struct for D.
Trait Implementations§
Source§impl Clone for DatabaseClient
impl Clone for DatabaseClient
Source§fn clone(&self) -> DatabaseClient
fn clone(&self) -> DatabaseClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DatabaseClient
impl !RefUnwindSafe for DatabaseClient
impl Send for DatabaseClient
impl Sync for DatabaseClient
impl Unpin for DatabaseClient
impl UnsafeUnpin for DatabaseClient
impl !UnwindSafe for DatabaseClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request