Skip to main content

DatabaseDriver

Trait DatabaseDriver 

Source
pub trait DatabaseDriver: Send + Sync {
Show 36 methods // Required methods fn driver_type(&self) -> DatabaseType; fn connect<'life0, 'life1, 'async_trait>( &'life0 self, config: &'life1 ConnectionConfig, ) -> Pin<Box<dyn Future<Output = Result<ConnectionHandle, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn test_connection<'life0, 'life1, 'async_trait>( &'life0 self, config: &'life1 ConnectionConfig, ) -> Pin<Box<dyn Future<Output = Result<ServerInfo, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn disconnect<'life0, 'async_trait>( &'life0 self, handle: ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_databases<'life0, 'life1, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_tables<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, database: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<TableInfo>, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn get_table_schema<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, table: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<TableSchema, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn query<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<QueryResult, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn query_multi<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<MultiQueryResult, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn query_with_params<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, params: &'life3 [Value], ) -> Pin<Box<dyn Future<Output = Result<QueryResult, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<u64, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn cancel_query<'life0, 'life1, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; // Provided methods fn driver_category(&self) -> DriverCategory { ... } fn quote_char(&self) -> char { ... } fn quote_ident(&self, name: &str) -> String { ... } fn skip_count_query(&self) -> bool { ... } fn supports_offset(&self) -> bool { ... } fn supports_explain(&self) -> bool { ... } fn format_sql_literal(&self, value: &Option<Value>) -> String { ... } fn build_update_sql( &self, table: &str, set_columns: &[(&str, Option<Value>)], pk_columns: &[(&str, Option<Value>)], ) -> String { ... } fn get_columns<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, table: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(Vec<ColumnSchema>, Vec<String>), DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn query_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, limit: Option<u32>, on_event: QueryStreamCallback, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn command_definitions(&self) -> Vec<DriverCommandDefinition> { ... } fn execute_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, command: &'life2 str, input: Value, ) -> Pin<Box<dyn Future<Output = Result<CommandResult, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn begin_transaction<'life0, 'life1, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<TransactionHandle, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn commit<'life0, 'async_trait>( &'life0 self, _tx: TransactionHandle, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn rollback<'life0, 'async_trait>( &'life0 self, _tx: TransactionHandle, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn explain<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, _sql: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<ExplainResult, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn get_server_info<'life0, 'life1, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<ServerInfo, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn use_database<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, _database: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn prompt_overrides(&self) -> HashMap<PromptScenario, PromptTemplate> { ... } fn dump_table_ddl<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, table: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<String, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn dump_database<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, database: &'life2 str, opts: &'life3 BackupDumpOptions, ) -> Pin<Box<dyn Future<Output = Result<String, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn restore_sql<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, opts: Option<&'life3 BackupRestoreOptions>, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn structure_capabilities<'life0, 'life1, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<StructureCapabilities, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn plan_structure_changes<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, _request: &'life2 StructureChangeRequest, ) -> Pin<Box<dyn Future<Output = Result<StructureChangePlan, DriverError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... }
}

Required Methods§

Source

fn driver_type(&self) -> DatabaseType

Source

fn connect<'life0, 'life1, 'async_trait>( &'life0 self, config: &'life1 ConnectionConfig, ) -> Pin<Box<dyn Future<Output = Result<ConnectionHandle, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn test_connection<'life0, 'life1, 'async_trait>( &'life0 self, config: &'life1 ConnectionConfig, ) -> Pin<Box<dyn Future<Output = Result<ServerInfo, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn disconnect<'life0, 'async_trait>( &'life0 self, handle: ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn get_databases<'life0, 'life1, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn get_tables<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, database: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<TableInfo>, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn get_table_schema<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, table: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<TableSchema, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn query<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<QueryResult, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn query_multi<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<MultiQueryResult, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn query_with_params<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, params: &'life3 [Value], ) -> Pin<Box<dyn Future<Output = Result<QueryResult, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<u64, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn cancel_query<'life0, 'life1, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Provided Methods§

