2021-08-08 11:57:40 +00:00
|
|
|
pub mod mysql;
|
|
|
|
pub mod postgres;
|
|
|
|
|
|
|
|
pub use mysql::MySqlPool;
|
|
|
|
pub use postgres::PostgresPool;
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use database_tree::{Child, Database, Table};
|
|
|
|
|
|
|
|
pub const RECORDS_LIMIT_PER_PAGE: u8 = 200;
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
pub trait Pool {
|
|
|
|
async fn get_databases(&self) -> anyhow::Result<Vec<Database>>;
|
|
|
|
async fn get_tables(&self, database: String) -> anyhow::Result<Vec<Child>>;
|
|
|
|
async fn get_records(
|
|
|
|
&self,
|
|
|
|
database: &Database,
|
|
|
|
table: &Table,
|
|
|
|
page: u16,
|
|
|
|
filter: Option<String>,
|
|
|
|
) -> anyhow::Result<(Vec<String>, Vec<Vec<String>>)>;
|
|
|
|
async fn get_columns(
|
|
|
|
&self,
|
|
|
|
database: &Database,
|
|
|
|
table: &Table,
|
2021-08-28 03:46:33 +00:00
|
|
|
) -> anyhow::Result<Vec<Box<dyn TableRow>>>;
|
|
|
|
async fn get_constraints(
|
|
|
|
&self,
|
|
|
|
database: &Database,
|
|
|
|
table: &Table,
|
|
|
|
) -> anyhow::Result<Vec<Box<dyn TableRow>>>;
|
2021-08-28 05:01:11 +00:00
|
|
|
async fn get_foreign_keys(
|
|
|
|
&self,
|
|
|
|
database: &Database,
|
|
|
|
table: &Table,
|
|
|
|
) -> anyhow::Result<Vec<Box<dyn TableRow>>>;
|
2021-08-08 11:57:40 +00:00
|
|
|
async fn close(&self);
|
|
|
|
}
|
2021-08-28 03:46:33 +00:00
|
|
|
|
|
|
|
pub trait TableRow: std::marker::Send {
|
|
|
|
fn fields(&self) -> Vec<String>;
|
|
|
|
fn columns(&self) -> Vec<String>;
|
|
|
|
}
|