@housekit/orm 0.1.47 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +34 -0
  2. package/dist/builders/delete.js +112 -0
  3. package/dist/builders/insert.d.ts +0 -91
  4. package/dist/builders/insert.js +393 -0
  5. package/dist/builders/prepared.d.ts +1 -2
  6. package/dist/builders/prepared.js +30 -0
  7. package/dist/builders/select.d.ts +0 -161
  8. package/dist/builders/select.js +562 -0
  9. package/dist/builders/select.types.js +1 -0
  10. package/dist/builders/update.js +136 -0
  11. package/dist/client.d.ts +0 -6
  12. package/dist/client.js +140 -0
  13. package/dist/codegen/zod.js +107 -0
  14. package/dist/column.d.ts +1 -25
  15. package/dist/column.js +133 -0
  16. package/dist/compiler.d.ts +0 -7
  17. package/dist/compiler.js +513 -0
  18. package/dist/core.js +6 -0
  19. package/dist/data-types.d.ts +0 -61
  20. package/dist/data-types.js +127 -0
  21. package/dist/dictionary.d.ts +0 -149
  22. package/dist/dictionary.js +158 -0
  23. package/dist/engines.d.ts +0 -385
  24. package/dist/engines.js +292 -0
  25. package/dist/expressions.d.ts +0 -10
  26. package/dist/expressions.js +268 -0
  27. package/dist/external.d.ts +0 -112
  28. package/dist/external.js +224 -0
  29. package/dist/index.d.ts +0 -51
  30. package/dist/index.js +139 -6853
  31. package/dist/logger.js +36 -0
  32. package/dist/materialized-views.d.ts +0 -188
  33. package/dist/materialized-views.js +380 -0
  34. package/dist/metadata.js +59 -0
  35. package/dist/modules/aggregates.d.ts +0 -164
  36. package/dist/modules/aggregates.js +121 -0
  37. package/dist/modules/array.d.ts +0 -98
  38. package/dist/modules/array.js +71 -0
  39. package/dist/modules/conditional.d.ts +0 -84
  40. package/dist/modules/conditional.js +138 -0
  41. package/dist/modules/conversion.d.ts +0 -147
  42. package/dist/modules/conversion.js +109 -0
  43. package/dist/modules/geo.d.ts +0 -164
  44. package/dist/modules/geo.js +112 -0
  45. package/dist/modules/hash.js +4 -0
  46. package/dist/modules/index.js +12 -0
  47. package/dist/modules/json.d.ts +0 -106
  48. package/dist/modules/json.js +76 -0
  49. package/dist/modules/math.d.ts +0 -16
  50. package/dist/modules/math.js +16 -0
  51. package/dist/modules/string.d.ts +0 -136
  52. package/dist/modules/string.js +89 -0
  53. package/dist/modules/time.d.ts +0 -123
  54. package/dist/modules/time.js +91 -0
  55. package/dist/modules/types.d.ts +0 -133
  56. package/dist/modules/types.js +114 -0
  57. package/dist/modules/window.js +140 -0
  58. package/dist/relational.d.ts +0 -82
  59. package/dist/relational.js +290 -0
  60. package/dist/relations.js +21 -0
  61. package/dist/schema-builder.d.ts +0 -90
  62. package/dist/schema-builder.js +140 -0
  63. package/dist/table.d.ts +0 -42
  64. package/dist/table.js +406 -0
  65. package/dist/utils/background-batcher.js +75 -0
  66. package/dist/utils/batch-transform.js +51 -0
  67. package/dist/utils/binary-reader.d.ts +0 -6
  68. package/dist/utils/binary-reader.js +334 -0
  69. package/dist/utils/binary-serializer.d.ts +0 -125
  70. package/dist/utils/binary-serializer.js +637 -0
  71. package/dist/utils/binary-worker-code.js +1 -0
  72. package/dist/utils/binary-worker-pool.d.ts +0 -34
  73. package/dist/utils/binary-worker-pool.js +206 -0
  74. package/dist/utils/binary-worker.d.ts +0 -11
  75. package/dist/utils/binary-worker.js +63 -0
  76. package/dist/utils/insert-processing.d.ts +0 -2
  77. package/dist/utils/insert-processing.js +163 -0
  78. package/dist/utils/lru-cache.js +30 -0
  79. package/package.json +68 -3
