QueryBuilder
QueryBuilderInterface<T>
Methods:
- createView(name: string): QueryBuilderInterface<T>- name: The name of the virtual table or view. Returns:- QueryBuilderInterface<T>. Allows continuing the chain of calls to build the query.
- select(columns?: string[]): QueryBuilderInterface<T>- columns(optional): An array of column names to select. If not specified, all columns are selected. Returns:- QueryBuilderInterface<T>. Allows adding columns to the selection.
- into(name: string): QueryBuilderInterface<T>- name: The name of the table into which the insertion will occur. Returns:- QueryBuilderInterface<T>. Allows specifying the table for insertion.
- sum(column: string): QueryBuilderInterface<T>- column: The name of the column to sum. Returns:- QueryBuilderInterface<T>. Adds a sum function.
- count(column: string): QueryBuilderInterface<T>- column: The name of the column to count. Returns:- QueryBuilderInterface<T>. Adds a count function.
- having(condition: ConditionParamsType<T>): QueryBuilderInterface<T>- condition: Conditions for filtering the results of aggregate functions. Returns:- QueryBuilderInterface<T>. Adds conditions for filtering results.
- as(alias: string): QueryBuilderInterface<T>- alias: Alias for the table or column. Returns:- QueryBuilderInterface<T>. Adds an alias to the table or column.
- groupBy(columns: string[]): QueryBuilderInterface<T>- columns: An array of columns to group the results by. Returns:- QueryBuilderInterface<T>. Adds a grouping condition to the query.
- from(table: string): QueryBuilderInterface<T>- table: The name of the table for the main query. Returns:- QueryBuilderInterface<T>. Adds the table from which data will be retrieved.
- where(params: ConditionParamsType<T>): QueryBuilderInterface<T>- params: Conditions for filtering the query results. Returns:- QueryBuilderInterface<T>. Adds conditions for filtering.
- leftJoin(table: string, condition: JoinCondition): QueryBuilderInterface<T>- table: The name of the table to join.- condition: Join conditions as a- JoinConditionobject. Returns:- QueryBuilderInterface<T>. Adds a left join to the query.
- rightJoin(table: string, condition: JoinCondition): QueryBuilderInterface<T>- table: The name of the table to join.- condition: Join conditions as a- JoinConditionobject. Returns:- QueryBuilderInterface<T>. Adds a right join to the query.
- innerJoin(table: string, condition: JoinCondition): QueryBuilderInterface<T>- table: The name of the table to join.- condition: Join conditions as a- JoinConditionobject. Returns:- QueryBuilderInterface<T>. Adds an inner join to the query.
- union(queryBuilder: QueryBuilderInterface<T>): QueryBuilderInterface<T>- queryBuilder: Another- QueryBuilderInterface<T>whose results are to be united with the current query. Returns:- QueryBuilderInterface<T>. Adds a union to the query.
- unionAll(queryBuilder: QueryBuilderInterface<T>): QueryBuilderInterface<T>- queryBuilder: Another- QueryBuilderInterface<T>whose results are to be united with the current query, including duplicates. Returns:- QueryBuilderInterface<T>. Adds a union of all results to the query.
- orderBy(column: string, order?: string): QueryBuilderInterface<T>- column: The name of the column to sort by.- order(optional): The direction of sorting ('asc' or 'desc'). Returns:- QueryBuilderInterface<T>. Adds a sorting condition to the query.
- limit(count: number): QueryBuilderInterface<T>- count: The number of records to select. Returns:- QueryBuilderInterface<T>. Adds a limit on the number of results.
- insert(values: Partial<T>, tableName: string): QueryBuilderInterface<T>- values: An object with data to insert into the table.- tableName: The name of the table for inserting data. Returns:- QueryBuilderInterface<T>. Adds an insertion condition.
- insertMany(values: Partial<T>[], tableName: string): QueryBuilderInterface<T>- values: An array of objects with data to insert into the table.- tableName: The name of the table for inserting data. Returns:- QueryBuilderInterface<T>. Adds an insertion condition for multiple records.
- update(values: Partial<T>, tableName: string): QueryBuilderInterface<T>- values: An object with data to update in the table.- tableName: The name of the table for updating data. Returns:- QueryBuilderInterface<T>. Adds an update condition.
- delete(tableName: string): QueryBuilderInterface<T>- tableName: The name of the table for deleting data. Returns:- QueryBuilderInterface<T>. Adds a deletion condition.
- cache(options: CacheOptionsInterface, enableMonitoring?: boolean): Promise<T>- options: An object implementing the- CacheOptionsInterfacefor cache configuration.- key(optional): Cache key.- ttl(optional): Cache time-to-live in seconds.- enableMonitoring(optional): Boolean value indicating the need for cache monitoring. Returns:- Promise<T>. Promises to return query results with caching.
- build(isParametrized?: boolean, isSemicolon?: boolean, useCounter?: boolean): string- isParametrized(optional): Boolean value indicating whether to parameterize the query (boolean). Determines the format of query parameters ($1, $2, etc. for PostgreSQL or ? for other DBMS).- isSemicolon(optional): Boolean value indicating whether to add a semicolon at the end of the query (boolean).- useCounter(optional): Boolean value indicating whether to use a counter for query parameters. Returns:- string. The constructed SQL query as a string.
- parametrize(parameters: any[]): QueryBuilderInterface<T>- parameters: An array of parameters to substitute into the query. Returns:- QueryBuilderInterface<T>. Adds parameters to the query.
- buildWithoutSemicolon(): stringReturns:- string. The constructed SQL query as a string without a semicolon at the end.
- execute(enableMonitoring?: boolean): Promise<T>- enableMonitoring(optional): Boolean value indicating the need for execution monitoring. Returns:- Promise<T>. Promises to return the results of query execution.
Types and Interfaces:
- ConditionParamsType<T>- conditions: Filtering conditions defined as- Condition<T>.- logicalOperator(optional): Logical operator for combining conditions ('and' or 'or').- exists(optional): Column name for existence check.
- Condition<T>- [K in keyof ElementType<T>]: Conditions for each column with possible comparison operators.
- JoinCondition- column: The name of the column for joining.- operator: Join operator.- value: Value or array of values for comparison.
- CacheOptionsInterface- key(optional): Cache key.- ttl(optional): Cache time-to-live in seconds.
Last updated