use crate::schema::{CountResponse, QueryResult, RowQuery, RowsResponse, TableInfo, TableSchema};
use async_trait::async_trait;
use thiserror::Error;
#[async_trait]
pub trait DatabaseProvider: Send + Sync + 'static {
async fn list_tables(&self) -> Result<Vec<TableInfo>, DatabaseError>;
async fn get_table_schema(&self, table: &str) -> Result<TableSchema, DatabaseError>;
async fn get_rows(&self, table: &str, query: RowQuery) -> Result<RowsResponse, DatabaseError>;
async fn count_rows(&self, table: &str, query: &RowQuery) -> Result<CountResponse, DatabaseError>;
async fn execute_query(&self, sql: &str) -> Result<QueryResult, DatabaseError>;
}
#[derive(Debug, Error)]
pub enum DatabaseError {
#[error("Database error: {0}")]
Query(String),
#[error("Table not found: {0}")]
TableNotFound(String),
#[error("Invalid column: {0}")]
InvalidColumn(String),
#[error("Query timeout exceeded")]
Timeout,
#[error("Result set too large (max {0} rows)")]
TooManyRows(u64),
#[error("Serialization error: {0}")]
Serialization(String),
}
impl From<sqlx::Error> for DatabaseError {
fn from(error: sqlx::Error) -> Self {
DatabaseError::Query(error.to_string())
}
}