11# Batch statement
22
3- A batch statement allows to run many queries at once.\
4- These queries can be [ simple queries ] ( simple.md ) or [ prepared queries ] ( prepared.md ) .\
5- Only queries like ` INSERT ` or ` UPDATE ` can be in a batch .
3+ A batch statement allows to execute many data-modifying statements at once.\
4+ These statements can be [ simple] ( simple.md ) or [ prepared] ( prepared.md ) .\
5+ Only ` INSERT ` , ` UPDATE ` and ` DELETE ` statements are allowed .
66
77``` rust
88# extern crate scylla;
@@ -16,20 +16,20 @@ use scylla::prepared_statement::PreparedStatement;
1616// Create a batch statement
1717let mut batch : Batch = Default :: default ();
1818
19- // Add a simple query to the batch using its text
19+ // Add a simple statement to the batch using its text
2020batch . append_statement (" INSERT INTO ks.tab(a, b) VALUES(?, ?)" );
2121
22- // Add a simple query created manually to the batch
22+ // Add a simple statement created manually to the batch
2323let simple : Query = Query :: new (" INSERT INTO ks.tab (a, b) VALUES(3, 4)" );
2424batch . append_statement (simple );
2525
26- // Add a prepared query to the batch
26+ // Add a prepared statement to the batch
2727let prepared : PreparedStatement = session
2828 . prepare (" INSERT INTO ks.tab (a, b) VALUES(?, 6)" )
2929 . await ? ;
3030batch . append_statement (prepared );
3131
32- // Specify bound values to use with each query
32+ // Specify bound values to use with each statement
3333let batch_values = ((1_i32 , 2_i32 ),
3434 (),
3535 (5_i32 ,));
@@ -41,7 +41,7 @@ session.batch(&batch, batch_values).await?;
4141```
4242
4343### Preparing a batch
44- Instead of preparing each query individually, it's possible to prepare a whole batch at once:
44+ Instead of preparing each statement individually, it's possible to prepare a whole batch at once:
4545
4646``` rust
4747# extern crate scylla;
@@ -58,7 +58,7 @@ batch.append_statement("INSERT INTO ks.simple_unprepared2 VALUES(?, ?)");
5858// Prepare all statements in the batch at once
5959let prepared_batch : Batch = session . prepare_batch (& batch ). await ? ;
6060
61- // Specify bound values to use with each query
61+ // Specify bound values to use with each statement
6262let batch_values = ((1_i32 , 2_i32 ),
6363 (3_i32 , 4_i32 ));
6464
@@ -99,10 +99,10 @@ for more options
9999Batch takes a tuple of values specified just like in [ simple] ( simple.md ) or [ prepared] ( prepared.md ) queries.
100100
101101Length of batch values must be equal to the number of statements in a batch.\
102- Each query must have its values specified, even if they are empty.
102+ Each statement must have its values specified, even if they are empty.
103103
104104Values passed to ` Session::batch ` must implement the trait ` BatchValues ` .\
105- By default this includes tuples ` () ` and slices ` &[] ` of tuples and slices which implement ` ValueList ` .\
105+ By default this includes tuples ` () ` and slices ` &[] ` of tuples and slices which implement ` ValueList ` .
106106
107107Example:
108108``` rust
@@ -114,26 +114,26 @@ use scylla::batch::Batch;
114114
115115let mut batch : Batch = Default :: default ();
116116
117- // A query with two bound values
117+ // A statement with two bound values
118118batch . append_statement (" INSERT INTO ks.tab(a, b) VALUES(?, ?)" );
119119
120- // A query with one bound value
120+ // A statement with one bound value
121121batch . append_statement (" INSERT INTO ks.tab(a, b) VALUES(3, ?)" );
122122
123- // A query with no bound values
123+ // A statement with no bound values
124124batch . append_statement (" INSERT INTO ks.tab(a, b) VALUES(5, 6)" );
125125
126- // Batch values is a tuple of 3 tuples containing values for each query
127- let batch_values = ((1_i32 , 2_i32 ), // Tuple with two values for the first query
128- (4_i32 ,), // Tuple with one value for the second query
129- ()); // Empty tuple/unit for the third query
126+ // Batch values is a tuple of 3 tuples containing values for each statement
127+ let batch_values = ((1_i32 , 2_i32 ), // Tuple with two values for the first statement
128+ (4_i32 ,), // Tuple with one value for the second statement
129+ ()); // Empty tuple/unit for the third statement
130130
131131// Run the batch
132132session . batch (& batch , batch_values ). await ? ;
133133# Ok (())
134134# }
135135```
136- For more information about sending values in a query see [ Query values] ( values.md )
136+ For more information about sending values in a statement see [ Query values] ( values.md )
137137
138138
139139### Performance
0 commit comments