Expand description
§Rust Query Builder
A powerful, type-safe query builder library for Rust that leverages key-paths for SQL-like operations on in-memory collections.
§Features
- Type-safe queries: Compile-time type checking using key-paths
- SQL-like operations: WHERE, SELECT, ORDER BY, GROUP BY, JOIN
- Aggregations: COUNT, SUM, AVG, MIN, MAX
- Pagination: LIMIT and SKIP operations
- Join operations: INNER JOIN, LEFT JOIN with custom predicates
- Zero-cost abstractions: Leverages Rust’s zero-cost abstractions
§Example
use rust_queries_builder::{Query, QueryExt};
use key_paths_derive::Keypaths;
#[derive(Clone, Keypaths)]
struct Product {
id: u32,
name: String,
price: f64,
category: String,
}
let products = vec![
Product { id: 1, name: "Laptop".to_string(), price: 999.99, category: "Electronics".to_string() },
Product { id: 2, name: "Mouse".to_string(), price: 29.99, category: "Electronics".to_string() },
];
// Using extension trait - most ergonomic
let query = products.query().where_(Product::category_r(), |cat| cat == "Electronics");
let electronics = query.all();
// Traditional approach
let affordable = Query::new(&products)
.where_(Product::price_r(), |&price| price < 100.0)
.all();
// Lazy evaluation for better performance
let total = products.lazy_query().sum_by(Product::price_r());Modules§
- ext
- join
- Join query implementation for combining multiple collections.
- lazy
- Lazy query implementation using iterators.
- macros
- Macros to simplify query building and reduce boilerplate.
- query
- Query builder implementation for filtering, selecting, ordering, grouping, and aggregating data.
- queryable
- Queryable trait for supporting multiple container types.
Macros§
- avg_
where - Quick average aggregation.
- collect_
lazy - Creates a lazy query and collects results in one line.
- count_
where - Quick count with filter.
- exists_
where - Check if any item matches.
- filter
- Simplified where_ macro that reduces boilerplate.
- filter_
collect - Quick filter and collect.
- find_
first - Find first matching item.
- lazy_
query - Creates a lazy query with multiple filters in a concise syntax.
- paginate
- Quick pagination.
- query
- Creates a Query with multiple filters in a concise syntax.
- select_
all - Select and collect in one line.
- select_
where - Select with filter.
- sum_
where - Quick sum aggregation.
Structs§
- Join
Query - A query builder for joining two collections.
- Lazy
Query - A lazy query builder that uses iterators for deferred execution.
- Query
- A query builder for filtering, selecting, ordering, grouping, and aggregating data.
- Query
With Skip - Helper struct for pagination after a skip operation.
Enums§
- KeyPaths
- Go to examples section to see the implementations
Traits§
- Query
Ext - Extension trait that adds query methods directly to containers
- Queryable
- Trait for types that can be queried.
Derive Macros§
- Query
Builder - Derive macro to generate helper methods for query building
- Queryable
Derive - Derive macro to generate Queryable implementations