| 43 | } |
| 44 | |
| 45 | export class Query<T = any> { |
| 46 | private _select: (string | Expression)[] = []; |
| 47 | private _except: string[] = []; |
| 48 | private _from?: string | Expression; |
| 49 | private _where: WhereCondition[] = []; |
| 50 | private _groupBy: string[] = []; |
| 51 | private _rollup = false; |
| 52 | private _having: { condition: string; operator: 'AND' | 'OR' }[] = []; |
| 53 | private _orderBy: { |
| 54 | column: string; |
| 55 | direction: 'ASC' | 'DESC'; |
| 56 | }[] = []; |
| 57 | private _limit?: number; |
| 58 | private _offset?: number; |
| 59 | private _final = false; |
| 60 | private _settings: Record<string, string> = {}; |
| 61 | private _ctes: CTE[] = []; |
| 62 | private _joins: { |
| 63 | type: JoinType; |
| 64 | table: string | Expression | Query; |
| 65 | condition: string; |
| 66 | alias?: string; |
| 67 | }[] = []; |
| 68 | private _skipNext = false; |
| 69 | private _rawJoins: string[] = []; |
| 70 | private _fill?: { |
| 71 | from: string | Date; |
| 72 | to: string | Date; |
| 73 | step: string; |
| 74 | }; |
| 75 | private _transform?: Record<string, (item: T) => any>; |
| 76 | private _union?: Query; |
| 77 | private _dateRegex = /\d{4}-\d{2}-\d{2}([\s:\d.]+)?/g; |
| 78 | private _dateValueRegex = /^(?:[a-zA-Z]\w*\()?\d{4}-\d{2}-\d{2}(?:[\s:\d.]+)?\)?$/; |
| 79 | constructor( |
| 80 | private client: ClickHouseClient, |
| 81 | private timezone: string |
| 82 | ) {} |
| 83 | |
| 84 | // Select methods |
| 85 | select<U>( |
| 86 | columns: (string | Expression | null | undefined | false)[], |
| 87 | type: 'merge' | 'replace' = 'replace' |
| 88 | ): Query<U> { |
| 89 | if (this._skipNext) { |
| 90 | return this as unknown as Query<U>; |
| 91 | } |
| 92 | if (type === 'merge') { |
| 93 | this._select = [ |
| 94 | ...this._select, |
| 95 | ...columns.filter((col): col is string | Expression => Boolean(col)), |
| 96 | ]; |
| 97 | } else { |
| 98 | this._select = columns.filter((col): col is string | Expression => |
| 99 | Boolean(col) |
| 100 | ); |
| 101 | } |
| 102 | return this as unknown as Query<U>; |
nothing calls this directly
no outgoing calls
no test coverage detected