Skip to main content

Module builder

Module builder 

Source
Expand description

Fluent SQL Builder API

Provides a programmatic way to construct SQL Expression trees without parsing raw SQL strings. The API mirrors Python sqlglot’s builder functions (select(), from_(), condition(), etc.) and is the primary entry point for constructing queries programmatically in Rust.

§Design

The builder is organized around a few key concepts:

§Examples

use polyglot_sql::builder::*;

// SELECT id, name FROM users WHERE age > 18 ORDER BY name LIMIT 10
let expr = select(["id", "name"])
    .from("users")
    .where_(col("age").gt(lit(18)))
    .order_by(["name"])
    .limit(10)
    .build();
use polyglot_sql::builder::*;

// CASE WHEN x > 0 THEN 'positive' ELSE 'non-positive' END
let expr = case()
    .when(col("x").gt(lit(0)), lit("positive"))
    .else_(lit("non-positive"))
    .build();
use polyglot_sql::builder::*;

// SELECT id FROM a UNION ALL SELECT id FROM b ORDER BY id LIMIT 5
let expr = union_all(
    select(["id"]).from("a"),
    select(["id"]).from("b"),
)
.order_by(["id"])
.limit(5)
.build();

Structs§

CaseBuilder
Fluent builder for SQL CASE expressions (both searched and simple forms).
DeleteBuilder
Fluent builder for constructing DELETE FROM statements.
Expr
A thin wrapper around Expression that provides fluent operator methods.
InsertBuilder
Fluent builder for constructing INSERT INTO statements.
MergeBuilder
Fluent builder for constructing MERGE INTO statements.
SelectBuilder
Fluent builder for constructing SELECT statements.
SetOpBuilder
Fluent builder for UNION, INTERSECT, and EXCEPT set operations.
UpdateBuilder
Fluent builder for constructing UPDATE statements.
WindowDefBuilder
Builder for constructing named WINDOW clause definitions.

Traits§

IntoExpr
Conversion trait for types that can be turned into an Expr.
IntoLiteral
Conversion trait for types that can be turned into a SQL literal Expr.

Functions§

alias
Create an expr AS name alias expression.
and
Combine two expressions with AND.
boolean
Create a SQL boolean literal expression (TRUE or FALSE).
case
Start building a searched CASE expression (CASE WHEN cond THEN result ... END).
case_of
Start building a simple CASE expression (CASE operand WHEN value THEN result ... END).
cast
Create a CAST(expr AS type) expression.
col
Create a column reference expression.
condition
Parse a SQL condition string into an Expr.
delete
Start building a DELETE FROM statement targeting the given table.
except_
Create an EXCEPT (rows in left but not right) of two SELECT queries.
except_all
Create an EXCEPT ALL (keep duplicate difference rows) of two SELECT queries.
from
Start building a SELECT query beginning with a FROM clause.
func
Create a SQL function call expression.
insert_into
Start building an INSERT INTO statement targeting the given table.
intersect
Create an INTERSECT (rows common to both) of two SELECT queries.
intersect_all
Create an INTERSECT ALL (keep duplicate common rows) of two SELECT queries.
lit
Create a literal expression from any type implementing IntoLiteral.
merge_into
Start building a MERGE INTO statement targeting the given table.
not
Create a NOT expr unary expression.
null
Create a SQL NULL literal expression.
or
Combine two expressions with OR.
select
Start building a SELECT query with the given column expressions.
sql_expr
Parse a raw SQL expression fragment into an Expr.
star
Create a star (*) expression, typically used in SELECT *.
subquery
Wrap a SelectBuilder as a named subquery for use in FROM or JOIN clauses.
subquery_expr
Wrap an existing Expression as a named subquery.
table
Create a table reference expression.
union
Create a UNION (duplicate elimination) of two SELECT queries.
union_all
Create a UNION ALL (keep duplicates) of two SELECT queries.
update
Start building an UPDATE statement targeting the given table.