README

jaredzhou/foxql/builder does not have a README file

#
AnyColumn

pub trait AnyColumn {
fn name(Self) -> String
fn table_name(Self) -> String
fn sql_type(Self) -> String
}

Trait that erases T — exposes column identity for heterogeneous column lists.

#
Comparable

pub trait Comparable {
fn compare(Self) -> Unit
}

Trait for types that support comparison operators (gt, gte, lt, lte, between).
impl Comparable for Int

#
StringMatchable

pub trait StringMatchable {
fn str_match(Self) -> Unit
}

Trait for types that support string operators (like, not_like).

#
Column

pub(all) struct Column[T] {
name : String
table : String
sql_type : String
_marker : T?
} derive(Eq,
Debug
)

A typed column reference in a specific table.
impl AnyColumn for Column[T]

#
Column::asc

Sort ascending.

#
Column::desc

Sort descending.

#
Column::eq_col

fn[T] Column::eq_col(self : Column[T], other : Column[T]) ->
Expr

Compare two columns for equality (for JOIN ON).

#
Column::eq_select

Compare column with a scalar subquery.

#
Column::gt_select

#
Column::gte_select

#
Column::in_select

#
Column::is_not_null

fn[T] Column::is_not_null(self : Column[T]) ->
Expr

#
Column::is_null

fn[T] Column::is_null(self : Column[T]) ->
Expr

#
Column::like

fn[T : StringMatchable] Column::like(self : Column[T], pattern : String) ->
Expr

#
Column::lt_select

#
Column::lte_select

#
Column::neq_select

#
Column::new

fn[T] Column::new(name : String, table : String, sql_type : String) -> Column[T]

Create a new column reference.

#
Column::not_like

fn[T : StringMatchable] Column::not_like(self : Column[T], pattern : String) ->
Expr

#
Column::to_ref

Produce a type-erased ColumnRef.

#
DeleteBuilder

pub(all) struct DeleteBuilder {
table : Table
} derive(Eq,
Debug
)

A pending DELETE builder. Must call .where_() before .to_sql().

#
DeleteBuilder::new

fn DeleteBuilder::new(table : Table) -> DeleteBuilder

Create a new DeleteBuilder. Internal — users call table.delete().

#
DeleteBuilder::where_

Attach a WHERE clause. Promotes to DeleteReady.

#
DeleteReady

pub(all) struct DeleteReady {
table : Table
where_clause :
Expr

returning : Array[
ColumnRef
]?
}

A complete DELETE builder with a WHERE clause. Terminal: .to_sql().

#
DeleteReady::returning

fn DeleteReady::returning(self : DeleteReady, cols : Array[&AnyColumn]) -> DeleteReady

Attach a RETURNING clause.

#
DeleteReady::to_sql

Render the query to a parameterised SQL string + args array.

#
DeleteReady::where_

Attach another WHERE condition, AND-ed with the existing one.

#
InsertBuilder

A fluent builder for an INSERT query. Terminal: .to_sql().

#
InsertBuilder::do_nothing

fn InsertBuilder::do_nothing(self : InsertBuilder) -> InsertBuilder

ON CONFLICT DO NOTHING.

#
InsertBuilder::do_update

ON CONFLICT DO UPDATE SET column = value.

#
InsertBuilder::new

fn InsertBuilder::new(table : Table, columns : Array[&AnyColumn]) -> InsertBuilder

Create a new InsertBuilder. Internal — users call table.insert(..) instead.

#
InsertBuilder::on_conflict

fn InsertBuilder::on_conflict(self : InsertBuilder, cols : Array[&AnyColumn]) -> InsertBuilder

Set the ON CONFLICT target column(s).

#
InsertBuilder::returning

fn InsertBuilder::returning(self : InsertBuilder, cols : Array[&AnyColumn]) -> InsertBuilder

Attach a RETURNING clause.

#
InsertBuilder::rows

Add a multi-row VALUES clause.

#
InsertBuilder::to_sql

Render the query to a parameterised SQL string + args array.

#
InsertBuilder::values

