SQL Builders
Oxide SQL provides type-safe builders for common SQL statements. Each builder uses the typestate pattern to ensure valid SQL at compile time.
Available Builders
- SELECT - Query data from tables
- INSERT - Insert new rows
- UPDATE - Modify existing rows
- DELETE - Remove rows
Typed vs String-Based Builders
Oxide SQL offers two levels of type safety:
String-Based Builders (This Section)
Use column names as strings. Good for dynamic queries or quick prototyping.
Typed Builders (Recommended)
Use #[derive(Table)] for compile-time column validation. Invalid column
names won't compile.
See Schema > Typed Queries for full typed builder documentation.
The Typestate Pattern
All builders use Rust's type system to enforce SQL validity at compile time. This means:
- Required clauses are enforced - You can't build a SELECT without FROM
- Order is enforced - WHERE must come after FROM
- Invalid combinations fail to compile - No runtime errors for SQL syntax
Expressions
All builders use the same expression system for WHERE clauses, supporting comparisons, null checks, range checks, and logical operators.
Parameterized Queries
All values are automatically parameterized to prevent SQL injection. The
params vector should be passed to your database driver for safe execution.
API Reference
See the builder module rustdoc for the dynamic builders and the typed builder module rustdoc for compile-time validated builders with full code examples.