1pub mod args;
2pub mod error;
3mod excel;
4mod helpers;
5mod json;
6
7use crate::layout::value::{DataValue, ValueSource};
8use error::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 match (&args.xlsx, &args.postgres, &args.http, &args.json) {
29 (Some(_), _, _, _) => Ok(Some(Box::new(ExcelDataSource::new(args)?))),
30 (_, Some(_), _, _) => Ok(Some(Box::new(JsonDataSource::from_postgres(args)?))),
31 (_, _, Some(_), _) => Ok(Some(Box::new(JsonDataSource::from_http(args)?))),
32 (_, _, _, Some(_)) => Ok(Some(Box::new(JsonDataSource::from_json(args)?))),
33 _ => Ok(None),
34 }
35}