surrealdb::kvs

Struct Transaction

Source
pub struct Transaction { /* private fields */ }
Expand description

A set of undoable updates and requests against a dataset.

Implementations§

Source§

impl Transaction

Source

pub fn rollback_with_warning(self) -> Self

Source

pub fn rollback_with_panic(self) -> Self

Source

pub fn rollback_and_ignore(self) -> Self

Source

pub fn enclose(self) -> Arc<Mutex<Self>>

Source

pub async fn closed(&self) -> bool

Check if transaction is finished.

If the transaction has been cancelled or committed, then this function will return true, and any further calls to functions on this transaction will result in a Error::TxFinished error.

Source

pub async fn cancel(&mut self) -> Result<(), Error>

Cancel a transaction.

This reverses all changes made within the transaction.

Source

pub async fn commit(&mut self) -> Result<(), Error>

Commit a transaction.

This attempts to commit all changes made within the transaction.

Source

pub async fn del<K>(&mut self, key: K) -> Result<(), Error>
where K: Into<Key> + Debug,

Delete a key from the datastore.

Source

pub async fn exi<K>(&mut self, key: K) -> Result<bool, Error>
where K: Into<Key> + Debug,

Check if a key exists in the datastore.

Source

pub async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where K: Into<Key> + Debug,

Fetch a key from the datastore.

Source

pub async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where K: Into<Key> + Debug, V: Into<Val> + Debug,

Insert or update a key in the datastore.

Source

pub async fn get_timestamp<K>( &mut self, key: K, lock: bool, ) -> Result<[u8; 10], Error>
where K: Into<Key> + Debug,

Obtain a new change timestamp for a key which is replaced with the current timestamp when the transaction is committed. NOTE: This should be called when composing the change feed entries for this transaction, which should be done immediately before the transaction commit. That is to keep other transactions commit delay(pessimistic) or conflict(optimistic) as less as possible.

Source

pub async fn set_versionstamped_key<K, V>( &mut self, ts_key: K, prefix: K, suffix: K, val: V, ) -> Result<(), Error>
where K: Into<Key> + Debug, V: Into<Val> + Debug,

Insert or update a key in the datastore.

Source

pub async fn put<K, V>( &mut self, category: KeyCategory, key: K, val: V, ) -> Result<(), Error>
where K: Into<Key> + Debug, V: Into<Val> + Debug,

Insert a key if it doesn’t exist in the datastore.

Source

pub async fn scan<K>( &mut self, rng: Range<K>, limit: u32, ) -> Result<Vec<(Key, Val)>, Error>
where K: Into<Key> + Debug,

Retrieve a specific range of keys from the datastore.

This function fetches the full range of key-value pairs, in a single request to the underlying datastore.

Source

pub async fn putc<K, V>( &mut self, key: K, val: V, chk: Option<V>, ) -> Result<(), Error>
where K: Into<Key> + Debug, V: Into<Val> + Debug,

Update a key in the datastore if the current value matches a condition.

Source

pub async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where K: Into<Key> + Debug, V: Into<Val> + Debug,

Delete a key from the datastore if the current value matches a condition.

Source

pub async fn getr<K>( &mut self, rng: Range<K>, limit: u32, ) -> Result<Vec<(Key, Val)>, Error>
where K: Into<Key> + Debug,

Retrieve a specific range of keys from the datastore.

This function fetches key-value pairs from the underlying datastore in batches of 1000.

Source

pub async fn delr<K>(&mut self, rng: Range<K>, limit: u32) -> Result<(), Error>
where K: Into<Key> + Debug,

Delete a range of keys from the datastore.

This function fetches key-value pairs from the underlying datastore in batches of 1000.

Source

pub async fn getp<K>( &mut self, key: K, limit: u32, ) -> Result<Vec<(Key, Val)>, Error>
where K: Into<Key> + Debug,

Retrieve a specific prefix of keys from the datastore.

This function fetches key-value pairs from the underlying datastore in batches of 1000.