Add a single-row VALUES clause.

#
SelectBuilder

A fluent builder for a SELECT query. Terminal: .to_sql() or .build().

#
SelectBuilder::agg

Add an aggregate expression to the SELECT list.

#
SelectBuilder::build

Produce the AST node without rendering.

#
SelectBuilder::distinct

fn SelectBuilder::distinct(self : SelectBuilder) -> SelectBuilder

Add SELECT DISTINCT.

#
SelectBuilder::distinct_on

fn SelectBuilder::distinct_on(self : SelectBuilder, cols : Array[&AnyColumn]) -> SelectBuilder

Add SELECT DISTINCT ON (columns).

#
SelectBuilder::group_by

fn SelectBuilder::group_by(self : SelectBuilder, cols : Array[&AnyColumn]) -> SelectBuilder

Add a GROUP BY clause.

#
SelectBuilder::having

Attach a HAVING clause (must be after GROUP BY).

#
SelectBuilder::join

Add an INNER JOIN clause.

#
SelectBuilder::limit

fn SelectBuilder::limit(self : SelectBuilder, n : Int) -> SelectBuilder

Attach a LIMIT clause.

#
SelectBuilder::new

Create a new SelectBuilder. Internal — users call table.select(..) instead.

#
SelectBuilder::offset

fn SelectBuilder::offset(self : SelectBuilder, n : Int) -> SelectBuilder

Attach an OFFSET clause.

#
SelectBuilder::order_by

Add an ORDER BY clause. Chain multiple times for multiple columns.

#
SelectBuilder::to_sql

Render the query to a parameterised SQL string + args array.

#
SelectBuilder::where_

Attach a WHERE condition, AND-ed with any existing conditions. Call multiple times to build up filters from different layers.

#
Table

pub(all) struct Table {
name : String
schema_name : String?
} derive(Eq,
Debug
)

Table identity — name and optional schema.

#
Table::delete

fn Table::delete(self : Table) -> DeleteBuilder

Start building a DELETE query on this table. Requires .where_() before .to_sql().

#
Table::insert

fn Table::insert(self : Table, columns : Array[&AnyColumn]) -> InsertBuilder

Start building an INSERT query on this table.

#
Table::new

fn Table::new(name : String, schema? : String) -> Table

Create a table, optionally qualified with a schema.

#
Table::qualified_name

fn Table::qualified_name(self : Table) -> String

Return the fully-qualified table name for use in SQL (schema.name or name).

#
Table::select

fn Table::select(self : Table, columns? : Array[&AnyColumn]) -> SelectBuilder

Start building a SELECT query on this table. Omit columns for SELECT *.

#
Table::update

fn Table::update(self : Table) -> UpdateBuilder

Start building an UPDATE query on this table. Requires .where_() before .to_sql().

#
UpdateBuilder

pub(all) struct UpdateBuilder {
table : Table
set_clauses : Array[
SetClause
]
}

A pending UPDATE builder. Must call .where_() before .to_sql().

#
UpdateBuilder::new

fn UpdateBuilder::new(table : Table) -> UpdateBuilder

Create a new UpdateBuilder. Internal — users call table.update().

#
UpdateBuilder::set

Add a SET clause. Column as &AnyColumn, value as &@moonpg.ToValue.

#
UpdateBuilder::where_

Attach a WHERE clause. Promotes to UpdateReady.

#
UpdateReady

pub(all) struct UpdateReady {
table : Table
set_clauses : Array[
SetClause
]
where_clause :
Expr

returning : Array[
ColumnRef
]?
}

A complete UPDATE builder with a WHERE clause. Terminal: .to_sql().

#
UpdateReady::returning

fn UpdateReady::returning(self : UpdateReady, cols : Array[&AnyColumn]) -> UpdateReady

Attach a RETURNING clause.

#
UpdateReady::to_sql

Render the query to a parameterised SQL string + args array.

#
UpdateReady::where_

Attach another WHERE condition, AND-ed with the existing one.

#
count_star

COUNT(*) — count all rows.