Module sql

Module sql 

Source
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§

CachedSql
A cached lazy SQL that stores previously generated SQL for each database type.
FastSqlBuilder
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.
SqlTemplateCache
A thread-safe cache for SQL templates.

Enums§

AdvancedQueryCapacity
Extended capacity hints for advanced query types.
DatabaseType
Build a parameter placeholder for a given database type.
QueryCapacity
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.