Source

pub async fn delp<K>(&mut self, key: K, limit: u32) -> Result<(), Error>
where K: Into<Key> + Debug,

Delete a prefix of keys from the datastore.

This function fetches key-value pairs from the underlying datastore in batches of 1000.

Source

pub async fn clr<K>(&mut self, key: K) -> Result<(), Error>
where K: Into<Key>,

Clear any cache entry for the specified key.

Source

pub async fn set_nd(&mut self, id: Uuid) -> Result<(), Error>

Source

pub async fn get_nd( &mut self, id: Uuid, ) -> Result<Option<ClusterMembership>, Error>

Source

pub async fn clock(&mut self) -> Timestamp

Clock retrieves the current timestamp, without guaranteeing monotonicity in all implementations.

It is used for unreliable ordering of events as well as handling of timeouts. Operations that are not guaranteed to be correct. But also allows for lexicographical ordering.

Public for tests, but not required for usage from a user perspective.

Source

pub async fn set_hb( &mut self, timestamp: Timestamp, id: Uuid, ) -> Result<(), Error>

Source

pub async fn del_hb( &mut self, timestamp: Timestamp, id: Uuid, ) -> Result<(), Error>

Source

pub async fn del_nd(&mut self, node: Uuid) -> Result<(), Error>

Source

pub async fn del_ndlq( &mut self, nd: Uuid, lq: Uuid, ns: &str, db: &str, ) -> Result<(), Error>

Source

pub async fn scan_hb( &mut self, time_to: &Timestamp, limit: u32, ) -> Result<Vec<Hb>, Error>

Source

pub async fn scan_nd( &mut self, limit: u32, ) -> Result<Vec<ClusterMembership>, Error>

scan_nd will scan all the cluster membership registers setting limit to 0 will result in scanning all entries

Source

pub async fn delr_hb(&mut self, ts: Vec<Hb>, limit: u32) -> Result<(), Error>

Source

pub async fn del_tblq( &mut self, ns: &str, db: &str, tb: &str, lv: Uuid, ) -> Result<(), Error>

Source

pub async fn scan_ndlq<'a>( &mut self, node: &Uuid, limit: u32, ) -> Result<Vec<LqValue>, Error>

Source

pub async fn scan_tblq<'a>( &mut self, ns: &str, db: &str, tb: &str, limit: u32, ) -> Result<Vec<LqValue>, Error>

Source

pub async fn putc_tblq( &mut self, ns: &str, db: &str, tb: &str, live_stm: LiveStatement, expected: Option<LiveStatement>, ) -> Result<(), Error>

Add live query to table

Source

pub async fn putc_ndlq( &mut self, nd: Uuid, lq: Uuid, ns: &str, db: &str, tb: &str, chk: Option<&str>, ) -> Result<(), Error>

Source

pub async fn all_root_users( &mut self, ) -> Result<Arc<[DefineUserStatement]>, Error>

Retrieve all ROOT users.

Source

pub async fn all_ns(&mut self) -> Result<Arc<[DefineNamespaceStatement]>, Error>

Retrieve all namespace definitions in a datastore.

Source

pub async fn all_ns_users( &mut self, ns: &str, ) -> Result<Arc<[DefineUserStatement]>, Error>

Retrieve all namespace user definitions for a specific namespace.

Source

pub async fn all_ns_tokens( &mut self, ns: &str, ) -> Result<Arc<[DefineTokenStatement]>, Error>

Retrieve all namespace token definitions for a specific namespace.

Source

pub async fn all_db( &mut self, ns: &str, ) -> Result<Arc<[DefineDatabaseStatement]>, Error>

Retrieve all database definitions for a specific namespace.

Source

pub async fn all_db_users( &mut self, ns: &str, db: &str, ) -> Result<Arc<[DefineUserStatement]>, Error>

Retrieve all database user definitions for a specific database.

Source

pub async fn all_db_tokens( &mut self, ns: &str, db: &str, ) -> Result<Arc<[DefineTokenStatement]>, Error>

