Overview
Concrete tool for identifying database dialects from connection URLs and quoting identifiers per dialect provided by the sqmeow-db crate.
Description
The Dialect enum represents the 11 database families sqmeow.nvim supports: SQLite, DuckDB, PostgreSQL, MySQL, Redis, MongoDB, Scylla, SurrealDB, ClickHouse, Oracle, and MSSQL. Dialect::from_url infers the dialect from a connection URL's scheme (case-insensitive), recognizing aliases like postgresql, mariadb, valkey, cassandra, sqlserver, and TLS variants. Dialect::quote_ident quotes an identifier for the dialect, escaping embedded delimiters (" for standard SQL, ` for MySQL/SurrealDB, [] for MSSQL).
Usage
- Adapter selection:
Dialect::from_url determines which adapter to instantiate from a connection URL's scheme.
- SQL generation:
Dialect::quote_ident quotes table and column names in generated DML for in-grid editing and SQL export.
- Statement splitting: The dialect selects splitting rules (e.g., MSSQL uses a T-SQL batch parser).
- Guard checks: Write/danger detection rules vary per dialect.
Code Reference
Source Location
- Repository: sqmeow.nvim
- File: core/sqmeow-db/src/adapter.rs
- Lines: L22-101
Signature
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Dialect {
Sqlite, DuckDb, Postgres, MySql, Redis, MongoDb,
Scylla, SurrealDb, ClickHouse, Oracle, MsSql,
}
impl Dialect {
pub fn name(self) -> &'static str;
pub fn quote_ident(self, name: &str) -> String;
pub fn from_url(url: &str) -> Option<Self>;
}
Import
use sqmeow_db::adapter::Dialect;
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| url |
&str |
Yes |
Connection URL whose scheme identifies the dialect
|
| name |
&str |
Yes |
Identifier to quote
|
Outputs
| Name |
Type |
Description
|
| from_url |
Option<Dialect> /// Dialect variant or None for unknown scheme
|
| quote_ident |
String /// Quoted identifier with escaped delimiters
|
| name |
&'static str /// Canonical name ("sqlite", "postgres", etc.)
|
Usage Examples
Identifying a dialect from a URL
assert_eq!(Dialect::from_url("postgres://localhost/dev"), Some(Dialect::Postgres));
assert_eq!(Dialect::from_url("mariadb://localhost/db"), Some(Dialect::MySql));
assert_eq!(Dialect::from_url("valkeys://h:6379"), Some(Dialect::Redis));
assert_eq!(Dialect::from_url("unknown://h"), None);
Quoting identifiers per dialect
assert_eq!(Dialect::Postgres.quote_ident("plain"), "\"plain\"");
assert_eq!(Dialect::Postgres.quote_ident("od\"d"), "\"od\"\"d\"");
assert_eq!(Dialect::MySql.quote_ident("plain"), "`plain`");
assert_eq!(Dialect::MsSql.quote_ident("a]b"), "[a]]b]");
Related Pages
Implements Principle
Requires Environment