Coder Social home page Coder Social logo

Comments (4)

altanozlu avatar altanozlu commented on June 18, 2024

is there any news about it ?

from scylla-rust-driver.

psarna avatar psarna commented on June 18, 2024

This issue is currently in a "pull requests welcome" state. It's generally on a roadmap, but the team is currently focused on providing performance benchmarks.

from scylla-rust-driver.

krzysztofgal avatar krzysztofgal commented on June 18, 2024

If someone needs func. like that - it is quite easy to impl according to usecase.

use super::{BatchValues, ScyllaError};
use scylla::batch::Batch;
use scylla::frame::value::SerializedValues;
use scylla::prepared_statement::PreparedStatement;

pub struct BatchPrepare {
    batch: Batch,
    values: Vec<SerializedValues>,
    stmt_count: u32,
}

impl BatchPrepare {
    pub fn new() -> Self {
        Self {
            batch: Batch::default(),
            values: Vec::new(),
            stmt_count: 0,
        }
    }

    pub fn take(mut self) -> (Batch, Vec<SerializedValues>) {
        let batch = std::mem::take(&mut self.batch);
        let values = std::mem::take(&mut self.values);
        self.stmt_count = 0;
        (batch, values)
    }

    pub fn add_batch_stmt(&mut self, prepared_statement: PreparedStatement) {
        self.batch.append_statement(prepared_statement);
        self.stmt_count += 1;
    }

    pub fn add_values(&mut self, values: impl BatchValues) -> Result<(), ScyllaError> {
        let v = values.as_batch_values()?;
        self.values.push(v);
        Ok(())
    }

    pub fn is_empty(&self) -> bool {
        self.stmt_count == 0
    }
}
use super::ScyllaError;
use scylla::frame::value::{SerializedValues, Value, ValueList};

fn add_value(s: &mut SerializedValues, val: &impl Value) -> Result<(), ScyllaError> {
    s.add_value(val)
        .map_err(|e| ScyllaError::Internal(e.into()))
}

pub trait BatchValues {
    fn as_batch_values(&self) -> Result<SerializedValues, ScyllaError>;
}

impl<T: ValueList> BatchValues for &T {
    fn as_batch_values(&self) -> Result<SerializedValues, ScyllaError> {
        let s = <T as ValueList>::serialized(self).map_err(|e| ScyllaError::Internal(e.into()))?;
        Ok(s.into_owned())
    }
}

macro_rules! impl_batch_tuple {
    ( $($Ti:ident),* ; $($FieldI:tt),*) => {
        impl<$($Ti),+> BatchValues for ($($Ti,)+)
            where
                $($Ti: Value),+
        {
            fn as_batch_values(&self) -> Result<SerializedValues, ScyllaError> {
                let mut s = SerializedValues::new();
                $(
                    add_value(&mut s, &self.$FieldI)?;
                )*
                Ok(s)
            }
        }
    }
}

impl_batch_tuple!(T0; 0);
impl_batch_tuple!(T0, T1; 0, 1);
impl_batch_tuple!(T0, T1, T2; 0, 1, 2);
impl_batch_tuple!(T0, T1, T2, T3; 0, 1, 2, 3);
impl_batch_tuple!(T0, T1, T2, T3, T4; 0, 1, 2, 3, 4);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5; 0, 1, 2, 3, 4, 5);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6; 0, 1, 2, 3, 4, 5, 6);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7; 0, 1, 2, 3, 4, 5, 6, 7);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8; 0, 1, 2, 3, 4, 5, 6, 7, 8);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
impl_batch_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);

from scylla-rust-driver.

wprzytula avatar wprzytula commented on June 18, 2024

Ref: #941

from scylla-rust-driver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.