Skip to content

Commit 55c0111

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 4fbc36b commit 55c0111

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
@@ -225,7 +225,7 @@ impl<'a: 'b, 'b> From<&'a BatchStatement>
225225
}
226226

227227
/// A batch with all of its statements bound to values
228-
pub(crate) struct BoundBatch {
228+
pub struct BoundBatch {
229229
pub(crate) config: StatementConfig,
230230
batch_type: BatchType,
231231
pub(crate) buffer: Vec<u8>,
@@ -235,21 +235,26 @@ pub(crate) struct BoundBatch {
235235
}
236236

237237
impl BoundBatch {
238+
pub fn new(batch_type: BatchType) -> Self {
239+
Self {
240+
batch_type,
241+
..Default::default()
242+
}
243+
}
244+
238245
pub(crate) fn from_batch(
239246
batch: &Batch,
240247
values: impl BatchValues,
241248
) -> Result<Self, ExecutionError> {
242249
let mut bound_batch = BoundBatch {
243250
config: batch.config.clone(),
244251
batch_type: batch.batch_type,
245-
prepared: HashMap::new(),
246-
buffer: vec![],
247-
first_prepared: None,
248252
statements_len: batch.statements.len().try_into().map_err(|_| {
249253
ExecutionError::BadQuery(BadQuery::TooManyQueriesInBatchStatement(
250254
batch.statements.len(),
251255
))
252256
})?,
257+
..Default::default()
253258
};
254259

255260
let mut values = values.batch_values_iter();
@@ -329,17 +334,17 @@ impl BoundBatch {
329334
}
330335

331336
/// Borrows the execution profile handle associated with this batch.
332-
pub(crate) fn get_execution_profile_handle(&self) -> Option<&ExecutionProfileHandle> {
337+
pub fn get_execution_profile_handle(&self) -> Option<&ExecutionProfileHandle> {
333338
self.config.execution_profile_handle.as_ref()
334339
}
335340

336341
/// Gets the default timestamp for this batch in microseconds.
337-
pub(crate) fn get_timestamp(&self) -> Option<i64> {
342+
pub fn get_timestamp(&self) -> Option<i64> {
338343
self.config.timestamp
339344
}
340345

341346
/// Gets type of batch.
342-
pub(crate) fn get_type(&self) -> BatchType {
347+
pub fn get_type(&self) -> BatchType {
343348
self.batch_type
344349
}
345350

@@ -398,6 +403,19 @@ fn serialize_statement<T>(
398403
Ok(Some(res))
399404
}
400405

406+
impl Default for BoundBatch {
407+
fn default() -> Self {
408+
Self {
409+
config: StatementConfig::default(),
410+
batch_type: BatchType::Logged,
411+
buffer: Vec::new(),
412+
prepared: HashMap::new(),
413+
first_prepared: None,
414+
statements_len: 0,
415+
}
416+
}
417+
}
418+
401419
fn counts_mismatch_err(n_value_lists: usize, n_statements: u16) -> BatchSerializationError {
402420
BatchSerializationError::ValuesAndStatementsLengthMismatch {
403421
n_value_lists,

0 commit comments

Comments
 (0)