pub struct SingleUseReadOnlyTransaction { /* private fields */ }Expand description
A single-use read-only transaction. A single-use read-only transaction is the most efficient way to execute a single query or read operation.
§Example
let db_client = spanner.database_client("projects/p/instances/i/databases/d").build().await?;
let tx = db_client.single_use().build();
let stmt = Statement::builder("SELECT * FROM users WHERE id = @id")
.add_param("id", &42)
.build();
let rs = tx.execute_query(stmt).await?;Implementations§
Source§impl SingleUseReadOnlyTransaction
impl SingleUseReadOnlyTransaction
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.
§Example
let db_client = spanner.database_client("projects/p/instances/i/databases/d").build().await?;
let tx = db_client.single_use().build();
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.single_use().build();
// 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 SingleUseReadOnlyTransaction
impl !RefUnwindSafe for SingleUseReadOnlyTransaction
impl !UnwindSafe for SingleUseReadOnlyTransaction
impl Send for SingleUseReadOnlyTransaction
impl Sync for SingleUseReadOnlyTransaction
impl Unpin for SingleUseReadOnlyTransaction
impl UnsafeUnpin for SingleUseReadOnlyTransaction
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