19 releases (stable)
| 1.3.5 | Jun 28, 2026 |
|---|---|
| 1.3.4 | Jun 11, 2026 |
| 1.3.2 | May 30, 2026 |
| 1.2.0 | Apr 29, 2026 |
| 0.1.4 | Mar 27, 2026 |
#2508 in Database interfaces
Used in 3 crates
(2 directly)
275KB
6K
SLoC
nautilus-dialect
SQL dialect renderers for the Nautilus ORM.
This crate translates query ASTs produced by nautilus-core into dialect-specific
SQL strings with bound parameters ready for execution via nautilus-connector.
Supported dialects
| Dialect | Struct | Placeholders | Quoting | RETURNING |
|---|---|---|---|---|
| PostgreSQL | PostgresDialect |
$1, $2, ... |
"name" |
yes |
| MySQL | MysqlDialect |
? |
`name` |
no (emulated) |
| SQLite | SqliteDialect |
? |
"name" |
yes (3.35+) |
Usage
use nautilus_dialect::{Dialect, PostgresDialect};
use nautilus_core::{Select, Value};
let select = Select::from_table("users")
.filter(
nautilus_core::Expr::column("email")
.eq(nautilus_core::Expr::param(Value::String("alice@example.com".into())))
)
.build()?;
let sql = PostgresDialect.render_select(&select)?;
// sql.text => SELECT * FROM "users" WHERE ("email" = $1)
// sql.params => [Value::String("alice@example.com")]
Architecture
The crate is organized as follows:
-
lib.rs— Public API:Dialecttrait,Sqlstruct, shared rendering macros (render_insert_body!,render_update_body!,render_delete_body!,render_select_body_core!,render_returning!), and shared render helpers for identifier writing and placeholder formatting. -
render_estimate.rs— Conservative SQL/params capacity estimation used by the dialect renderers to preallocateStringandVec<Value>buffers. -
postgres.rs— PostgreSQL renderer. Handles$Nplaceholders,DISTINCT ON,FILTER (WHERE ...)on aggregates, and@>/<@/&&array operators. -
mysql.rs— MySQL renderer. Uses?placeholders and backtick quoting. EmitsLIMIT 18446744073709551615when onlyOFFSETis requested (MySQL requiresLIMITbeforeOFFSET).RETURNINGis silently omitted. -
sqlite.rs— SQLite renderer. Uses?placeholders and ANSI double-quote quoting. SupportsRETURNING(SQLite 3.35+) and nativeFILTER (WHERE ...)on aggregates.
Array operators
PostgreSQL natively supports @> (contains), <@ (contained by), and &&
(overlaps) array operators via BinaryOp::ArrayContains,
BinaryOp::ArrayContainedBy, and BinaryOp::ArrayOverlaps.
MySQL emulates contains / contained-by via JSON_CONTAINS(target, candidate).
The generic MysqlDialect intentionally rejects overlap rendering because the
workspace-wide "mysql" provider also covers MySQL-family backends where
JSON_OVERLAPS is not guaranteed. SQLite uses json_each + correlated
EXISTS predicates so JSON null elements are preserved instead of being
lost to IN / NOT IN null semantics. Arrays are bound as JSON strings by
the connector layer, so no special client-side handling is needed.
Dependencies
~2.5–4MB
~75K SLoC