UNPKG

ts-db-helper

Version:
99 lines (98 loc) 3.05 kB
import { IClause } from '../interfaces/i-clause.interface'; import { QueryPart } from './query-part.model'; /** * @public API * @class CompositeClause * * @description * Clause that allow integrators to compare tuple of value like in this raw query: * "SELECT * FROM Animals WHERE (species, color) IN (('dog', 'white'), ('cat', 'ginger'), ('bird', 'blue'))" * * @example * ```typescript * // Create a group of clauses * const composite = new CompositeClause(['species', 'color'], [['dog', 'white'], ['cat', 'ginger'], ['bird', 'blue']]); * composite.comparator = ClauseCompators.IN * * // start select clause * Select(Animal).where(composite).exec().subscribe((QueryResult<Animal>) => { * // do something with the result... * }, (err) => { * // do something with the error... * }); * ``` * * @author Olivier Margarit * @since 0.2 */ export declare class CompositeClause implements IClause { /** * @public * @property {string} operator is used as join clause condition * * @default ClauseOperators.AND */ operator: string; /** * @private * @property {Array<string>} keysValue list of column from the composite clause */ private keysValue; /** * @private * @property {Array<any>} valuesValue list of values matching with the column keys to compare with */ private valuesValue; /** * @public * @property {Array<string>} key is table column name corresponding to the field * to compare with */ readonly keys: string[]; /** * @public * @property {Array<any>} value is the column value to compare with */ readonly values: any[]; /** * @public * @property {boolean} not is an additionnal operator to invert condition */ not: boolean; /** * @public * @property {string} comparator is a comparator that define the type of * relation with the value to compare with and the result. * * @default ClauseComparators.EQ */ comparator: string; /** * @public * @constructor create new instance of composite clause * @param {Array<string>} keys optional list of columns from the composite clause to compare with * @param {Array<any>} values optional list of values to compare with */ constructor(keys?: string[], values?: any[]); /** * @public * @method addKey add column to compare with * * @param {string} value the column reference */ addKey(value: string): void; /** * @public * @method addValue add value to compare with * @param {any} value the value to compare with */ addValue(value: any): void; /** * @public * @method build should be removed to be a part of the private API * * @return {QueryPart} query part of the query with the string part and * clauses params. */ build(): QueryPart; }