Module builder

Module builder 

Source
Expand description

Optimized builder patterns for query construction.

This module provides memory-efficient builder types that minimize allocations:

  • SmallVec for small collections (partition columns, order by, etc.)
  • Cow<'static, str> for identifiers that are often static
  • SmolStr for inline small strings (< 24 bytes stored inline)
  • Reusable builders that can be reset and reused

§Performance Characteristics

TypeStack SizeInline CapacityHeap Allocation
SmallVec<[T; 8]>64+ bytes8 elements> 8 elements
SmolStr24 bytes22 chars> 22 chars
Cow<'static, str>24 bytesN/AOnly if owned
Identifier24 bytes22 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§

BuilderPool
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.
OptimizedWindowSpec
An optimized window specification using SmallVec for partition/order columns.
ReusableBuilder
A reusable string builder that can be reset and reused.
WindowFrame
Window frame specification.

Enums§

FrameBound
Frame bound specification.
FrameType
Frame type for window functions.

Type Aliases§

ColumnList
A list of columns optimized for typical use cases (1-8 columns).
ColumnNameList
A list of column names as strings, optimized for 1-8 columns.
CowColumnList
A list of column names as Cow strings for zero-copy static columns.
ExprList
A list of expressions, optimized for 1-8 items.
OrderByList
A list of sort orders, optimized for 1-4 ORDER BY columns.
PartitionByList
A list of partition columns, optimized for 1-4 PARTITION BY columns.
ValueList
A list of values, optimized for 1-16 items (e.g., IN clauses).