Expand description
Optimized builder patterns for query construction.
This module provides memory-efficient builder types that minimize allocations:
SmallVecfor small collections (partition columns, order by, etc.)Cow<'static, str>for identifiers that are often staticSmolStrfor inline small strings (< 24 bytes stored inline)- Reusable builders that can be reset and reused
§Performance Characteristics
| Type | Stack Size | Inline Capacity | Heap Allocation |
|---|---|---|---|
SmallVec<[T; 8]> | 64+ bytes | 8 elements | > 8 elements |
SmolStr | 24 bytes | 22 chars | > 22 chars |
Cow<'static, str> | 24 bytes | N/A | Only if owned |
Identifier | 24 bytes | 22 chars | > 22 chars |
§Example
use prax_query::builder::{Identifier, ColumnList, ReusableBuilder};
// Identifier that stores small strings inline
let col = Identifier::new("user_id"); // No heap allocation
let long_col = Identifier::new("very_long_column_name_here"); // May heap allocate
// Column list optimized for typical use (1-8 columns)
let mut cols = ColumnList::new();
cols.push("id");
cols.push("name");
cols.push("email"); // Still on stack!
// Reusable builder pattern
let mut builder = ReusableBuilder::new();
builder.push("SELECT * FROM users");
let sql1 = builder.build();
builder.reset(); // Reuse the allocation
builder.push("SELECT * FROM posts");
let sql2 = builder.build();Structs§
- Builder
Pool - A pool of reusable builders for high-throughput scenarios.
- CowIdentifier
- A copy-on-write identifier that borrows static strings without allocation.
- Identifier
- An identifier (column name, table name, alias) optimized for small strings.
- Optimized
Window Spec - An optimized window specification using SmallVec for partition/order columns.
- Reusable
Builder - A reusable string builder that can be reset and reused.
- Window
Frame - Window frame specification.
Enums§
- Frame
Bound - Frame bound specification.
- Frame
Type - Frame type for window functions.
Type Aliases§
- Column
List - A list of columns optimized for typical use cases (1-8 columns).
- Column
Name List - A list of column names as strings, optimized for 1-8 columns.
- CowColumn
List - A list of column names as Cow strings for zero-copy static columns.
- Expr
List - A list of expressions, optimized for 1-8 items.
- Order
ByList - A list of sort orders, optimized for 1-4 ORDER BY columns.
- Partition
ByList - A list of partition columns, optimized for 1-4 PARTITION BY columns.
- Value
List - A list of values, optimized for 1-16 items (e.g., IN clauses).