Skip to content

Commit

Permalink
book: Add a note about Session::prepare_batch
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Ciolek <[email protected]>
  • Loading branch information
cvybhu committed Sep 6, 2022
1 parent 677db1c commit bb658b8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/source/queries/batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ session.batch(&batch, batch_values).await?;
# }
```

### Preparing a batch
Instead of preparing each query individually, it's possible to prepare a whole batch at once:

```rust
# extern crate scylla;
# use scylla::Session;
# use std::error::Error;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
use scylla::batch::Batch;

// Create a batch statement with unprepared statements
let mut batch: Batch = Default::default();
batch.append_statement("INSERT INTO ks.simple_unprepared1 VALUES(?, ?)");
batch.append_statement("INSERT INTO ks.simple_unprepared2 VALUES(?, ?)");

// Prepare all statements in the batch at once
let prepared_batch: Batch = session.prepare_batch(&batch).await?;

// Specify bound values to use with each query
let batch_values = ((1_i32, 2_i32),
(3_i32, 4_i32));

// Run the prepared batch
session.batch(&prepared_batch, batch_values).await?;
# Ok(())
# }
```

### Batch options
You can set various options by operating on the `Batch` object.\
For example to change consistency:
Expand Down

0 comments on commit bb658b8

Please sign in to comment.