pub trait TransactionContext: ReadContext {
    fn execute_update<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 mut self,
        statement: &'life1 str,
        parameters: &'life2 [(&'life3 str, &'life4 (dyn ToSpanner + Sync))]
    ) -> Pin<Box<dyn Future<Output = Result<i64, Error>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        'life4: 'async_trait,
        Self: 'async_trait
; fn execute_updates<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        statements: &'life1 [&'life2 Statement<'_>]
    ) -> Pin<Box<dyn Future<Output = Result<Vec<i64>, Error>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; }
Expand description

Defines the interface to read from and write into Cloud Spanner.

This extends ReadContext to provide additional write functionalities.

Required Methods

Execute a DML SQL statement and returns the number of affected rows.

Parameters

Like its [ReadContext::execute_sql] counterpart, this function also supports query parameters.

Example
let id = 42;
let name = "ferris";
let rows = client
    .read_write()
    .run(|tx| {
        Box::pin(async move {
            tx.execute_update(
                "INSERT INTO person(id, name) VALUES (@id, @name)",
                &[("id", &id), ("name", &name)],
            )
            .await
        })
    })
    .await?;

println!("Inserted {} row", rows);

Execute a batch of DML SQL statements and returns the number of affected rows for each statement.

Statements

Each DML statement has its own SQL statement and parameters. See Statement for more details.

Example
let id = 42;
let name = "ferris";
let new_name = "ferris";
let rows = client
    .read_write()
    .run(|tx| {
        Box::pin(async move {
            tx.execute_updates(&[
                &Statement {
                    sql: "INSERT INTO person(id, name) VALUES (@id, @name)",
                    params: &[("id", &id), ("name", &name)],
                },
                &Statement {
                    sql: "UPDATE person SET name = @name WHERE id = 42",
                    params: &[("name", &new_name)],
                },
            ])
            .await
        })
    })
    .await?;

// each statement modified a single row
assert_eq!(rows, vec![1, 1]);

Implementors