Skip to main content

SurrealClient

Struct SurrealClient 

Source
pub struct SurrealClient { /* private fields */ }

Implementations§

Source§

impl SurrealClient

Source

pub fn new( engine: Box<dyn Engine>, namespace: Option<String>, database: Option<String>, ) -> Self

Create a new SurrealDB instance with the given engine and optional namespace/database

Source

pub fn with_debug(self, enabled: bool) -> Self

Enable debug mode to log queries

Source

pub fn is_debug(&self) -> bool

Check if debug mode is enabled

Source

pub async fn let_var(&mut self, key: &str, value: Value) -> Result<()>

Set a parameter for the session

Source

pub async fn unset(&mut self, key: &str) -> Result<()>

Unset a parameter from the session

Source

pub async fn create(&self, resource: &str, data: Option<Value>) -> Result<Value>

Create a record in the database

Source

pub async fn select(&self, resource: &str) -> Result<Value>

Select records from the database

Source

pub async fn select_all(&self, table: Table) -> Result<Value>

Select all records from a table

Source

pub async fn select_record(&self, record: RecordId) -> Result<Value>

Select a specific record by ID

Source

pub async fn select_range(&self, range: RecordRange) -> Result<Value>

Select a range of records

Source

pub async fn update(&self, resource: &str, data: Option<Value>) -> Result<Value>

Update records in the database

Source

pub async fn update_record( &self, record: RecordId, data: Value, ) -> Result<Value>

Update a specific record by ID

Source

pub async fn update_all(&self, table: Table, data: Value) -> Result<Value>

Update all records in a table

Source

pub async fn upsert(&self, resource: &str, data: Option<Value>) -> Result<Value>

Upsert (insert or update) records in the database

Source

pub async fn upsert_record( &self, record: RecordId, data: Value, ) -> Result<Value>

Upsert a specific record by ID

Source

pub async fn merge(&self, resource: &str, data: Value) -> Result<Value>

Merge data into records in the database

Source

pub async fn merge_record(&self, record: RecordId, data: Value) -> Result<Value>

Merge data into a specific record by ID

Source

pub async fn merge_all(&self, table: Table, data: Value) -> Result<Value>

Merge data into all records in a table

Source

pub async fn patch(&self, resource: &str, patches: Vec<Value>) -> Result<Value>

Apply JSON patches to records Apply patches to records in the database

Source

pub async fn delete(&self, resource: &str) -> Result<Value>

Delete records from the database

Source

pub async fn delete_record(&self, record: RecordId) -> Result<Value>

Delete a specific record by ID

Source

pub async fn delete_all(&self, table: Table) -> Result<Value>

Delete all records from a table

Source

pub async fn insert(&self, table: &str, data: Value) -> Result<Value>

Insert records into the database Insert data into a table

Source

pub async fn insert_many(&self, table: Table, data: Vec<Value>) -> Result<Value>

Insert multiple records

Source

pub async fn relate( &self, from: &str, relation: &str, to: &str, data: Option<Value>, ) -> Result<Value>

Create a relation between records

Source

pub async fn relate_records( &self, from: RecordId, relation: Table, to: RecordId, data: Option<Value>, ) -> Result<Value>

Create a relation between specific records

Source

pub async fn run(&self, func: &str, args: Option<Value>) -> Result<Value>

Run a stored function

Source

pub async fn query(&self, sql: &str, variables: Option<Value>) -> Result<Value>

Execute a custom SurrealQL query

Source

pub async fn info(&self) -> Result<Value>

Get information about the current session

Source

pub async fn version(&self) -> Result<String>

Get the version of the SurrealDB instance

Source

pub async fn close(self) -> Result<()>

Close the connection

Source

pub async fn import( &self, _content: &str, _username: &str, _password: &str, ) -> Result<Value>

Import database content (HTTP only)

Source

pub async fn export(&self, _username: &str, _password: &str) -> Result<String>

Export database content (HTTP only)

Source

pub async fn import_ml( &self, _content: &str, _username: Option<&str>, _password: Option<&str>, ) -> Result<Value>

Import ML model (HTTP only)

Source

pub async fn export_ml( &self, _name: &str, _version: Option<&str>, _username: Option<&str>, _password: Option<&str>, ) -> Result<String>

Export ML model (HTTP only)

Source

pub async fn query_cbor( &self, sql: &str, variables: CborValue, ) -> Result<CborValue>

Execute a custom SurrealQL query with CBOR parameters

Trait Implementations§

Source§

impl Clone for SurrealClient

Source§

fn clone(&self) -> Self

Clone the client - creates a new client instance sharing the same engine and session

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more