Expand description
SQL generation utilities.
This module provides optimized SQL generation with:
- Pre-allocated string buffers
- Zero-copy placeholder generation for common cases
- Batch placeholder generation for IN clauses
- SQL template caching for common query patterns
- Static SQL keywords to avoid allocations
- Lazy SQL generation for deferred execution
Modules§
- keywords
- Static SQL keywords to avoid repeated allocations.
- templates
- Pre-built SQL templates for common query patterns.
Structs§
- Cached
Sql - A cached lazy SQL that stores previously generated SQL for each database type.
- Fast
SqlBuilder - An optimized SQL builder that uses a single String buffer.
- LazySql
- A lazily-generated SQL string that defers construction until needed.
- SqlBuilder
- A SQL builder for constructing queries.
- SqlTemplate
Cache - A thread-safe cache for SQL templates.
Enums§
- Advanced
Query Capacity - Extended capacity hints for advanced query types.
- Database
Type - Build a parameter placeholder for a given database type.
- Query
Capacity - Capacity hints for different query types.
Constants§
- MYSQL_
IN_ PATTERNS - Pre-computed IN clause placeholder patterns for MySQL/SQLite. Format: “?, ?, ?, …” for common sizes (1-32 elements).
- POSTGRES_
PLACEHOLDERS - Pre-computed PostgreSQL placeholder strings for indices 1-256.
This avoids
format!calls for the most common parameter counts. Index 0 is unused (placeholders start at $1), but kept for simpler indexing. Pre-computed PostgreSQL parameter placeholders ($1-$256).
Functions§
- escape_
identifier - Escape a string for use in SQL (for identifiers, not values).
- global_
sql_ cache - Global SQL template cache for common query patterns.
- needs_
quoting - Check if an identifier needs quoting.
- postgres_
in_ pattern - Get a pre-computed PostgreSQL IN placeholder pattern. Returns patterns like “$1, $2, $3” for count=3 starting at start_idx=1.
- quote_
identifier - Quote an identifier if needed.
- write_
postgres_ in_ pattern - Write PostgreSQL IN placeholders directly to a buffer.