QldbClient

Struct QldbClient 

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

It allows to start transactions. In QLDB all queries are transactions. So you always need to create a transaction for every query.

The recommended method is transaction_within.

Implementations§

Source§

impl QldbClient

Source

pub async fn default( ledger_name: &str, max_sessions: u16, ) -> QldbResult<QldbClient>

Creates a new QldbClient.

It will spawn one thread for the session pool.

This function will take the credentials from several locations in this order:

  • Environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
  • credential_process command in the AWS config file, usually located at ~/.aws/config.
  • AWS credentials file. Usually located at ~/.aws/credentials.
  • IAM instance profile. Will only work if running on an EC2 instance with an instance profile/role.

https://docs.rs/rusoto_credential/0.45.0/rusoto_credential/struct.ChainProvider.html

For the region it will will attempt to read the AWS_DEFAULT_REGION or AWS_REGION environment variable. If it is malformed, it will fall back to Region::UsEast1. If it is not present it will fallback on the value associated with the current profile in ~/.aws/config or the file specified by the AWS_CONFIG_FILE environment variable. If that is malformed of absent it will fall back on Region::UsEast1

Source

pub async fn default_with_spawner( ledger_name: &str, max_sessions: u16, spawner: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>, ) -> QldbResult<QldbClient>

Creates a new QldbClient.

This function won’t spawn a thread for the session pool, but it will require to be given an spawn function so it can start 2 green threads for the session pool.

This function will take the credentials from several locations in this order:

  • Environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
  • credential_process command in the AWS config file, usually located at ~/.aws/config.
  • AWS credentials file. Usually located at ~/.aws/credentials.
  • IAM instance profile. Will only work if running on an EC2 instance with an instance profile/role.

https://docs.rs/rusoto_credential/0.45.0/rusoto_credential/struct.ChainProvider.html

For the region it will will attempt to read the AWS_DEFAULT_REGION or AWS_REGION environment variable. If it is malformed, it will fall back to Region::UsEast1. If it is not present it will fallback on the value associated with the current profile in ~/.aws/config or the file specified by the AWS_CONFIG_FILE environment variable. If that is malformed of absent it will fall back on Region::UsEast1

Source

pub async fn read_query(&self, statement: &str) -> QldbResult<QueryBuilder>

Shorthand method that creates a transaction and executes a query. Currently it doesn’t filter by statements, so any statement can be sent but it won’t have effect as it will rollback any change. This allows to read big quantities of data without failing other transactions that may be reading that data at the same time.

This is a good option when you want to execute an isolated non-ACID SELECT/COUNT statement.

Source

pub async fn transaction(&self) -> QldbResult<Transaction>

Starts a transaction and returns you the transaction handler. When using this method the transaction won’t automatically commit or rollback when finished. If they are left open they will be canceled when the transaction times out on the DB side (30 seconds).

Use this method if you really need to use the transaction handler directly. If not, you may be better off using the method transaction_within.

Source

pub async fn close(&mut self)

It closes the session pool. Current transaction which already have a session can work as normal, but new transaction (requiring a new session id) will return error.

Call this method only when you are sure that all important work is already commited to QLDB.

Source

pub async fn transaction_within<F, R, FR>(&self, clousure: F) -> QldbResult<R>
where R: Debug, FR: Future<Output = QldbResult<R>>, F: FnOnce(Transaction) -> FR,

It call the closure providing an already made transaction. Once the closure finishes it will call commit or rollback if any error.

Trait Implementations§

Source§

impl Clone for QldbClient

Source§

fn clone(&self) -> QldbClient

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> 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> CompatExt for T

Source§

fn compat(self) -> Compat<T>

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. 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> 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<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