Surrealix is a type-safe query builder for SurrealDB that brings compile-time query validation and type inference to your Rust projects. It analyzes your database schema and queries at compile time to ensure type safety and provide rich IDE support.
- 🔍 Compile-time Query Validation: Catch query errors before runtime
- 🎯 Type Inference: Automatically derive Rust types from your SurrealDB schema
- 🚀 Zero Runtime Overhead: All analysis happens at compile time
- 💡 Rich IDE Support: Get autocompletion and type hints for your queries
- 🔒 Type-safe Record Links: Properly typed relationships between tables
- 🌐 Framework Integration: (Coming Soon)
- React/Next.js bindings
- SvelteKit bindings
- More frameworks planned
Add Surrealix to your Cargo.toml
:
[dependencies]
surrealix = "0.1.0"
- Define your schema:
DEFINE TABLE user SCHEMAFULL;
DEFINE FIELD name ON user TYPE string;
DEFINE FIELD age ON user TYPE number;
DEFINE FIELD tags ON user TYPE array;
DEFINE FIELD tags.* ON user TYPE string;
- Create a
.env
file in your project root:
SURREALIX_SCHEMA_PATH=./schema.surql
- Use the query builder:
use surrealix_macros::build_query;
build_query! {
AdultUsers,
"SELECT name FROM user WHERE age > 18;"
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let adults = AdultUsers::execute()?;
for user in adults {
println!("Adult user: {}", user.name);
}
Ok(())
}
Surrealix works by:
- Reading your SurrealDB schema at compile time
- Analyzing your queries for correctness
- Generating type-safe Rust code
- Providing a runtime that efficiently executes the queries
build_query! {
UserWithFriends,
"SELECT *, ->friend->user.name as friend_names FROM user;"
}
build_query! {
UserProfile,
"SELECT
name,
tags,
->posted->article.* as articles
FROM user
FETCH articles;"
}
We welcome contributions! Please see our Contributing Guide for details.
- Rust (latest stable)
- SurrealDB
- Node.js (for web framework integrations)
# Clone the repository
git clone https://github.com/yourusername/surrealix.git
cd surrealix
# Run tests
cargo test
# Run examples
cargo run --example basic
- Complete Web Framework Integrations
- Query Parameter Support
- Transaction Support
- Migration Tools
- CLI Tools
- Query Performance Optimization
This project is licensed under the MIT License - see the LICENSE file for details.
- SurrealDB team for creating an amazing database
- Rust community for inspiration and support