Struct google_cloud_spanner::client::Client [−][src]
pub struct Client { /* fields omitted */ }Expand description
Client is a client for reading and writing data to a Cloud Spanner database. A client is safe to use concurrently, except for its Close method.
Implementations
new creates a client to a database. A valid database name has the form projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID.
pub async fn new_with_config(
database: impl Into<String>,
config: ClientConfig
) -> Result<Self, InitializationError>
pub async fn new_with_config(
database: impl Into<String>,
config: ClientConfig
) -> Result<Self, InitializationError>
new creates a client to a database. A valid database name has the form projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID.
single provides a read-only snapshot transaction optimized for the case where only a single read or query is needed. This is more efficient than using read_only_transaction for a single read or query.
pub async fn single_with_timestamp_bound(
&self,
tb: TimestampBound
) -> Result<ReadOnlyTransaction, TxError>
pub async fn single_with_timestamp_bound(
&self,
tb: TimestampBound
) -> Result<ReadOnlyTransaction, TxError>
single provides a read-only snapshot transaction optimized for the case where only a single read or query is needed. This is more efficient than using read_only_transaction for a single read or query.
read_only_transaction returns a ReadOnlyTransaction that can be used for multiple reads from the database.
pub async fn read_only_transaction_with_option(
&self,
options: ReadOnlyTransactionOption
) -> Result<ReadOnlyTransaction, TxError>
pub async fn read_only_transaction_with_option(
&self,
options: ReadOnlyTransactionOption
) -> Result<ReadOnlyTransaction, TxError>
read_only_transaction returns a ReadOnlyTransaction that can be used for multiple reads from the database.
batch_read_only_transaction returns a BatchReadOnlyTransaction that can be used for partitioned reads or queries from a snapshot of the database. This is useful in batch processing pipelines where one wants to divide the work of reading from the database across multiple machines.
pub async fn batch_read_only_transaction_with_option(
&self,
options: ReadOnlyTransactionOption
) -> Result<BatchReadOnlyTransaction, TxError>
pub async fn batch_read_only_transaction_with_option(
&self,
options: ReadOnlyTransactionOption
) -> Result<BatchReadOnlyTransaction, TxError>
batch_read_only_transaction returns a BatchReadOnlyTransaction that can be used for partitioned reads or queries from a snapshot of the database. This is useful in batch processing pipelines where one wants to divide the work of reading from the database across multiple machines.
partitioned_update executes a DML statement in parallel across the database, using separate, internal transactions that commit independently. The DML statement must be fully partitionable: it must be expressible as the union of many statements each of which accesses only a single row of the table. The statement should also be idempotent, because it may be applied more than once.
PartitionedUpdate returns an estimated count of the number of rows affected. The actual number of affected rows may be greater than the estimate.
pub async fn partitioned_update_with_option(
&self,
stmt: Statement,
options: PartitionedUpdateOption
) -> Result<i64, TxError>
pub async fn partitioned_update_with_option(
&self,
stmt: Statement,
options: PartitionedUpdateOption
) -> Result<i64, TxError>
partitioned_update executes a DML statement in parallel across the database, using separate, internal transactions that commit independently. The DML statement must be fully partitionable: it must be expressible as the union of many statements each of which accesses only a single row of the table. The statement should also be idempotent, because it may be applied more than once.
PartitionedUpdate returns an estimated count of the number of rows affected. The actual number of affected rows may be greater than the estimate.
apply_at_least_once may attempt to apply mutations more than once; if the mutations are not idempotent, this may lead to a failure being reported when the mutation was applied more than once. For example, an insert may fail with ALREADY_EXISTS even though the row did not exist before Apply was called. For this reason, most users of the library will prefer not to use this option. However, apply_at_least_once requires only a single RPC, whereas apply’s default replay protection may require an additional RPC. So this method may be appropriate for latency sensitive and/or high throughput blind writing.
pub async fn apply_at_least_once_with_option(
&self,
ms: Vec<Mutation>,
options: CommitOptions
) -> Result<Option<Timestamp>, TxError>
pub async fn apply_at_least_once_with_option(
&self,
ms: Vec<Mutation>,
options: CommitOptions
) -> Result<Option<Timestamp>, TxError>
apply_at_least_once may attempt to apply mutations more than once; if the mutations are not idempotent, this may lead to a failure being reported when the mutation was applied more than once. For example, an insert may fail with ALREADY_EXISTS even though the row did not exist before Apply was called. For this reason, most users of the library will prefer not to use this option. However, apply_at_least_once requires only a single RPC, whereas apply’s default replay protection may require an additional RPC. So this method may be appropriate for latency sensitive and/or high throughput blind writing.
Apply applies a list of mutations atomically to the database.
pub async fn apply_with_option(
&self,
ms: Vec<Mutation>,
options: ReadWriteTransactionOption
) -> Result<Option<Timestamp>, TxError>
ReadWriteTransaction executes a read-write transaction, with retries as necessary.
The function f will be called one or more times. It must not maintain any state between calls.
If the transaction cannot be committed or if f returns an ABORTED error, ReadWriteTransaction will call f again. It will continue to call f until the transaction can be committed or the Context times out or is cancelled. If f returns an error other than ABORTED, ReadWriteTransaction will abort the transaction and return the error.
To limit the number of retries, set a deadline on the Context rather than using a fixed limit on the number of attempts. ReadWriteTransaction will retry as needed until that deadline is met.
See https://godoc.org/cloud.google.com/go/spanner#ReadWriteTransaction for more details.
pub async fn read_write_transaction_with_option<'a, T, E, F>(
&'a self,
f: F,
options: ReadWriteTransactionOption
) -> Result<(Option<Timestamp>, T), E> where
E: TryAs<Status> + From<SessionError> + From<Status>,
F: for<'tx> Fn(&'tx mut ReadWriteTransaction) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'tx>>,
pub async fn read_write_transaction_with_option<'a, T, E, F>(
&'a self,
f: F,
options: ReadWriteTransactionOption
) -> Result<(Option<Timestamp>, T), E> where
E: TryAs<Status> + From<SessionError> + From<Status>,
F: for<'tx> Fn(&'tx mut ReadWriteTransaction) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'tx>>,
ReadWriteTransaction executes a read-write transaction, with retries as necessary.
The function f will be called one or more times. It must not maintain any state between calls.
If the transaction cannot be committed or if f returns an ABORTED error, ReadWriteTransaction will call f again. It will continue to call f until the transaction can be committed or the Context times out or is cancelled. If f returns an error other than ABORTED, ReadWriteTransaction will abort the transaction and return the error.
To limit the number of retries, set a deadline on the Context rather than using a fixed limit on the number of attempts. ReadWriteTransaction will retry as needed until that deadline is met.
See https://godoc.org/cloud.google.com/go/spanner#ReadWriteTransaction for more details.
Get open session count.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
Blanket Implementations
Mutably borrows from an owned value. Read more
Wrap the input message T in a tonic::Request
pub fn vzip(self) -> V
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more
