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;
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() },
];

// Filter products by category and price
let affordable = Query::new(&products)
    .where_(Product::category_r(), |cat| cat == "Electronics")
    .where_(Product::price_r(), |&price| price < 100.0)
    .all();

// Order by price
let sorted = Query::new(&products)
    .order_by_float(Product::price_r());

// Aggregate
let total = Query::new(&products)
    .sum(Product::price_r());

Re-exports§

pub use query::Query;
pub use query::QueryWithSkip;
pub use join::JoinQuery;
pub use lazy::LazyQuery;

Modules§

join
Join query implementation for combining multiple collections.
lazy
Lazy query implementation using iterators.
query
Query builder implementation for filtering, selecting, ordering, grouping, and aggregating data.

Enums§

KeyPaths
Go to examples section to see the implementations