connectorx/sources/
mod.rs1#[cfg(feature = "src_bigquery")]
5pub mod bigquery;
6#[cfg(feature = "src_csv")]
7pub mod csv;
8#[cfg(feature = "src_dummy")]
9pub mod dummy;
10#[cfg(feature = "src_mssql")]
11pub mod mssql;
12#[cfg(feature = "src_mysql")]
13pub mod mysql;
14#[cfg(feature = "src_oracle")]
15pub mod oracle;
16#[cfg(feature = "src_postgres")]
17pub mod postgres;
18#[cfg(feature = "src_sqlite")]
19pub mod sqlite;
20#[cfg(feature = "src_trino")]
21pub mod trino;
22
23use crate::data_order::DataOrder;
24use crate::errors::ConnectorXError;
25use crate::sql::CXQuery;
26use crate::typesystem::{TypeAssoc, TypeSystem};
27use std::fmt::Debug;
28
29pub trait Source {
30 const DATA_ORDERS: &'static [DataOrder];
32 type TypeSystem: TypeSystem;
34 type Partition: SourcePartition<TypeSystem = Self::TypeSystem, Error = Self::Error> + Send;
36 type Error: From<ConnectorXError> + Send + Debug;
37
38 fn set_data_order(&mut self, data_order: DataOrder) -> Result<(), Self::Error>;
39
40 fn set_queries<Q: ToString>(&mut self, queries: &[CXQuery<Q>]);
41
42 fn set_origin_query(&mut self, query: Option<String>);
43
44 fn set_pre_execution_queries(&mut self, _pre_execution_queries: Option<&[String]>) {
45 unimplemented!("pre_execution_queries is not implemented in this source type");
46 }
47
48 fn fetch_metadata(&mut self) -> Result<(), Self::Error>;
49 fn result_rows(&mut self) -> Result<Option<usize>, Self::Error>;
51
52 fn names(&self) -> Vec<String>;
53
54 fn schema(&self) -> Vec<Self::TypeSystem>;
55
56 fn partition(self) -> Result<Vec<Self::Partition>, Self::Error>;
57}
58
59pub trait SourcePartition {
62 type TypeSystem: TypeSystem;
63 type Parser<'a>: PartitionParser<'a, TypeSystem = Self::TypeSystem, Error = Self::Error>
64 where
65 Self: 'a;
66 type Error: From<ConnectorXError> + Send + Debug;
67
68 fn result_rows(&mut self) -> Result<(), Self::Error>;
70
71 fn parser(&mut self) -> Result<Self::Parser<'_>, Self::Error>;
72
73 fn nrows(&self) -> usize;
76
77 fn ncols(&self) -> usize;
79}
80
81pub trait PartitionParser<'a>: Send {
82 type TypeSystem: TypeSystem;
83 type Error: From<ConnectorXError> + Send + Debug;
84
85 fn parse<'r, T>(&'r mut self) -> Result<T, <Self as PartitionParser<'a>>::Error>
88 where
89 T: TypeAssoc<Self::TypeSystem>,
90 Self: Produce<'r, T, Error = <Self as PartitionParser<'a>>::Error>,
91 {
92 self.produce()
93 }
94
95 fn fetch_next(&mut self) -> Result<(usize, bool), Self::Error>;
99}
100
101pub trait Produce<'r, T> {
103 type Error: From<ConnectorXError> + Send;
104
105 fn produce(&'r mut self) -> Result<T, Self::Error>;
106}