sql_cli/data/
datasource_trait.rs1use anyhow::Result;
2use serde_json::Value;
3use std::collections::HashMap;
4
5#[derive(Debug, Clone)]
7pub struct DataSourceQueryResponse {
8 pub data: Vec<Value>,
9 pub count: usize,
10 pub columns: Vec<String>,
11 pub table_name: String,
12}
13
14pub trait DataSource: Send + Sync {
17 fn query(&self, sql: &str) -> Result<DataSourceQueryResponse>;
19
20 fn query_with_options(
22 &self,
23 sql: &str,
24 case_insensitive: bool,
25 ) -> Result<DataSourceQueryResponse>;
26
27 fn get_schema(&self) -> Option<HashMap<String, Vec<String>>>;
29
30 fn get_table_name(&self) -> String;
32
33 fn get_row_count(&self) -> usize;
35
36 fn is_case_insensitive(&self) -> bool;
38
39 fn set_case_insensitive(&mut self, case_insensitive: bool);
41
42 fn clone_box(&self) -> Box<dyn DataSource>;
44}
45
46pub trait ToDataTable {
48 fn to_datatable(&self) -> Result<crate::datatable::DataTable>;
50}