@@ -0,0 +1,59 @@
1
+ export const supportedMetadataVersions = ['1.1.0', '1.2.0'];
2
+ export const defaultMetadataVersion = '1.2.0';
3
+ export const housekitMetadataSchemas = {
4
+ '1.1.0': { version: 'string', appendOnly: 'boolean' },
5
+ '1.2.0': { version: 'string', appendOnly: 'boolean', readOnly: 'boolean' }
6
+ };
7
+ export const housekitMetadataDefaults = {
8
+ '1.1.0': { appendOnly: true },
9
+ '1.2.0': { appendOnly: true, readOnly: false }
10
+ };
11
+ export function assertMetadataVersion(version) {
12
+ if (!supportedMetadataVersions.includes(version)) {
13
+ throw new Error(`Unsupported housekit metadata version "${version}". Supported versions: ${supportedMetadataVersions.join(', ')}`);
14
+ }
15
+ }
16
+ export function getMetadataDefaults(version) {
17
+ return housekitMetadataDefaults[version];
18
+ }
19
+ export function buildHousekitMetadata(version, opts) {
20
+ const defaults = getMetadataDefaults(version);
21
+ if (version === '1.1.0') {
22
+ return { version, appendOnly: opts.appendOnly ?? defaults.appendOnly };
23
+ }
24
+ if (version === '1.2.0') {
25
+ return { version, appendOnly: opts.appendOnly ?? defaults.appendOnly, readOnly: opts.readOnly ?? defaults.readOnly ?? false };
26
+ }
27
+ assertMetadataVersion(version);
28
+ return buildHousekitMetadata(defaultMetadataVersion, opts);
29
+ }
30
+ export function normalizeHousekitMetadata(raw) {
31
+ if (!raw || typeof raw !== 'object')
32
+ return null;
33
+ if (!raw.version)
34
+ return null;
35
+ const versionStr = String(raw.version);
36
+ try {
37
+ assertMetadataVersion(versionStr);
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ const version = versionStr;
43
+ if (version === '1.1.0') {
44
+ return { version, meta: { version, appendOnly: Boolean(raw.appendOnly ?? true) } };
45
+ }
46
+ if (version === '1.2.0') {
47
+ return { version, meta: { version, appendOnly: Boolean(raw.appendOnly ?? true), readOnly: Boolean(raw.readOnly ?? false) } };
48
+ }
49
+ return null;
50
+ }
51
+ export function upgradeMetadataVersion(base, targetVersion, overrides) {
52
+ const defaults = getMetadataDefaults(targetVersion);
53
+ const appendOnly = overrides?.appendOnly ?? base?.appendOnly ?? defaults.appendOnly;
54
+ if (targetVersion === '1.1.0') {
55
+ return { version: '1.1.0', appendOnly };
56
+ }
57
+ const readOnly = overrides?.readOnly ?? (base && 'readOnly' in base ? base.readOnly : defaults.readOnly ?? false);
58
+ return { version: '1.2.0', appendOnly, readOnly };
59
+ }
@@ -1,205 +1,41 @@
1
1
  import { ClickHouseColumn } from '../core';
2
2
  import { SQLExpression } from '../expressions';
3
- /**
4
- * Count rows or non-null values in column
5
- * @param col - Column to count (optional, defaults to all rows)
6
- */
7
3
  export declare function count(col?: ClickHouseColumn | SQLExpression): SQLExpression;
8
- /**
9
- * Get minimum value
10
- * @param col - Column to find minimum
11
- */
12
4
  export declare function min<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T>;
13
- /**
14
- * Get maximum value
15
- * @param col - Column to find maximum
16
- */
17
5
  export declare function max<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T>;
18
- /**
19
- * Calculate sum of values
20
- * @param col - Column to sum
21
- */
22
6
  export declare function sum(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
23
- /**
24
- * Calculate average of values
25
- * @param col - Column to average
26
- */
27
7
  export declare function avg(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
28
- /**
29
- * Count approximate unique values (HyperLogLog)
30
- * @param col - Column to count unique values
31
- */
32
8
  export declare function uniq(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
33
- /**
34
- * Count exact unique values (ClickHouse-native naming)
35
- * @param col - Column to count unique values
36
- */
37
9
  export declare function uniqExact(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
38
- /**
39
- * Count exact unique values (SQL-standard naming)
40
- * @param col - Column to count unique values
41
- */
42
10
  export declare function countDistinct(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
43
- /**
44
- * Create an array from all values in the group
45
- * @param expr - Expression to aggregate into array
46
- */
47
11
  export declare function groupArray<T>(expr: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T[]>;
48
- /**
49
- * Create an array of unique values from all values in the group
50
- * @param expr - Expression to aggregate into unique array
51
- */
52
12
  export declare function groupUniqArray<T>(expr: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T[]>;
53
- /**
54
- * Get any value from the group (non-deterministic)
55
- * @param expr - Expression to get any value from
56
- */
57
13
  export declare function any<T>(expr: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T>;
58
- /**
59
- * Get any value from the group, preferring the last one
60
- * @param expr - Expression to get any value from
61
- */
62
14
  export declare function anyLast<T>(expr: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T>;
63
- /**
64
- * Get the value with the minimum weight
65
- * Extremely useful in logs/metrics/"latest state" queries
66
- * @param value - The value to return when weight is minimum
67
- * @param weight - The weight to compare
68
- */
69
15
  export declare function argMin<T>(value: ClickHouseColumn<T, any, any> | SQLExpression<T>, weight: ClickHouseColumn | SQLExpression): SQLExpression<T>;
70
- /**
71
- * Get the value with the maximum weight
72
- * Extremely useful in logs/metrics/"latest state" queries
73
- * @param value - The value to return when weight is maximum
74
- * @param weight - The weight to compare
75
- */
76
16
  export declare function argMax<T>(value: ClickHouseColumn<T, any, any> | SQLExpression<T>, weight: ClickHouseColumn | SQLExpression): SQLExpression<T>;
77
- /**
78
- * Calculate standard deviation
79
- * @param col - Column to calculate standard deviation
80
- */
81
17
  export declare function stddevSamp(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
82
- /**
83
- * Calculate population standard deviation
84
- * @param col - Column to calculate standard deviation
85
- */
86
18
  export declare function stddevPop(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
87
- /**
88
- * Calculate sample variance
89
- * @param col - Column to calculate variance
90
- */
91
19
  export declare function varSamp(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
92
- /**
93
- * Calculate population variance
94
- * @param col - Column to calculate variance
95
- */
96
20
  export declare function varPop(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
97
- /**
98
- * Calculate median
99
- * @param col - Column to calculate median
100
- */
101
21
  export declare function median(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
102
- /**
103
- * Calculate quantile
104
- * @param col - Column to calculate quantile
105
- * @param level - Quantile level (0.0 to 1.0)
106
- */
107
22
  export declare function quantile(col: ClickHouseColumn | SQLExpression, level: number): SQLExpression<number>;
108
- /**
109
- * Calculate quantiles (multiple levels)
110
- * @param col - Column to calculate quantiles
111
- * @param levels - Array of quantile levels
112
- */
113
23
  export declare function quantiles(col: ClickHouseColumn | SQLExpression, levels: number[]): SQLExpression<number[]>;
114
- /**
115
- * Calculate Pearson correlation coefficient
116
- * @param col1 - First column
117
- * @param col2 - Second column
118
- */
119
24
  export declare function corr(col1: ClickHouseColumn | SQLExpression, col2: ClickHouseColumn | SQLExpression): SQLExpression<number>;
120
- /**
121
- * Calculate covariance
122
- * @param col1 - First column
123
- * @param col2 - Second column
124
- */
125
25
  export declare function covarSamp(col1: ClickHouseColumn | SQLExpression, col2: ClickHouseColumn | SQLExpression): SQLExpression<number>;
126
- /**
127
- * Calculate population covariance
128
- * @param col1 - First column
129
- * @param col2 - Second column
130
- */
131
26
  export declare function covarPop(col1: ClickHouseColumn | SQLExpression, col2: ClickHouseColumn | SQLExpression): SQLExpression<number>;
132
- /**
133
- * Calculate rate per second (for counters and metrics)
134
- * @param col - Counter column
135
- * @param bucket - Time bucket column
136
- */
137
27
  export declare function rate(col: ClickHouseColumn | SQLExpression, bucket: ClickHouseColumn | SQLExpression): SQLExpression<number>;
138
- /**
139
- * Calculate increase in counter value
140
- * @param col - Counter column
141
- * @param bucket - Time bucket column
142
- */
143
28
  export declare function increase(col: ClickHouseColumn | SQLExpression, bucket?: ClickHouseColumn | SQLExpression): SQLExpression<number>;
144
- /**
145
- * Calculate delta between consecutive values
146
- * @param col - Column to calculate delta
147
- */
148
29
  export declare function delta(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
149
- /**
150
- * Get top N values by frequency
151
- * @param col - Column to analyze
152
- * @param n - Number of top values to return
153
- */
154
30
  export declare function topK<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, n: number): SQLExpression<T[]>;
155
- /**
156
- * Get bottom N values by frequency
157
- * @param col - Column to analyze
158
- * @param n - Number of bottom values to return
159
- */
160
31
  export declare function bottomK<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, n: number): SQLExpression<T[]>;
161
- /**
162
- * Get top N values by sum
163
- * @param col - Column to analyze
164
- * @param n - Number of top values to return
165
- */
166
32
  export declare function topSum<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, n: number): SQLExpression<T[]>;
167
- /**
168
- * Get bottom N values by sum
169
- * @param col - Column to analyze
170
- * @param n - Number of bottom values to return
171
- */
172
33
  export declare function bottomSum<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, n: number): SQLExpression<T[]>;
173
- /**
174
- * Sum values if condition is met
175
- */
176
34
  export declare function sumIf(col: ClickHouseColumn | SQLExpression, condition: SQLExpression): SQLExpression<number>;
177
- /**
178
- * Count rows if condition is met
179
- */
180
35
  export declare function countIf(condition: SQLExpression): SQLExpression<number>;
181
- /**
182
- * Average values if condition is met
183
- */
184
36
  export declare function avgIf(col: ClickHouseColumn | SQLExpression, condition: SQLExpression): SQLExpression<number>;
185
- /**
186
- * Minimum value if condition is met
187
- */
188
37
  export declare function minIf<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, condition: SQLExpression): SQLExpression<T>;
189
- /**
190
- * Maximum value if condition is met
191
- */
192
38
  export declare function maxIf<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, condition: SQLExpression): SQLExpression<T>;
193
- /**
194
- * Approximate unique values if condition is met
195
- */
196
39
  export declare function uniqIf(col: ClickHouseColumn | SQLExpression, condition: SQLExpression): SQLExpression<number>;
197
- /**
198
- * Exact unique values if condition is met
199
- */
200
40
  export declare function uniqExactIf(col: ClickHouseColumn | SQLExpression, condition: SQLExpression): SQLExpression<number>;
201
- /**
202
- * Aggregates all array elements into a single array
203
- * @example t.array(1, 2), t.array(3, 4) -> [1, 2, 3, 4]
204
- */
205
41
  export declare function groupArrayArray<T>(expr: ClickHouseColumn<T[], any, any> | SQLExpression<T[]>): SQLExpression<T[]>;
@@ -0,0 +1,121 @@
1
+ import { sql } from '../expressions';
2
+ export function count(col) {
3
+ if (!col)
4
+ return sql `count(*)`;
5
+ return sql `count(${col})`;
6
+ }
7
+ export function min(col) {
8
+ return sql `min(${col})`;
9
+ }
10
+ export function max(col) {
11
+ return sql `max(${col})`;
12
+ }
13
+ export function sum(col) {
14
+ return sql `sum(${col})`;
15
+ }
16
+ export function avg(col) {
17
+ return sql `avg(${col})`;
18
+ }
19
+ export function uniq(col) {
20
+ return sql `uniq(${col})`;
21
+ }
22
+ export function uniqExact(col) {
23
+ return sql `uniqExact(${col})`;
24
+ }
25
+ export function countDistinct(col) {
26
+ return sql `uniqExact(${col})`;
27
+ }
28
+ export function groupArray(expr) {
29
+ return sql `groupArray(${expr})`;
30
+ }
31
+ export function groupUniqArray(expr) {
32
+ return sql `groupUniqArray(${expr})`;
33
+ }
34
+ export function any(expr) {
35
+ return sql `any(${expr})`;
36
+ }
37
+ export function anyLast(expr) {
38
+ return sql `anyLast(${expr})`;
39
+ }
40
+ export function argMin(value, weight) {
41
+ return sql `argMin(${value}, ${weight})`;
42
+ }
43
+ export function argMax(value, weight) {
44
+ return sql `argMax(${value}, ${weight})`;
45
+ }
46
+ export function stddevSamp(col) {
47
+ return sql `stddevSamp(${col})`;
48
+ }
49
+ export function stddevPop(col) {
50
+ return sql `stddevPop(${col})`;
51
+ }
52
+ export function varSamp(col) {
53
+ return sql `varSamp(${col})`;
54
+ }
55
+ export function varPop(col) {
56
+ return sql `varPop(${col})`;
57
+ }
58
+ export function median(col) {
59
+ return sql `median(${col})`;
60
+ }
61
+ export function quantile(col, level) {
62
+ return sql `quantile(${level})(${col})`;
63
+ }
64
+ export function quantiles(col, levels) {
65
+ const levelsStr = levels.join(', ');
66
+ return sql `quantiles(${levelsStr})(${col})`;
67
+ }
68
+ export function corr(col1, col2) {
69
+ return sql `corr(${col1}, ${col2})`;
70
+ }
71
+ export function covarSamp(col1, col2) {
72
+ return sql `covarSamp(${col1}, ${col2})`;
73
+ }
74
+ export function covarPop(col1, col2) {
75
+ return sql `covarPop(${col1}, ${col2})`;
76
+ }
77
+ export function rate(col, bucket) {
78
+ return sql `rate(${col})`;
79
+ }
80
+ export function increase(col, bucket) {
81
+ return sql `increase(${col})`;
82
+ }
83
+ export function delta(col) {
84
+ return sql `delta(${col})`;
85
+ }
86
+ export function topK(col, n) {
87
+ return sql `topK(${n})(${col})`;
88
+ }
89
+ export function bottomK(col, n) {
90
+ return sql `bottomK(${n})(${col})`;
91
+ }
92
+ export function topSum(col, n) {
93
+ return sql `topSum(${n})(${col})`;
94
+ }
95
+ export function bottomSum(col, n) {
96
+ return sql `bottomSum(${n})(${col})`;
97
+ }
98
+ export function sumIf(col, condition) {
99
+ return sql `sumIf(${col}, ${condition})`;
100
+ }
101
+ export function countIf(condition) {
102
+ return sql `countIf(${condition})`;
103
+ }
104
+ export function avgIf(col, condition) {
105
+ return sql `avgIf(${col}, ${condition})`;
106
+ }
107
+ export function minIf(col, condition) {
108
+ return sql `minIf(${col}, ${condition})`;
109
+ }
110
+ export function maxIf(col, condition) {
111
+ return sql `maxIf(${col}, ${condition})`;
112
+ }
113
+ export function uniqIf(col, condition) {
114
+ return sql `uniqIf(${col}, ${condition})`;
115
+ }
116
+ export function uniqExactIf(col, condition) {
117
+ return sql `uniqExactIf(${col}, ${condition})`;
118
+ }
119
+ export function groupArrayArray(expr) {
120
+ return sql `groupArrayArray(${expr})`;
121
+ }
@@ -1,122 +1,24 @@
1
1
  import { ClickHouseColumn } from '../core';
2
2
  import { SQLExpression } from '../expressions';
3
- /**
4
- * Join array elements with a separator
5
- * @param separator - Separator string
6
- * @param col - Array column or expression
7
- */
8
3
  export declare function arrayJoin(separator: string | ClickHouseColumn | SQLExpression, col?: ClickHouseColumn | SQLExpression): SQLExpression<any>;
9
- /**
10
- * Apply a lambda function to each element of an array
11
- * @param lambda - Lambda function (e.g., 'x -> x * 2')
12
- * @param col - Array column or expression
13
- */
14
4
  export declare function arrayMap(lambda: string, col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
15
- /**
16
- * Filter array elements using a lambda function
17
- * @param lambda - Lambda function (e.g., 'x -> x > 0')
18
- * @param col - Array column or expression
19
- */
20
5
  export declare function arrayFilter(lambda: string, col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
21
- /**
22
- * Get the length of an array
23
- * @param col - Array column or expression
24
- */
25
6
  export declare function arrayLength(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
26
- /**
27
- * Reduce an array using a function
28
- * @param func - Aggregate function name (e.g., 'sum', 'avg', 'max')
29
- * @param col - Array column or expression
30
- */
31
7
  export declare function arrayReduce(func: string, col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
32
- /**
33
- * Concatenate multiple arrays
34
- * @param arrays - Array columns or expressions to concatenate
35
- */
36
8
  export declare function arrayConcat(...arrays: (ClickHouseColumn | SQLExpression)[]): SQLExpression<any>;
37
- /**
38
- * Get element at specific index (1-based)
39
- * @param col - Array column or expression
40
- * @param index - Index (1-based)
41
- */
42
9
  export declare function arrayElement(col: ClickHouseColumn | SQLExpression, index: number): SQLExpression<any>;
43
- /**
44
- * Check if array contains an element
45
- * @param col - Array column or expression
46
- * @param element - Element to search for
47
- */
48
10
  export declare function arrayHas(col: ClickHouseColumn | SQLExpression, element: any): SQLExpression<any>;
49
- /**
50
- * Check if array has all elements from another array
51
- * @param col - Array column or expression
52
- * @param elements - Array of elements to check
53
- */
54
11
  export declare function arrayHasAll(col: ClickHouseColumn | SQLExpression, elements: any[] | ClickHouseColumn | SQLExpression): SQLExpression<any>;
55
- /**
56
- * Check if array has any element from another array
57
- * @param col - Array column or expression
58
- * @param elements - Array of elements to check
59
- */
60
12
  export declare function arrayHasAny(col: ClickHouseColumn | SQLExpression, elements: any[] | ClickHouseColumn | SQLExpression): SQLExpression<any>;
61
- /**
62
- * Get the first element of an array
63
- * @param col - Array column or expression
64
- */
65
13
  export declare function arrayFirst(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
66
- /**
67
- * Get the last element of an array
68
- * @param col - Array column or expression
69
- */
70
14
  export declare function arrayLast(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
71
- /**
72
- * Sort an array
73
- * @param col - Array column or expression
74
- * @param ascending - Sort order (default: true for ascending)
75
- */
76
15
  export declare function arraySort(col: ClickHouseColumn | SQLExpression, ascending?: boolean): SQLExpression<any>;
77
- /**
78
- * Reverse an array
79
- * @param col - Array column or expression
80
- */
81
16
  export declare function arrayReverse(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
82
- /**
83
- * Get unique elements from an array
84
- * @param col - Array column or expression
85
- */
86
17
  export declare function arrayDistinct(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
87
- /**
88
- * Count occurrences of an element in an array
89
- * @param col - Array column or expression
90
- * @param element - Element to count
91
- */
92
18
  export declare function arrayCountMatches(col: ClickHouseColumn | SQLExpression, element: any): SQLExpression<any>;
93
- /**
94
- * Check if array is empty
95
- * @param col - Array column or expression
96
- */
97
19
  export declare function empty(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
98
- /**
99
- * Check if array is not empty
100
- * @param col - Array column or expression
101
- */
102
20
  export declare function notEmpty(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
103
- /**
104
- * Get the minimum value in an array
105
- * @param col - Array column or expression
106
- */
107
21
  export declare function arrayMin(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
108
- /**
109
- * Get the maximum value in an array
110
- * @param col - Array column or expression
111
- */
112
22
  export declare function arrayMax(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
113
- /**
114
- * Calculate the sum of array elements
115
- * @param col - Array column or expression
116
- */
117
23
  export declare function arraySum(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
118
- /**
119
- * Calculate the average of array elements
120
- * @param col - Array column or expression
121
- */
122
24
  export declare function arrayAvg(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
@@ -0,0 +1,71 @@
1
+ import { sql } from '../expressions';
2
+ export function arrayJoin(separator, col) {
3
+ if (col) {
4
+ return sql `arrayJoin(${separator}, ${col})`;
5
+ }
6
+ return sql `arrayJoin(${separator})`;
7
+ }
8
+ export function arrayMap(lambda, col) {
9
+ return sql `arrayMap(${lambda}, ${col})`;
10
+ }
11
+ export function arrayFilter(lambda, col) {
12
+ return sql `arrayFilter(${lambda}, ${col})`;
13
+ }
14
+ export function arrayLength(col) {
15
+ return sql `arrayLength(${col})`;
16
+ }
17
+ export function arrayReduce(func, col) {
18
+ return sql `arrayReduce('${func}', ${col})`;
19
+ }
20
+ export function arrayConcat(...arrays) {
21
+ const params = arrays.map(arr => sql `${arr}`).join(', ');
22
+ return sql `arrayConcat(${params})`;
23
+ }
24
+ export function arrayElement(col, index) {
25
+ return sql `arrayElement(${col}, ${index})`;
26
+ }
27
+ export function arrayHas(col, element) {
28
+ return sql `has(${col}, ${element})`;
29
+ }
30
+ export function arrayHasAll(col, elements) {
31
+ return sql `hasAll(${col}, ${elements})`;
32
+ }
33
+ export function arrayHasAny(col, elements) {
34
+ return sql `hasAny(${col}, ${elements})`;
35
+ }
36
+ export function arrayFirst(col) {
37
+ return sql `arrayFirst(${col})`;
38
+ }
39
+ export function arrayLast(col) {
40
+ return sql `arrayLast(${col})`;
41
+ }
42
+ export function arraySort(col, ascending = true) {
43
+ return ascending ? sql `arraySort(${col})` : sql `arrayReverseSort(${col})`;
44
+ }
45
+ export function arrayReverse(col) {
46
+ return sql `arrayReverse(${col})`;
47
+ }
48
+ export function arrayDistinct(col) {
49
+ return sql `arrayDistinct(${col})`;
50
+ }
51
+ export function arrayCountMatches(col, element) {
52
+ return sql `countMatches(${col}, ${element})`;
53
+ }
54
+ export function empty(col) {
55
+ return sql `empty(${col})`;
56
+ }
57
+ export function notEmpty(col) {
58
+ return sql `notEmpty(${col})`;
59
+ }
60
+ export function arrayMin(col) {
61
+ return sql `arrayMin(${col})`;
62
+ }
63
+ export function arrayMax(col) {
64
+ return sql `arrayMax(${col})`;
65
+ }
66
+ export function arraySum(col) {
67
+ return sql `arraySum(${col})`;
68
+ }
69
+ export function arrayAvg(col) {
70
+ return sql `arrayAvg(${col})`;
71
+ }
@@ -1,110 +1,26 @@
1
1
  import { ClickHouseColumn } from '../core';
2
2
  import { SQLExpression } from '../expressions';
3
- /**
4
- * Return alternative value if column is null
5
- * @param col - Column to check
6
- * @param alt - Alternative value
7
- */
8
3
  export declare function ifNull(col: ClickHouseColumn | SQLExpression, alt: any): SQLExpression;
9
- /**
10
- * Simple if-then-else conditional
11
- * @param condition - Condition to evaluate
12
- * @param trueVal - Value if condition is true
13
- * @param falseVal - Value if condition is false
14
- */
15
4
  export declare function sqlIf(condition: SQLExpression, trueVal: any, falseVal: any): SQLExpression;
16
- /**
17
- * Multi-conditional function for ClickHouse case-like logic
18
- * Usage: multiIf(cond1, val1, cond2, val2, ..., default)
19
- */
20
5
  export declare function multiIf(...args: (ClickHouseColumn | SQLExpression | any)[]): SQLExpression;
21
- /**
22
- * Case When builder for analytics queries
23
- * Compiles to multiIf for better DX
24
- *
25
- * @example
26
- * caseWhen()
27
- * .when(gt(events.count, 100), sql`'high'`)
28
- * .when(gt(events.count, 50), sql`'medium'`)
29
- * .otherwise(sql`'low'`)
30
- */
31
6
  export declare function caseWhen(): CaseWhenBuilder;
32
7
  declare class CaseWhenBuilder {
33
8
  private conditions;
34
9
  private values;
35
10
  private defaultValue?;
36
- /**
37
- * Add a condition-value pair
38
- * @param condition - The condition to evaluate
39
- * @param value - The value to return if condition is true
40
- */
41
11
  when(condition: ClickHouseColumn | SQLExpression, value: ClickHouseColumn | SQLExpression | any): this;
42
- /**
43
- * Set the default value (required)
44
- * @param value - The default value to return if all conditions are false
45
- */
46
12
  otherwise(value: ClickHouseColumn | SQLExpression | any): SQLExpression;
47
- /**
48
- * Build the final multiIf expression
49
- */
50
13
  private build;
51
14
  }
52
- /**
53
- * Return first non-null value
54
- * @param args - Values to check
55
- */
56
15
  export declare function coalesce(...args: (ClickHouseColumn | SQLExpression | any)[]): SQLExpression;
57
- /**
58
- * Return greatest value
59
- * @param args - Values to compare
60
- */
61
16
  export declare function greatest(...args: (ClickHouseColumn | SQLExpression | any)[]): SQLExpression;
62
- /**
63
- * Return smallest value
64
- * @param args - Values to compare
65
- */
66
17
  export declare function least(...args: (ClickHouseColumn | SQLExpression | any)[]): SQLExpression;
67
- /**
68
- * Check if value is null
69
- * @param col - Column or expression to check
70
- */
71
18
  export declare function isNull(col: ClickHouseColumn | SQLExpression): SQLExpression;
72
- /**
73
- * Check if value is not null
74
- * @param col - Column or expression to check
75
- */
76
19
  export declare function isNotNull(col: ClickHouseColumn | SQLExpression): SQLExpression;
77
- /**
78
- * Convert to null if condition is met
79
- * @param condition - Condition to check
80
- * @param col - Column to convert to null
81
- */
82
20
  export declare function nullIf(condition: SQLExpression, col: ClickHouseColumn | SQLExpression): SQLExpression;
83
- /**
84
- * Convert to null if value matches
85
- * @param col - Column to check
86
- * @param value - Value to match
87
- */
88
21
  export declare function nullIfEqual(col: ClickHouseColumn | SQLExpression, value: any): SQLExpression;
89
- /**
90
- * Logical NOT
91
- * @param expr - Expression to negate
92
- */
93
22
  export declare function not(expr: SQLExpression): SQLExpression;
94
- /**
95
- * Logical AND (multiple conditions)
96
- * @param exprs - Conditions to AND together
97
- */
98
23
  export declare function and(...exprs: (SQLExpression | undefined | null | false)[]): SQLExpression | undefined;
99
- /**
100
- * Logical OR (multiple conditions)
101
- * @param exprs - Conditions to OR together
102
- */
103
24
  export declare function or(...exprs: (SQLExpression | undefined | null | false)[]): SQLExpression | undefined;
104
- /**
105
- * Logical XOR (exclusive or)
106
- * @param expr1 - First expression
107
- * @param expr2 - Second expression
108
- */
109
25
  export declare function xor(expr1: SQLExpression, expr2: SQLExpression): SQLExpression;
110
26
  export {};