pub struct MultiUseReadOnlyTransaction { /* private fields */ }Expand description
A multi-use read-only transaction. This transaction can be used for multiple read queries ensuring consistency across all queries.
§Example
let db_client = spanner.database_client("projects/p/instances/i/databases/d").build().await?;
let tx = db_client.read_only_transaction().build().await?;
let stmt1 = Statement::builder("SELECT * FROM users WHERE id = @id")
.add_param("id", &42)
.build();
let mut rs1 = tx.execute_query(stmt1).await?;
let stmt2 = Statement::builder("SELECT * FROM other_table")
.build();
let mut rs2 = tx.execute_query(stmt2).await?;Implementations§
Source§impl MultiUseReadOnlyTransaction
impl MultiUseReadOnlyTransaction
Sourcepub fn read_timestamp(&self) -> Option<Timestamp>
pub fn read_timestamp(&self) -> Option<Timestamp>
Returns the read timestamp chosen for the transaction.
Sourcepub async fn execute_query<T: Into<Statement>>(
&self,
statement: T,
) -> Result<ResultSet>
pub async fn execute_query<T: Into<Statement>>( &self, statement: T, ) -> Result<ResultSet>
Executes a query using this transaction.
§Example
let db_client = spanner.database_client("projects/p/instances/i/databases/d").build().await?;
let tx = db_client.read_only_transaction().build().await?;
let stmt = Statement::builder("SELECT * FROM users WHERE id = @id")
.add_param("id", &42)
.build();
let mut rs = tx.execute_query(stmt).await?;
while let Some(row) = rs.next().await {
let _row = row?;
// process row
}Sourcepub async fn execute_read<T: Into<ReadRequest>>(
&self,
read: T,
) -> Result<ResultSet>
pub async fn execute_read<T: Into<ReadRequest>>( &self, read: T, ) -> Result<ResultSet>
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to execute_query.
§Example
let db_client = spanner.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = db_client.read_only_transaction().build().await?;
// Read using the primary key
let read_by_pk = ReadRequest::builder("Users", vec!["Id", "Name"]).with_keys(KeySet::all()).build();
let mut result_set = transaction.execute_read(read_by_pk).await?;
while let Some(row) = result_set.next().await {
let _row = row?;
// process row
}
// Read using a secondary index
let read_by_index = ReadRequest::builder("Users", vec!["Id", "Name"])
.with_index("UsersByIndex", key![1_i64]).build();
let mut result_set = transaction.execute_read(read_by_index).await?;
while let Some(row) = result_set.next().await {
let _row = row?;
// process row
}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for MultiUseReadOnlyTransaction
impl !RefUnwindSafe for MultiUseReadOnlyTransaction
impl !UnwindSafe for MultiUseReadOnlyTransaction
impl Send for MultiUseReadOnlyTransaction
impl Sync for MultiUseReadOnlyTransaction
impl Unpin for MultiUseReadOnlyTransaction
impl UnsafeUnpin for MultiUseReadOnlyTransaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request