Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:2giosangmitom Sqmeow nvim Backend

From Leeroopedia
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_to opens a connection by URL scheme, optionally overriding the database and setting read-only mode.
  • Execution: execute_results runs a statement returning multiple result sets; execute_bound_results runs with native bound values.
  • Editing: plan generates DML from staged changes; apply runs them transactionally.
  • Metadata: schemas, columns, indexes, relations, routines, relationships discover catalog structure.
  • Dialect: dialect() returns the connection's Dialect for quoting and syntax decisions.

Usage

  • Connection lifecycle: connect_to opens a connection after secret expansion and tunneling.
  • Query execution: execute_results / execute_bound_results run validated statements.
  • In-grid editing: plan generates DML for review, apply executes approved statements.
  • Schema discovery: schemas, columns, indexes populate 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

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment