Expand description
SQL Query Builder Utilities
Provides a type-safe, fluent API for constructing dynamic SQL queries.
§Overview
The query builder helps construct complex SQL queries programmatically while maintaining type safety and preventing SQL injection through parameter binding.
§Features
- Fluent API: Chain methods to build queries naturally
- Type Safety: Compile-time checks for query structure
- Parameter Binding: Automatic SQL injection protection
- Dynamic Filters: Conditionally add WHERE clauses
- Sorting: Type-safe ORDER BY clauses
- Pagination: LIMIT and OFFSET support
- Aggregations: COUNT, SUM, AVG, MIN, MAX support
§Example
use oxify_storage::query_builder::{QueryBuilder, Condition, SortOrder};
let mut builder = QueryBuilder::new("workflows")
.select(&["id", "name", "created_at"])
.where_condition(Condition::Eq("user_id".to_string()))
.where_condition(Condition::IsNotNull("deleted_at".to_string()))
.order_by("created_at", SortOrder::Desc)
.limit(20)
.offset(0);
let (sql, param_count) = builder.build();
// SELECT id, name, created_at FROM workflows
// WHERE user_id = $1 AND deleted_at IS NOT NULL
// ORDER BY created_at DESC LIMIT 20 OFFSET 0Structs§
- Delete
Builder - Builder for DELETE queries
- Join
- JOIN clause definition
- Query
Builder - SQL query builder for SELECT statements
- Update
Builder - Builder for UPDATE queries