Retrieve all database token definitions for a specific database.

Source

pub async fn all_db_analyzers( &mut self, ns: &str, db: &str, ) -> Result<Arc<[DefineAnalyzerStatement]>, Error>

Retrieve all analyzer definitions for a specific database.

Source

pub async fn all_db_functions( &mut self, ns: &str, db: &str, ) -> Result<Arc<[DefineFunctionStatement]>, Error>

Retrieve all function definitions for a specific database.

Source

pub async fn all_db_params( &mut self, ns: &str, db: &str, ) -> Result<Arc<[DefineParamStatement]>, Error>

Retrieve all param definitions for a specific database.

Source

pub async fn all_sc( &mut self, ns: &str, db: &str, ) -> Result<Arc<[DefineScopeStatement]>, Error>

Retrieve all scope definitions for a specific database.

Source

pub async fn all_sc_tokens( &mut self, ns: &str, db: &str, sc: &str, ) -> Result<Arc<[DefineTokenStatement]>, Error>

Retrieve all scope token definitions for a scope.

Source

pub async fn all_tb( &mut self, ns: &str, db: &str, ) -> Result<Arc<[DefineTableStatement]>, Error>

Retrieve all table definitions for a specific database.

Source

pub async fn all_tb_events( &mut self, ns: &str, db: &str, tb: &str, ) -> Result<Arc<[DefineEventStatement]>, Error>

Retrieve all event definitions for a specific table.

Source

pub async fn all_tb_fields( &mut self, ns: &str, db: &str, tb: &str, ) -> Result<Arc<[DefineFieldStatement]>, Error>

Retrieve all field definitions for a specific table.

Source

pub async fn all_tb_indexes( &mut self, ns: &str, db: &str, tb: &str, ) -> Result<Arc<[DefineIndexStatement]>, Error>

Retrieve all index definitions for a specific table.

Source

pub async fn all_tb_views( &mut self, ns: &str, db: &str, tb: &str, ) -> Result<Arc<[DefineTableStatement]>, Error>

Retrieve all view definitions for a specific table.

Source

pub async fn all_tb_lives( &mut self, ns: &str, db: &str, tb: &str, ) -> Result<Arc<[LiveStatement]>, Error>

Retrieve all live definitions for a specific table.

Source

pub async fn all_lq(&mut self, nd: &Uuid) -> Result<Vec<LqValue>, Error>

Source

pub async fn get_root_user( &mut self, user: &str, ) -> Result<DefineUserStatement, Error>

Retrieve a specific user definition from ROOT.

Source

pub async fn get_ns( &mut self, ns: &str, ) -> Result<DefineNamespaceStatement, Error>

Retrieve a specific namespace definition.

Source

pub async fn get_ns_user( &mut self, ns: &str, user: &str, ) -> Result<DefineUserStatement, Error>

Retrieve a specific user definition from a namespace.

Source

pub async fn get_ns_token( &mut self, ns: &str, nt: &str, ) -> Result<DefineTokenStatement, Error>

Retrieve a specific namespace token definition.

Source

pub async fn get_db( &mut self, ns: &str, db: &str, ) -> Result<DefineDatabaseStatement, Error>

Retrieve a specific database definition.

Source

pub async fn get_db_user( &mut self, ns: &str, db: &str, user: &str, ) -> Result<DefineUserStatement, Error>

Retrieve a specific user definition from a database.

Source

pub async fn get_db_token( &mut self, ns: &str, db: &str, dt: &str, ) -> Result<DefineTokenStatement, Error>

Retrieve a specific database token definition.

Source

pub async fn get_db_analyzer( &mut self, ns: &str, db: &str, az: &str, ) -> Result<DefineAnalyzerStatement, Error>

Retrieve a specific analyzer definition.

Source

pub async fn get_sc( &mut self, ns: &str, db: &str, sc: &str, ) -> Result<DefineScopeStatement, Error>

