From 563703446eaec2dbed721dbe2c6565cee0d419be Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 6 Jan 2025 18:51:45 +0200 Subject: Comment out py_bindings entirely for the time being --- py_bindings/src/lib.rs | 420 ++++++++++++++++++++++++------------------------- 1 file changed, 210 insertions(+), 210 deletions(-) (limited to 'py_bindings/src/lib.rs') diff --git a/py_bindings/src/lib.rs b/py_bindings/src/lib.rs index aa79680..498aaaf 100644 --- a/py_bindings/src/lib.rs +++ b/py_bindings/src/lib.rs @@ -1,212 +1,212 @@ -use log_db; -use pyo3::exceptions::PyException; -use pyo3::prelude::*; - -type Field = String; - -#[pyclass] -#[derive(Clone)] -struct ValueType { - record_field: log_db::ValueType, -} - -#[pymethods] -impl ValueType { - #[staticmethod] - fn int() -> Self { - ValueType { - record_field: log_db::ValueType::int(), - } - } - - #[staticmethod] - fn float() -> Self { - ValueType { - record_field: log_db::ValueType::float(), - } - } - - #[staticmethod] - fn string() -> Self { - ValueType { - record_field: log_db::ValueType::string(), - } - } - - #[staticmethod] - fn bytes() -> Self { - ValueType { - record_field: log_db::ValueType::bytes(), - } - } - - fn nullable(&self) -> Self { - ValueType { - record_field: self.record_field.clone().nullable(), - } - } -} - -#[pyclass] -#[derive(Clone)] -struct WriteDurability { - write_durability: log_db::WriteDurability, -} - -#[pyclass] -struct Config { - #[pyo3(get, set)] - data_dir: Option, - #[pyo3(get, set)] - segment_size: Option, - #[pyo3(get, set)] - fields: Option>, - #[pyo3(get, set)] - primary_key: Option, - #[pyo3(get, set)] - secondary_keys: Option>, - #[pyo3(get, set)] - write_durability: Option, -} - -#[pymethods] -impl Config { - pub fn initialize(&self) -> PyResult { - let mut config = log_db::DB::configure(); - if self.data_dir.is_some() { - config.data_dir(&self.data_dir.as_ref().unwrap().to_string()); - } - if self.segment_size.is_some() { - config.segment_size(self.segment_size.unwrap()); - } - if self.fields.is_some() { - let mut fields = Vec::new(); - for (field, record_field) in self.fields.as_ref().unwrap() { - fields.push((field.to_string(), record_field.record_field.clone())); - } - config.fields(&fields); - } - if self.primary_key.is_some() { - config.primary_key(self.primary_key.as_ref().unwrap().to_string()); - } - if self.secondary_keys.is_some() { - let tmp = self.secondary_keys.as_ref().unwrap(); - config.secondary_keys(&tmp); - } - if self.write_durability.is_some() { - let tmp = self.write_durability.as_ref().unwrap(); - config.write_durability(tmp.write_durability.clone()); - } - - let db = config - .initialize() - .map_err(|e| PyException::new_err(e.to_string()))?; - Ok(DB { db }) - } -} - -#[pyclass] -#[derive(Clone)] -struct Value { - record_value: log_db::Value, -} - -#[pymethods] -impl Value { - #[staticmethod] - fn int(value: i64) -> Self { - Value { - record_value: log_db::Value::Int(value), - } - } - - #[staticmethod] - fn float(value: f64) -> Self { - Value { - record_value: log_db::Value::Float(value), - } - } - - #[staticmethod] - fn string(value: &str) -> Self { - Value { - record_value: log_db::Value::String(value.to_string()), - } - } - - #[staticmethod] - fn bytes(value: &[u8]) -> Self { - Value { - record_value: log_db::Value::Bytes(value.to_vec()), - } - } - - #[staticmethod] - fn null() -> Self { - Value { - record_value: log_db::Value::Null, - } - } -} - -#[pyclass] -struct Record { - values: Vec, -} - -#[pymethods] -impl Record { - #[new] - #[pyo3(signature = (*py_args))] - fn new(py_args: Vec) -> Self { - Record { values: py_args } - } -} - -#[pyclass] -struct DB { - db: log_db::DB, -} - -#[pymethods] -impl DB { - fn upsert(&mut self, record: &Record) -> PyResult<()> { - let values: Vec = record - .values - .iter() - .map(|v| v.record_value.clone()) - .collect(); - - self.db - .upsert(&log_db::Record::from(&values)) - .map_err(|e| PyException::new_err(e.to_string()))?; - Ok(()) - } - - #[staticmethod] - pub fn configure() -> Config { - Config { - data_dir: None, - segment_size: None, - fields: None, - primary_key: None, - secondary_keys: None, - write_durability: None, - } - } -} - -// #[pyfunction] -// fn sum_as_string(a: usize, b: usize) -> PyResult { -// Ok((a + b).to_string()) +// use log_db; +// use pyo3::exceptions::PyException; +// use pyo3::prelude::*; + +// type Field = String; + +// #[pyclass] +// #[derive(Clone)] +// struct ValueType { +// record_field: log_db::ValueType, +// } + +// #[pymethods] +// impl ValueType { +// #[staticmethod] +// fn int() -> Self { +// ValueType { +// record_field: log_db::ValueType::int(), +// } +// } + +// #[staticmethod] +// fn float() -> Self { +// ValueType { +// record_field: log_db::ValueType::float(), +// } +// } + +// #[staticmethod] +// fn string() -> Self { +// ValueType { +// record_field: log_db::ValueType::string(), +// } +// } + +// #[staticmethod] +// fn bytes() -> Self { +// ValueType { +// record_field: log_db::ValueType::bytes(), +// } +// } + +// fn nullable(&self) -> Self { +// ValueType { +// record_field: self.record_field.clone().nullable(), +// } +// } +// } + +// #[pyclass] +// #[derive(Clone)] +// struct WriteDurability { +// write_durability: log_db::WriteDurability, +// } + +// #[pyclass] +// struct Config { +// #[pyo3(get, set)] +// data_dir: Option, +// #[pyo3(get, set)] +// segment_size: Option, +// #[pyo3(get, set)] +// fields: Option>, +// #[pyo3(get, set)] +// primary_key: Option, +// #[pyo3(get, set)] +// secondary_keys: Option>, +// #[pyo3(get, set)] +// write_durability: Option, +// } + +// #[pymethods] +// impl Config { +// pub fn initialize(&self) -> PyResult { +// let mut config = log_db::DB::configure(); +// if self.data_dir.is_some() { +// config.data_dir(&self.data_dir.as_ref().unwrap().to_string()); +// } +// if self.segment_size.is_some() { +// config.segment_size(self.segment_size.unwrap()); +// } +// if self.fields.is_some() { +// let mut fields = Vec::new(); +// for (field, record_field) in self.fields.as_ref().unwrap() { +// fields.push((field.to_string(), record_field.record_field.clone())); +// } +// config.fields(&fields); +// } +// if self.primary_key.is_some() { +// config.primary_key(self.primary_key.as_ref().unwrap().to_string()); +// } +// if self.secondary_keys.is_some() { +// let tmp = self.secondary_keys.as_ref().unwrap(); +// config.secondary_keys(&tmp); +// } +// if self.write_durability.is_some() { +// let tmp = self.write_durability.as_ref().unwrap(); +// config.write_durability(tmp.write_durability.clone()); +// } + +// let db = config +// .initialize() +// .map_err(|e| PyException::new_err(e.to_string()))?; +// Ok(DB { db }) +// } +// } + +// #[pyclass] +// #[derive(Clone)] +// struct Value { +// record_value: log_db::Value, // } -#[pymodule] -fn log_db_py(m: &Bound<'_, PyModule>) -> PyResult<()> { - //m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - Ok(()) -} +// #[pymethods] +// impl Value { +// #[staticmethod] +// fn int(value: i64) -> Self { +// Value { +// record_value: log_db::Value::Int(value), +// } +// } + +// #[staticmethod] +// fn float(value: f64) -> Self { +// Value { +// record_value: log_db::Value::Float(value), +// } +// } + +// #[staticmethod] +// fn string(value: &str) -> Self { +// Value { +// record_value: log_db::Value::String(value.to_string()), +// } +// } + +// #[staticmethod] +// fn bytes(value: &[u8]) -> Self { +// Value { +// record_value: log_db::Value::Bytes(value.to_vec()), +// } +// } + +// #[staticmethod] +// fn null() -> Self { +// Value { +// record_value: log_db::Value::Null, +// } +// } +// } + +// #[pyclass] +// struct Record { +// values: Vec, +// } + +// #[pymethods] +// impl Record { +// #[new] +// #[pyo3(signature = (*py_args))] +// fn new(py_args: Vec) -> Self { +// Record { values: py_args } +// } +// } + +// #[pyclass] +// struct DB { +// db: log_db::DB, +// } + +// #[pymethods] +// impl DB { +// fn upsert(&mut self, record: &Record) -> PyResult<()> { +// let values: Vec = record +// .values +// .iter() +// .map(|v| v.record_value.clone()) +// .collect(); + +// self.db +// .upsert(&log_db::Record::from(&values)) +// .map_err(|e| PyException::new_err(e.to_string()))?; +// Ok(()) +// } + +// #[staticmethod] +// pub fn configure() -> Config { +// Config { +// data_dir: None, +// segment_size: None, +// fields: None, +// primary_key: None, +// secondary_keys: None, +// write_durability: None, +// } +// } +// } + +// // #[pyfunction] +// // fn sum_as_string(a: usize, b: usize) -> PyResult { +// // Ok((a + b).to_string()) +// // } + +// #[pymodule] +// fn log_db_py(m: &Bound<'_, PyModule>) -> PyResult<()> { +// //m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; +// m.add_class::()?; +// m.add_class::()?; +// m.add_class::()?; +// m.add_class::()?; +// Ok(()) +// } -- cgit v1.3