#![doc = include_str!("../README.md")]
use oracle::Connection;
use statements::{PreppedGridData, PreppedRowData};
use format_data::{FormatData, FormattedData};
use types::DatatypeIndexes;
pub mod statements;
pub mod types;
pub mod utils;
pub mod format_data;
pub trait PrepData<T: FormatData> {
type Prep;
fn prep_data(self, connection: Connection) -> Self::Prep;
}
impl<T: FormatData> PrepData<T> for Vec<Vec<T>> {
type Prep = PreppedGridData;
fn prep_data(self, connection: Connection) -> Self::Prep {
let mut is_varchar: Vec<usize> = Vec::new();
let mut is_float: Vec<usize> = Vec::new();
let mut is_int: Vec<usize> = Vec::new();
let mut is_date: Vec<usize> = Vec::new();
let mut data = Vec::new();
let mut y_index: usize = 0 as usize;
for row in self {
let mut inner_vec = Vec::new();
let mut x_index: usize = 0 as usize;
for cell in row {
let formatted_cell = cell.fmt_data();
if y_index > 0 {
match &formatted_cell {
FormattedData::STRING(_) => is_varchar.push(x_index),
FormattedData::INT(_) => is_int.push(x_index),
FormattedData::FLOAT(_) => is_float.push(x_index),
FormattedData::DATE(_) => is_date.push(x_index),
FormattedData::TIMESTAMP(_) => is_date.push(x_index),
FormattedData::EMPTY => {
inner_vec.push(formatted_cell);
x_index += 1 as usize;
continue;
},
}
}
inner_vec.push(formatted_cell);
x_index += 1 as usize;
}
data.push(inner_vec);
y_index += 1 as usize;
}
let data_indexes = DatatypeIndexes {
is_varchar,
is_float,
is_int,
is_date,
}.find_uniques();
Self::Prep {
data,
conn: connection,
data_indexes
}
}
}
impl<T: FormatData> PrepData<T> for Vec<T> {
type Prep = PreppedRowData;
fn prep_data(self, connection: Connection) -> Self::Prep {
let mut data = Vec::new();
for val in self { data.push(val.fmt_data().to_string()) }
Self::Prep {
data,
conn: connection,
}
}
}