Skip to content

Commit 3cfdf5b

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 1aaadba commit 3cfdf5b

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
@@ -249,7 +249,7 @@ impl<'a: 'b, 'b> From<&'a BatchStatement>
249249
}
250250

251251
/// A batch with all of its statements bound to values
252-
pub(crate) struct BoundBatch {
252+
pub struct BoundBatch {
253253
pub(crate) config: StatementConfig,
254254
batch_type: BatchType,
255255
pub(crate) buffer: Vec<u8>,
@@ -259,21 +259,26 @@ pub(crate) struct BoundBatch {
259259
}
260260

261261
impl BoundBatch {
262+
pub fn new(batch_type: BatchType) -> Self {
263+
Self {
264+
batch_type,
265+
..Default::default()
266+
}
267+
}
268+
262269
pub(crate) fn from_batch(
263270
batch: &Batch,
264271
values: impl BatchValues,
265272
) -> Result<Self, ExecutionError> {
266273
let mut bound_batch = BoundBatch {
267274
config: batch.config.clone(),
268275
batch_type: batch.batch_type,
269-
prepared: HashMap::new(),
270-
buffer: vec![],
271-
first_prepared: None,
272276
statements_len: batch.statements.len().try_into().map_err(|_| {
273277
ExecutionError::BadQuery(BadQuery::TooManyQueriesInBatchStatement(
274278
batch.statements.len(),
275279
))
276280
})?,
281+
..Default::default()
277282
};
278283

279284
let mut values = values.batch_values_iter();
@@ -355,17 +360,17 @@ impl BoundBatch {
355360
}
356361

357362
/// Borrows the execution profile handle associated with this batch.
358-
pub(crate) fn get_execution_profile_handle(&self) -> Option<&ExecutionProfileHandle> {
363+
pub fn get_execution_profile_handle(&self) -> Option<&ExecutionProfileHandle> {
359364
self.config.execution_profile_handle.as_ref()
360365
}
361366

362367
/// Gets the default timestamp for this batch in microseconds.
363-
pub(crate) fn get_timestamp(&self) -> Option<i64> {
368+
pub fn get_timestamp(&self) -> Option<i64> {
364369
self.config.timestamp
365370
}
366371

367372
/// Gets type of batch.
368-
pub(crate) fn get_type(&self) -> BatchType {
373+
pub fn get_type(&self) -> BatchType {
369374
self.batch_type
370375
}
371376

@@ -424,6 +429,19 @@ fn serialize_statement<T>(
424429
Ok(Some(res))
425430
}
426431

432+
impl Default for BoundBatch {
433+
fn default() -> Self {
434+
Self {
435+
config: StatementConfig::default(),
436+
batch_type: BatchType::Logged,
437+
buffer: Vec::new(),
438+
prepared: HashMap::new(),
439+
first_prepared: None,
440+
statements_len: 0,
441+
}
442+
}
443+
}
444+
427445
fn counts_mismatch_err(n_value_lists: usize, n_statements: u16) -> BatchSerializationError {
428446
BatchSerializationError::ValuesAndStatementsLengthMismatch {
429447
n_value_lists,

0 commit comments

Comments
 (0)