Skip to main content

DatabaseBackend

Trait DatabaseBackend 

Source
pub trait DatabaseBackend {
    // Required methods
    async fn list_databases(&self) -> Result<Vec<String>, AppError>;
    async fn list_tables(&self, database: &str) -> Result<Vec<String>, AppError>;
    async fn get_table_schema(
        &self,
        database: &str,
        table: &str,
    ) -> Result<Value, AppError>;
    async fn get_table_schema_with_relations(
        &self,
        database: &str,
        table: &str,
    ) -> Result<Value, AppError>;
    async fn execute_query(
        &self,
        sql: &str,
        database: Option<&str>,
    ) -> Result<Value, AppError>;
    async fn create_database(&self, name: &str) -> Result<Value, AppError>;
    fn dialect(&self) -> Box<dyn Dialect>;
    fn read_only(&self) -> bool;
}
Expand description

Operations every database backend must support.

Required Methods§

Source

async fn list_databases(&self) -> Result<Vec<String>, AppError>

Lists all accessible databases.

Source

async fn list_tables(&self, database: &str) -> Result<Vec<String>, AppError>

Lists all tables in a database.

Source

async fn get_table_schema( &self, database: &str, table: &str, ) -> Result<Value, AppError>

Returns column definitions for a table.

Source

async fn get_table_schema_with_relations( &self, database: &str, table: &str, ) -> Result<Value, AppError>

Returns column definitions with foreign key relationships.

Source

async fn execute_query( &self, sql: &str, database: Option<&str>, ) -> Result<Value, AppError>

Executes a SQL query and returns rows as a JSON array.

Source

async fn create_database(&self, name: &str) -> Result<Value, AppError>

Creates a database if it doesn’t exist.

Source

fn dialect(&self) -> Box<dyn Dialect>

Returns the SQL dialect for this backend.

Source

fn read_only(&self) -> bool

Whether read-only mode is enabled.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§