Source

fn driver_category(&self) -> DriverCategory

Source

fn quote_char(&self) -> char

Source

fn quote_ident(&self, name: &str) -> String

Source

fn skip_count_query(&self) -> bool

Source

fn supports_offset(&self) -> bool

Whether the driver’s SQL dialect supports OFFSET in pagination. Drivers that don’t (e.g. Presto/Hive via Superset) should return false.

Source

fn supports_explain(&self) -> bool

Whether the driver supports EXPLAIN query plan analysis.

Source

fn format_sql_literal(&self, value: &Option<Value>) -> String

Source

fn build_update_sql( &self, table: &str, set_columns: &[(&str, Option<Value>)], pk_columns: &[(&str, Option<Value>)], ) -> String

Source

fn get_columns<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, table: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(Vec<ColumnSchema>, Vec<String>), DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn query_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, limit: Option<u32>, on_event: QueryStreamCallback, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Stream query results as row batches.

limit is the SQL result cap from the host “limit SELECT results” setting (None = do not rewrite/cap SQL). It is not the IPC batch size. Drivers that can stream from the wire should override this; the default materializes Self::query_multi then emits chunks.

Source

fn command_definitions(&self) -> Vec<DriverCommandDefinition>

Return commands supported by this driver.

Existing SQL drivers get the standard query and execute commands. A driver with additional capabilities can override this method and append its own command definitions.

Source

fn execute_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, command: &'life2 str, input: Value, ) -> Pin<Box<dyn Future<Output = Result<CommandResult, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute a driver command.

The default implementation maps the existing SQL APIs to commands so existing drivers remain source-compatible. Driver plugins can override this method to implement driver-specific commands without adding another application-level dispatch path.

Source

fn begin_transaction<'life0, 'life1, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<TransactionHandle, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn commit<'life0, 'async_trait>( &'life0 self, _tx: TransactionHandle, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn rollback<'life0, 'async_trait>( &'life0 self, _tx: TransactionHandle, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn explain<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, _sql: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<ExplainResult, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn get_server_info<'life0, 'life1, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<ServerInfo, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch server version info using an existing connection handle. Unlike test_connection which creates a temporary pool, this reuses the live connection.

Source

fn use_database<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, _database: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Switch the active database for subsequent queries. Drivers that maintain per-session state (e.g. Kiwi) should override this.

Source

fn prompt_overrides(&self) -> HashMap<PromptScenario, PromptTemplate>

Return driver-specific prompt overrides for AI features.

Templates can use {{variable}} placeholders. Available variables per scenario are documented in the main application’s PromptResolver. The default implementation returns an empty map (use global defaults).

Source

fn dump_table_ddl<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, table: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<String, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Emit CREATE TABLE DDL for a single table.

Default builds DDL from Self::get_table_schema.

Source

fn dump_database<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, database: &'life2 str, opts: &'life3 BackupDumpOptions, ) -> Pin<Box<dyn Future<Output = Result<String, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Dump an entire database to SQL text.

Default refuses create_database with DriverError::NotSupported and otherwise delegates to crate::sql_dump::dump_sql_database.

Source

fn restore_sql<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, handle: &'life1 ConnectionHandle, sql: &'life2 str, opts: Option<&'life3 BackupRestoreOptions>, ) -> Pin<Box<dyn Future<Output = Result<(), DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Restore a SQL dump by executing statements against the live connection.

Default uses crate::sql_dump::split_sql_statements and honors BackupRestoreOptions::single_transaction / dump header flags.

Source

fn structure_capabilities<'life0, 'life1, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, ) -> Pin<Box<dyn Future<Output = Result<StructureCapabilities, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn plan_structure_changes<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _handle: &'life1 ConnectionHandle, _request: &'life2 StructureChangeRequest, ) -> Pin<Box<dyn Future<Output = Result<StructureChangePlan, DriverError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§