This documentation provides an overview of the functions available in the builder module. These functions assist in constructing SQL queries using DW SQL Builder.
-
condition(lvalue: String | Number, op: UnaryOperator): Condition
Creates a simple condition with a unary operator. The
lvalue
represents the value to be compared, and theop
represents the unary operator used in the condition. -
condition(lvalue: String | Number, op: Operator, rvalue: String | Number): Condition
Creates a simple condition with a binary operator. The
lvalue
represents the left value to be compared, theop
represents the binary operator used in the condition, and thervalue
represents the right value to be compared. -
condition(func: (Condition) -> SQLStruct, condition: String): SQLStruct
Applies a function to a condition. The
func
is a function that takes a condition as an argument and returns an SQLStruct. Thecondition
parameter is the condition to be passed to the function. -
AND(lCondition: Condition, rCondition: Condition): Condition
Combines two conditions using the logical AND operator.
-
OR(lCondition: Condition, rCondition: Condition): Condition
Combines two conditions using the logical OR operator.
-
BETWEEN(col: String, fst: Value): (Value) -> Between
Creates a condition that checks if a column value is between two specified values. The
col
parameter represents the column name, and thefst
parameter represents the first value of the range. The function returns a function that takes the second value of the range and returns a Between condition. -
AND(func: (String) -> Between, snd: Value): Between
Applies a function that creates a Between condition with a column name and the first value of the range and combines it with the second value using the logical AND operator.
-
NOT(condition: Condition): Condition
Negates a condition using the logical NOT operator.
-
columns(sql: SQLStruct, cols: Array<Column> | "*"): SQLStruct
Sets the columns to be selected in the SQLStruct. The
sql
parameter is the SQLStruct, and thecols
parameter is either an array of column names or "*" to select all columns. -
appendColumn(sql: SQLStruct, col: Column): SQLStruct
Appends a column to the list of columns to be selected in the SQLStruct.
-
FROM(sql: SQLStruct, table: Table | SQLStruct): SQLStruct
Sets the table or SQLStruct to retrieve data from in the SQLStruct.
-
WHERE(sql: SQLStruct, where: Condition): SQLStruct
Sets the condition for filtering the data in the SQLStruct.
-
WHERE(sql: SQLStruct, not: (Condition) -> Condition): (Condition) -> SQLStruct
Applies a function that creates a negated condition to the WHERE clause in the SQLStruct.
-
GROUPBY(sql: SQLStruct, cols: Array<Column>): SQLStruct
Sets the columns for grouping the data in the SQLStruct.
-
HAVING(sql: SQLStruct, condition: Condition): SQLStruct
Sets the condition for filtering the grouped data in the SQLStruct.
-
HAVING(sql: SQLStruct, not: (Condition) -> Condition): (Condition) -> SQLStruct
Applies a function that creates a negated condition to the HAVING clause in the SQLStruct.
-
ORDERBY(sql: SQLStruct, cols: Array<Column>): SQLStruct
Sets the columns for ordering the data in the SQLStruct.
-
LIMIT(sql: SQLStruct, limit: Number): SQLStruct
Sets the limit on the number of records to be retrieved in the SQLStruct.
-
INNERJOIN(leftTable: Table, rightTable: Table): JoinedTable
Creates a joined table using the INNER JOIN operation.
-
FULLJOIN(leftTable: Table, rightTable: Table): JoinedTable
Creates a joined table using the FULL JOIN operation.
-
LEFTJOIN(leftTable: Table, rightTable: Table): JoinedTable
Creates a joined table using the LEFT JOIN operation.
-
RIGHTJOIN(leftTable: Table, rightTable: Table): JoinedTable
Creates a joined table using the RIGHT JOIN operation.
-
ON(join: JoinedTable, condition: Condition): Table
Specifies the join condition for a joined table.
-
AS(table: String, alias: String): Table
Specifies an alias for a table.
-
build(sql: SQLStruct, flag: Boolean = true, indent: String = ""): SQLQuery
Builds the SQL query string from the SQLStruct. The
flag
parameter indicates whether to include the query's parentheses, theindent
parameter specifies the indentation for subqueries, and the function returns the SQL query string.