TableClient

Struct TableClient 

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

Client for YDB table service (SQL queries)

Table service used for work with data abd DB struct with SQL queries.

TableClient contains options for make queries. See TableClient::retry_transaction for examples.

Implementations§

Source§

impl TableClient

Source

pub fn clone_with_timeouts(&self, timeouts: TimeoutSettings) -> Self

Source

pub fn clone_with_retry_timeout(&self, timeout: Duration) -> Self

Clone the table client and set new retry timeouts

Source

pub fn clone_with_no_retry(&self) -> Self

Clone the table client and deny retries

Source

pub fn clone_with_idempotent_operations(&self, idempotent: bool) -> Self

Clone the table client and set feature operations as idempotent (can retry in more cases)

Source

pub fn clone_with_transaction_options(&self, opts: TransactionOptions) -> Self

Source

pub async fn retry_execute_scan_query( &self, query: Query, ) -> YdbResult<StreamResult>

Execute scan query. The method will auto-retry errors while start query execution, but no retries after server start streaming result.

Source

pub async fn retry_execute_scheme_query<T: Into<String>>( &self, query: T, ) -> YdbResult<()>

Execute scheme query with retry policy

Source

pub async fn retry_execute_bulk_upsert( &self, table_path: String, rows: Vec<Value>, ) -> YdbResult<()>

Execute bulk upsert with retry policy

Source

pub async fn retry_transaction<CallbackFuture, CallbackResult>( &self, callback: impl Fn(Box<dyn Transaction>) -> CallbackFuture, ) -> YdbResultWithCustomerErr<CallbackResult>
where CallbackFuture: Future<Output = YdbResultWithCustomerErr<CallbackResult>>,

Retry callback in transaction

retries callback as retry policy. every call of callback will within new transaction retry will call callback next time if:

  1. allow by retry policy
  2. callback return retriable error

Example with move lambda args:

    let res: Option<i32> = table_client.retry_transaction(|mut t| async move {
        let value: Value = t.query(Query::new("SELECT 1 + 1 as sum")).await?
            .into_only_row()?
            .remove_field_by_name("sum")?;
        let res: Option<i32> = value.try_into()?;
        return Ok(res);
    }).await?;
    assert_eq!(Some(2), res);

Example without move lambda args - it allow to borrow external items:

    let mut attempts: AtomicUsize = AtomicUsize::new(0);
    let res: Option<i32> = table_client.retry_transaction(|mut t| async {
        let mut t = t; // explicit move lambda argument inside async code block for borrow checker
        attempts.fetch_add(1, Ordering::Relaxed); // can borrow outer values istead of move
        let value: Value = t.query(Query::new("SELECT 1 + 1 as sum")).await?
            .into_only_row()?
            .remove_field_by_name("sum")?;
        let res: Option<i32> = value.try_into()?;
        return Ok(res);
    }).await?;
    assert_eq!(Some(2), res);
    assert_eq!(1, attempts.load(Ordering::Relaxed));
Source

pub fn with_error_on_truncate(self, error_on_truncate: bool) -> Self

Source

pub async fn copy_table( &self, source_path: String, destination_path: String, ) -> YdbResult<()>

Source

pub async fn copy_tables(&self, tables: Vec<CopyTableItem>) -> YdbResult<()>

Trait Implementations§

Source§

impl Clone for TableClient

Source§

fn clone(&self) -> TableClient

Returns a duplicate of the value. Read more
1.0.0 · 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> Any for T
where T: Any + ?Sized,

Source§

fn type_id_compat(&self) -> TypeId

TODO: once 1.33.0 is the minimum supported compiler version, remove Any::type_id_compat and use StdAny::type_id instead. https://github.com/rust-lang/rust/issues/27745
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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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
Source§

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