Retrieve a specific scope definition.

Source

pub async fn get_sc_token( &mut self, ns: &str, db: &str, sc: &str, st: &str, ) -> Result<DefineTokenStatement, Error>

Retrieve a specific scope token definition.

Source

pub async fn get_lq( &mut self, nd: Uuid, ns: &str, db: &str, lq: Uuid, ) -> Result<Strand, Error>

Return the table stored at the lq address

Source

pub async fn get_tb( &mut self, ns: &str, db: &str, tb: &str, ) -> Result<DefineTableStatement, Error>

Retrieve a specific table definition.

Source

pub async fn get_tb_live( &mut self, ns: &str, db: &str, tb: &str, lv: &Uuid, ) -> Result<LiveStatement, Error>

Retrieve a live query for a table.

Source

pub async fn add_ns( &mut self, ns: &str, strict: bool, ) -> Result<DefineNamespaceStatement, Error>

Add a namespace with a default configuration, only if we are in dynamic mode.

Source

pub async fn add_db( &mut self, ns: &str, db: &str, strict: bool, ) -> Result<DefineDatabaseStatement, Error>

Add a database with a default configuration, only if we are in dynamic mode.

Source

pub async fn add_sc( &mut self, ns: &str, db: &str, sc: &str, strict: bool, ) -> Result<DefineScopeStatement, Error>

Add a scope with a default configuration, only if we are in dynamic mode.

Source

pub async fn add_tb( &mut self, ns: &str, db: &str, tb: &str, strict: bool, ) -> Result<DefineTableStatement, Error>

Add a table with a default configuration, only if we are in dynamic mode.

Source

pub async fn get_and_cache_ns( &mut self, ns: &str, ) -> Result<Arc<DefineNamespaceStatement>, Error>

Retrieve and cache a specific namespace definition.

Source

pub async fn get_and_cache_db( &mut self, ns: &str, db: &str, ) -> Result<Arc<DefineDatabaseStatement>, Error>

Retrieve and cache a specific database definition.

Source

pub async fn get_and_cache_tb( &mut self, ns: &str, db: &str, tb: &str, ) -> Result<Arc<DefineTableStatement>, Error>

Retrieve and cache a specific table definition.

Source

pub async fn get_and_cache_db_function( &mut self, ns: &str, db: &str, fc: &str, ) -> Result<Arc<DefineFunctionStatement>, Error>

Retrieve a specific function definition.

Source

pub async fn get_and_cache_db_param( &mut self, ns: &str, db: &str, pa: &str, ) -> Result<Arc<DefineParamStatement>, Error>

Retrieve a specific param definition.

Source

pub async fn get_and_cache_tb_index( &mut self, ns: &str, db: &str, tb: &str, ix: &str, ) -> Result<Arc<DefineIndexStatement>, Error>

Retrieve a specific table index definition.

Source

pub async fn add_and_cache_ns( &mut self, ns: &str, strict: bool, ) -> Result<Arc<DefineNamespaceStatement>, Error>

Add a namespace with a default configuration, only if we are in dynamic mode.

Source

pub async fn add_and_cache_db( &mut self, ns: &str, db: &str, strict: bool, ) -> Result<Arc<DefineDatabaseStatement>, Error>

Add a database with a default configuration, only if we are in dynamic mode.

Source

pub async fn add_and_cache_tb( &mut self, ns: &str, db: &str, tb: &str, strict: bool, ) -> Result<Arc<DefineTableStatement>, Error>

Add a table with a default configuration, only if we are in dynamic mode.

Source

pub async fn check_ns_db_tb( &mut self, ns: &str, db: &str, tb: &str, strict: bool, ) -> Result<(), Error>

Retrieve and cache a specific table definition.

Source

pub async fn export( &mut self, ns: &str, db: &str, chn: Sender<Vec<u8>>, ) -> Result<(), Error>

Writes the full database contents as binary SQL.

Trait Implementations§

Source§

impl Display for Transaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T