Skip to content

Commit 8979702

Browse files
committed
expose creation of BoundBatch
it implements Default same as `Batch`, and it also allows for override of the batch_type same as `Batch`
1 parent 80308b5 commit 8979702

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

scylla/src/statement/batch.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'a: 'b, 'b> From<&'a BatchStatement>
277277
}
278278

279279
/// A batch with all of its statements bound to values
280-
pub(crate) struct BoundBatch {
280+
pub struct BoundBatch {
281281
pub(crate) config: StatementConfig,
282282
batch_type: BatchType,
283283
pub(crate) buffer: Vec<u8>,
@@ -287,6 +287,13 @@ pub(crate) struct BoundBatch {
287287
}
288288

289289
impl BoundBatch {
290+
pub fn new(batch_type: BatchType) -> Self {
291+
Self {
292+
batch_type,
293+
..Default::default()
294+
}
295+
}
296+
290297
#[allow(clippy::result_large_err)]
291298
pub(crate) fn from_batch(
292299
batch: &Batch,
@@ -295,14 +302,12 @@ impl BoundBatch {
295302
let mut bound_batch = BoundBatch {
296303
config: batch.config.clone(),
297304
batch_type: batch.batch_type,
298-
prepared: HashMap::new(),
299-
buffer: vec![],
300-
first_prepared: None,
301305
statements_len: batch.statements.len().try_into().map_err(|_| {
302306
ExecutionError::BadQuery(BadQuery::TooManyQueriesInBatchStatement(
303307
batch.statements.len(),
304308
))
305309
})?,
310+
..Default::default()
306311
};
307312

308313
let mut values = values.batch_values_iter();
@@ -384,17 +389,17 @@ impl BoundBatch {
384389
}
385390

386391
/// Borrows the execution profile handle associated with this batch.
387-
pub(crate) fn get_execution_profile_handle(&self) -> Option<&ExecutionProfileHandle> {
392+
pub fn get_execution_profile_handle(&self) -> Option<&ExecutionProfileHandle> {
388393
self.config.execution_profile_handle.as_ref()
389394
}
390395

391396
/// Gets the default timestamp for this batch in microseconds.
392-
pub(crate) fn get_timestamp(&self) -> Option<i64> {
397+
pub fn get_timestamp(&self) -> Option<i64> {
393398
self.config.timestamp
394399
}
395400

396401
/// Gets type of batch.
397-
pub(crate) fn get_type(&self) -> BatchType {
402+
pub fn get_type(&self) -> BatchType {
398403
self.batch_type
399404
}
400405

@@ -453,6 +458,19 @@ fn serialize_statement<T>(
453458
Ok(Some(res))
454459
}
455460

461+
impl Default for BoundBatch {
462+
fn default() -> Self {
463+
Self {
464+
config: StatementConfig::default(),
465+
batch_type: BatchType::Logged,
466+
buffer: Vec::new(),
467+
prepared: HashMap::new(),
468+
first_prepared: None,
469+
statements_len: 0,
470+
}
471+
}
472+
}
473+
456474
fn counts_mismatch_err(n_value_lists: usize, n_statements: u16) -> BatchSerializationError {
457475
BatchSerializationError::ValuesAndStatementsLengthMismatch {
458476
n_value_lists,

0 commit comments

Comments
 (0)