1pub mod args;
2pub mod errors;
3mod excel;
4mod helpers;
5mod json;
6
7use crate::layout::value::{DataValue, ValueSource};
8use errors::DataError;
9use excel::ExcelDataSource;
10use json::JsonDataSource;
11
12pub trait DataSource: Sync {
14 fn retrieve_single_value(&self, name: &str) -> Result<DataValue, DataError>;
16
17 fn retrieve_1d_array_or_string(&self, name: &str) -> Result<ValueSource, DataError>;
19
20 fn retrieve_2d_array(&self, name: &str) -> Result<Vec<Vec<DataValue>>, DataError>;
22}
23
24pub fn create_data_source(args: &args::DataArgs) -> Result<Option<Box<dyn DataSource>>, DataError> {
28 if args.variant.is_some() && args.version.is_none() {
30 eprintln!("Warning: --variant is deprecated, use --version instead");
31 }
32
33 match (&args.xlsx, &args.postgres, &args.rest, &args.json) {
34 (Some(_), _, _, _) => Ok(Some(Box::new(ExcelDataSource::new(args)?))),
35 (_, Some(_), _, _) => Ok(Some(Box::new(JsonDataSource::from_postgres(args)?))),
36 (_, _, Some(_), _) => Ok(Some(Box::new(JsonDataSource::from_rest(args)?))),
37 (_, _, _, Some(_)) => Ok(Some(Box::new(JsonDataSource::from_json(args)?))),
38 _ => Ok(None),
39 }
40}