datafusion_table_providers/sql/db_connection_pool/
mod.rs1use async_trait::async_trait;
2use dbconnection::DbConnection;
3use std::sync::Arc;
4
5pub mod dbconnection;
6#[cfg(feature = "duckdb")]
7pub mod duckdbpool;
8#[cfg(feature = "mysql")]
9pub mod mysqlpool;
10#[cfg(feature = "odbc")]
11pub mod odbcpool;
12#[cfg(feature = "postgres")]
13pub mod postgrespool;
14#[cfg(feature = "sqlite")]
15pub mod sqlitepool;
16
17pub type Error = Box<dyn std::error::Error + Send + Sync>;
18type Result<T, E = Error> = std::result::Result<T, E>;
19
20#[derive(Clone, Debug, PartialEq, Eq)]
22pub enum JoinPushDown {
23 Disallow,
25 AllowedFor(String),
29}
30
31#[async_trait]
32pub trait DbConnectionPool<T, P: 'static> {
33 async fn connect(&self) -> Result<Box<dyn DbConnection<T, P>>>;
34
35 fn join_push_down(&self) -> JoinPushDown;
36}
37
38#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
39pub enum Mode {
40 #[default]
41 Memory,
42 File,
43}
44
45impl From<&str> for Mode {
46 fn from(m: &str) -> Self {
47 match m {
48 "file" => Mode::File,
49 "memory" => Mode::Memory,
50 _ => Mode::default(),
51 }
52 }
53}
54
55#[derive(Debug, Clone, PartialEq, Eq, Hash)]
57pub enum DbInstanceKey {
58 File(Arc<str>),
60 Memory,
62}
63
64impl DbInstanceKey {
65 pub fn memory() -> Self {
66 DbInstanceKey::Memory
67 }
68
69 pub fn file(path: Arc<str>) -> Self {
70 DbInstanceKey::File(path)
71 }
72}