surql-rs
A code-first database toolkit for SurrealDB. Define schemas, generate migrations, build queries, and perform typed CRUD -- all from Rust.
Features
- Code-First Migrations - Schema changes defined in code with automatic migration generation (auto-diff,
.surqlfile output with-- @up/-- @downsections, squash, hooks). - Type-Safe Query Builder - Immutable fluent API with operator-typed
where_, expression helpers, serde integration, and first-classQuery::execute/Query::select_expr. - Query UX Helpers -
type_record/type_thing,extract_many/has_result,aggregate_records+AggregateOptshoisted to the crate root. - Async-First - Tokio-based client on
surrealdb3.x with connection pooling, retry logic, and buffered transactions. - Vector Search - HNSW and MTREE index support with 8 distance metrics and EFC/M tuning.
- Graph Traversal - Native SurrealDB graph features with edge relationships (v3-compatible arrow chains).
- Schema Visualization - Mermaid, GraphViz, and ASCII diagrams with theming.
- CLI Tools - Full
surqlbinary (migrate,schema,db,orchestrate) behind theclifeature. - Optional subsystems -
cache(memory + Redis),settings,orchestration,watcherfeature flags.
Quick Start
cargo add oneiriq-surql
Pure-Rust TLS (no openssl-sys, recommended for CI runners without
libssl-dev):
cargo add oneiriq-surql --no-default-features --features client-rustls
With the CLI:
cargo install oneiriq-surql --features cli
TLS backends
client(default) -- async client backed bynative-tls; linksopenssl-syson Linux, Security.framework on macOS.client-rustls-- same client surface, pure-Rust TLS viarustlswebpki-roots. No system OpenSSL needed. See docs/features.md.
Define a schema
use ;
use ;
let user_schema = table_schema
.mode
.field
.field
.field
.field
.index
.build?;
Execute a typed query
use ;
use ConnectionConfig;
use Query;
use ;
use eq;
let client = new?;
client.connect.await?;
// First-class target: `type::record('user', 'alice')`.
let target = type_record.to_surql;
// Typed select projection + `.execute(&client)` on the builder.
let raw = new
.select_expr
.from_table?
.where_
.group_all
.execute
.await?;
for row in extract_many
Aggregate with AggregateOpts
use ;
use ;
use eq;
let rows = aggregate_records
.await?;
Documentation
Full documentation at oneiriq.github.io/surql-rs.
Selected pages:
- Feature flags - picking a profile.
- Query UX helpers - the 0.2 crate-root helpers.
- SurrealDB v3 patterns - what changed rebasing on the 3.x driver.
- CLI reference - the full
surqlbinary. - Upgrading 0.1 -> 0.2 - API deltas.
Requirements
- Rust 1.90+
- SurrealDB 3.0+
License
Apache License 2.0 - see LICENSE.
Python / TypeScript / Go
- Python: surql-py -- the original, reference implementation (Python 3.12+).
- TypeScript / Deno / Node.js: surql -- type-safe query builder and client.
- Go: surql-go -- Go port of this library, sharing the same schema + migration model.
Support
- Documentation: oneiriq.github.io/surql-rs
- Issues: GitHub Issues
- Changelog: CHANGELOG.md