Crate rust_queries_builder

Crate rust_queries_builder 

Source
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::Keypath;

#[derive(Clone, Keypath)]
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§

datetime
DateTime operations for query builder.
ext
join
Join query implementation for combining multiple collections.
lazy
Lazy query implementation using iterators.
lock_ext
Extended lock support for parking_lot and tokio.
lock_join
JOIN operations for locked data structures.
lock_lazy
Lazy query support for locked data structures.
lock_query
Full SQL-like query support for locked data structures.
lock_view
View-like functionality for locked data.
locks
Lock-aware querying for thread-safe data structures.
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§

JoinQuery
A query builder for joining two collections.
LazyQuery
A lazy query builder that uses iterators for deferred execution.
LockJoinQuery
A join query builder for locked data structures.
LockLazyQuery
Lazy query for locked data with early termination.
LockQuery
A query builder for locked data structures.
LockView
A reusable query pattern (like a SQL VIEW).
LockedValueRef
A reference to a value behind a lock.
MaterializedLockView
Materialized view - a cached query result.
Query
A query builder for filtering, selecting, ordering, grouping, and aggregating data.
QueryWithSkip
Helper struct for pagination after a skip operation.

Enums§

KeyPaths
Go to examples section to see the implementations

Traits§

LockIterExt
Extension methods for lock iterators.
LockJoinable
Helper trait for creating join queries from locked collections.
LockJoinableCollection
Helper trait for collections that can participate in joins.
LockLazyQueryable
Extension trait for creating lazy lock queries.
LockQueryExt
Extension trait for querying collections of locks.
LockQueryable
Helper to create LockQuery from HashMap.
LockValue
Helper trait for lock-aware value extraction.
QueryExt
Extension trait that adds eager Query methods directly to slice-like containers
Queryable
Trait for types that can be queried.
QueryableExt
Extension trait for Queryable types that provides query building capabilities.

Derive Macros§

Keypath
QueryBuilder
Derive macro to generate helper methods for query building
QueryableDerive
Derive macro to generate Queryable implementations