Skip to content

Commit

Permalink
review feedback, use prepared statements
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelorji committed Oct 17, 2023
1 parent b35346b commit aa43b64
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions scylla/src/transport/large_batch_statements_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ async fn test_large_batch_statements() {
async fn create_test_session(session: Session, ks: &String) -> Session {
session
.query(
format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1 }}",ks),
format!("CREATE KEYSPACE {} WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1 }}",ks),
&[],
)
.await.unwrap();
session
.query(format!("DROP TABLE IF EXISTS {}.pairs;", ks), &[])
.await
.unwrap();
session
.query(
format!("CREATE TABLE IF NOT EXISTS {}.pairs (dummy int, k blob, v blob, primary key (dummy, k))", ks),
format!("CREATE TABLE {}.pairs (dummy int, k blob, v blob, primary key (dummy, k))", ks),
&[],
)
.await.unwrap();
Expand All @@ -53,15 +49,16 @@ async fn create_test_session(session: Session, ks: &String) -> Session {
async fn write_batch(session: &Session, n: usize, ks: &String) -> Result<QueryResult, QueryError> {
let mut batch_query = Batch::new(BatchType::Unlogged);
let mut batch_values = Vec::new();
let query = format!("INSERT INTO {}.pairs (dummy, k, v) VALUES (0, ?, ?)", ks);
let query = Query::new(query);
let prepared_statement = session.prepare(query).await.unwrap();
for i in 0..n {
let mut key = vec![0];
key.extend(i.to_be_bytes().as_slice());
let value = key.clone();
let query = format!("INSERT INTO {}.pairs (dummy, k, v) VALUES (0, ?, ?)", ks);
let values = vec![key, value];
batch_values.push(values);
let query = Query::new(query);
batch_query.append_statement(query);
batch_query.append_statement(prepared_statement.clone());
}
session.batch(&batch_query, batch_values).await
}

0 comments on commit aa43b64

Please sign in to comment.