Implementation:2giosangmitom Sqmeow nvim Backend
| Knowledge Sources | |
|---|---|
| Domains | Database, Connection_Management, Query_Execution, Editing, Schema |
| Last Updated | 2026-10-16 14:00 GMT |
Overview
Concrete tool for dispatching database operations across 11 adapter dialects through a type-erased enum provided by the sqmeow-adapters crate.
Description
The Backend enum wraps one of 11 concrete adapter types (SqliteAdapter, PostgresAdapter, MySqlAdapter, etc.) behind a single interface. A dispatch! macro matches the variant and forwards each method call to the inner adapter, which implements the Adapter trait. This lets the engine hold a heterogeneous set of connections without generics.
Key method groups:
- Connection:
connect_toopens a connection by URL scheme, optionally overriding the database and setting read-only mode. - Execution:
execute_resultsruns a statement returning multiple result sets;execute_bound_resultsruns with native bound values. - Editing:
plangenerates DML from staged changes;applyruns them transactionally. - Metadata:
schemas,columns,indexes,relations,routines,relationshipsdiscover catalog structure. - Dialect:
dialect()returns the connection'sDialectfor quoting and syntax decisions.
Usage
- Connection lifecycle:
connect_toopens a connection after secret expansion and tunneling. - Query execution:
execute_results/execute_bound_resultsrun validated statements. - In-grid editing:
plangenerates DML for review,applyexecutes approved statements. - Schema discovery:
schemas,columns,indexespopulate the drawer tree. - Result export:
dialect()determines SQL export quoting and CREATE TABLE syntax.
Code Reference
Source Location
- Repository: sqmeow.nvim
- File: core/sqmeow-adapters/src/lib.rs
- Lines: L140-391
Signature
pub enum Backend {
Sqlite(SqliteAdapter),
DuckDb(DuckDbAdapter),
Postgres(PostgresAdapter),
MySql(MySqlAdapter),
Redis(RedisAdapter),
MongoDb(MongoAdapter),
Scylla(ScyllaAdapter),
SurrealDb(SurrealAdapter),
ClickHouse(ClickHouseAdapter),
Oracle(OracleAdapter),
MsSql(Box<MsSqlAdapter>),
}
impl Backend {
pub async fn connect_to(url: &str, database: Option<&str>, read_only: bool) -> Result<Self>;
pub fn dialect(&self) -> Dialect;
pub async fn execute_results(&self, statement: &str, origin: &str, max_rows: usize, cancel: CancellationToken) -> Result<Vec<ResultSet>>;
pub async fn execute_bound_results(&self, statement: &str, values: &[Value], max_rows: usize, cancel: CancellationToken) -> Result<Vec<ResultSet>>;
pub fn plan(&self, result: &ResultSet, changes: &Changes) -> Result<Vec<String>>;
pub async fn apply(&self, statements: &[String], cancel: CancellationToken) -> Result<Vec<ResultSet>>;
pub async fn schemas(&self) -> Result<Vec<SchemaNode>>;
pub async fn columns(&self, schema: &str, relation: &str) -> Result<Vec<ColumnNode>>;
pub async fn indexes(&self, schema: &str, relation: &str) -> Result<Vec<IndexNode>>;
pub async fn close(&self);
}
Import
use sqmeow_adapters::Backend;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| url | &str | Yes | Expanded/tunneled connection URL |
| database | Option<&str> | No | Override database selection (Postgres, MongoDB, SurrealDB, Oracle, MSSQL) |
| read_only | bool | Yes | Session-level read-only flag |
| statement | &str | Yes | SQL to execute |
| origin | &str | Yes | Unwrapped query for column tracing |
| max_rows | usize | Yes | Row cap |
| cancel | CancellationToken | Yes | Cooperative cancellation token |
| statements | &[String] | Yes | Planned DML statements to apply |
| changes | &Changes | Yes | Staged cell edits for planning |
Outputs
| Name | Type | Description |
|---|---|---|
| connect_to | Result<Backend> /// Backend enum wrapping the live adapter | |
| execute_results | Result<Vec<ResultSet>> /// One or more retained result sets | |
| plan | Result<Vec<String>> /// Dialect-quoted DML statements | |
| apply | Result<Vec<ResultSet>> /// Rows returned by applied statements (RETURNING) | |
| schemas | Result<Vec<SchemaNode>> /// Catalog schemas | |
| columns | Result<Vec<ColumnNode>> /// Table column metadata |
Usage Examples
Opening a connection
let backend = Backend::connect_to(
"postgres://app:hunter2@localhost/dev",
None,
false,
).await?;
// Returns Backend::Postgres(PostgresAdapter { ... })
Executing a query
let results = backend.execute_results(
"SELECT * FROM users",
"SELECT * FROM users",
100_000,
cancel_token,
).await?;
// Returns Vec<ResultSet> with retained rows
Planning and applying edits
let statements = backend.plan(&result, &changes)?;
// User reviews statements, then:
let returned = backend.apply(&statements, cancel_token).await?;
Related Pages
Implements Principle
- Principle:2giosangmitom_Sqmeow_nvim_Adapter_Selection
- Principle:2giosangmitom_Sqmeow_nvim_Async_Execution
- Principle:2giosangmitom_Sqmeow_nvim_DML_Generation
- Principle:2giosangmitom_Sqmeow_nvim_Schema_Discovery
- Principle:2giosangmitom_Sqmeow_nvim_Result_Export
Requires Environment
- Environment:2giosangmitom_Sqmeow_nvim_Nix_Development_Shell
- Environment:2giosangmitom_Sqmeow_nvim_Docker_Compose_Test_Databases
- Environment:2giosangmitom_Sqmeow_nvim_Tokio_Multi_Thread_Runtime