use async_trait::async_trait;
use tokio::sync::mpsc;
use crate::core::error::DbResult;
use crate::core::models::*;
pub struct QueryBatch {
pub columns: Vec<String>,
pub rows: Vec<Vec<String>>,
pub done: bool,
}
#[allow(dead_code)]
#[async_trait]
pub trait DatabaseAdapter: Send + Sync {
fn name(&self) -> &str;
fn db_type(&self) -> DatabaseType;
async fn get_schemas(&self) -> DbResult<Vec<Schema>>;
async fn get_tables(&self, schema: &str) -> DbResult<Vec<Table>>;
async fn get_views(&self, schema: &str) -> DbResult<Vec<View>>;
async fn get_procedures(&self, schema: &str) -> DbResult<Vec<Procedure>>;
async fn get_functions(&self, schema: &str) -> DbResult<Vec<Function>>;
async fn get_columns(&self, schema: &str, table: &str) -> DbResult<Vec<Column>>;
async fn execute(&self, query: &str) -> DbResult<QueryResult>;
async fn execute_streaming(
&self,
query: &str,
tx: mpsc::Sender<DbResult<QueryBatch>>,
) -> DbResult<()> {
let result = self.execute(query).await?;
let _ = tx
.send(Ok(QueryBatch {
columns: result.columns,
rows: result.rows,
done: true,
}))
.await;
Ok(())
}
async fn get_packages(&self, _schema: &str) -> DbResult<Vec<Package>> {
Ok(vec![])
}
async fn get_package_content(
&self,
_schema: &str,
_name: &str,
) -> DbResult<Option<PackageContent>> {
Ok(None)
}
async fn get_table_ddl(&self, _schema: &str, _table: &str) -> DbResult<String> {
Ok(String::new())
}
async fn get_source_code(
&self,
_schema: &str,
_name: &str,
_obj_type: &str,
) -> DbResult<String> {
Ok(String::new())
}
}