@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.
- package/README.md +34 -0
- package/dist/builders/delete.js +112 -0
- package/dist/builders/insert.d.ts +0 -91
- package/dist/builders/insert.js +393 -0
- package/dist/builders/prepared.d.ts +1 -2
- package/dist/builders/prepared.js +30 -0
- package/dist/builders/select.d.ts +0 -161
- package/dist/builders/select.js +562 -0
- package/dist/builders/select.types.js +1 -0
- package/dist/builders/update.js +136 -0
- package/dist/client.d.ts +0 -6
- package/dist/client.js +140 -0
- package/dist/codegen/zod.js +107 -0
- package/dist/column.d.ts +1 -25
- package/dist/column.js +133 -0
- package/dist/compiler.d.ts +0 -7
- package/dist/compiler.js +513 -0
- package/dist/core.js +6 -0
- package/dist/data-types.d.ts +0 -61
- package/dist/data-types.js +127 -0
- package/dist/dictionary.d.ts +0 -149
- package/dist/dictionary.js +158 -0
- package/dist/engines.d.ts +0 -385
- package/dist/engines.js +292 -0
- package/dist/expressions.d.ts +0 -10
- package/dist/expressions.js +268 -0
- package/dist/external.d.ts +0 -112
- package/dist/external.js +224 -0
- package/dist/index.d.ts +0 -51
- package/dist/index.js +139 -6853
- package/dist/logger.js +36 -0
- package/dist/materialized-views.d.ts +0 -188
- package/dist/materialized-views.js +380 -0
- package/dist/metadata.js +59 -0
- package/dist/modules/aggregates.d.ts +0 -164
- package/dist/modules/aggregates.js +121 -0
- package/dist/modules/array.d.ts +0 -98
- package/dist/modules/array.js +71 -0
- package/dist/modules/conditional.d.ts +0 -84
- package/dist/modules/conditional.js +138 -0
- package/dist/modules/conversion.d.ts +0 -147
- package/dist/modules/conversion.js +109 -0
- package/dist/modules/geo.d.ts +0 -164
- package/dist/modules/geo.js +112 -0
- package/dist/modules/hash.js +4 -0
- package/dist/modules/index.js +12 -0
- package/dist/modules/json.d.ts +0 -106
- package/dist/modules/json.js +76 -0
- package/dist/modules/math.d.ts +0 -16
- package/dist/modules/math.js +16 -0
- package/dist/modules/string.d.ts +0 -136
- package/dist/modules/string.js +89 -0
- package/dist/modules/time.d.ts +0 -123
- package/dist/modules/time.js +91 -0
- package/dist/modules/types.d.ts +0 -133
- package/dist/modules/types.js +114 -0
- package/dist/modules/window.js +140 -0
- package/dist/relational.d.ts +0 -82
- package/dist/relational.js +290 -0
- package/dist/relations.js +21 -0
- package/dist/schema-builder.d.ts +0 -90
- package/dist/schema-builder.js +140 -0
- package/dist/table.d.ts +0 -42
- package/dist/table.js +406 -0
- package/dist/utils/background-batcher.js +75 -0
- package/dist/utils/batch-transform.js +51 -0
- package/dist/utils/binary-reader.d.ts +0 -6
- package/dist/utils/binary-reader.js +334 -0
- package/dist/utils/binary-serializer.d.ts +0 -125
- package/dist/utils/binary-serializer.js +637 -0
- package/dist/utils/binary-worker-code.js +1 -0
- package/dist/utils/binary-worker-pool.d.ts +0 -34
- package/dist/utils/binary-worker-pool.js +206 -0
- package/dist/utils/binary-worker.d.ts +0 -11
- package/dist/utils/binary-worker.js +63 -0
- package/dist/utils/insert-processing.d.ts +0 -2
- package/dist/utils/insert-processing.js +163 -0
- package/dist/utils/lru-cache.js +30 -0
- package/package.json +68 -3
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { sql } from '../expressions';
|
|
2
|
+
export function geoDistance(point1, point2, unit = 'km') {
|
|
3
|
+
if (unit === 'mi') {
|
|
4
|
+
return sql `greatCircleDistance(${point1}, ${point2}) * 0.621371`;
|
|
5
|
+
}
|
|
6
|
+
return sql `greatCircleDistance(${point1}, ${point2})`;
|
|
7
|
+
}
|
|
8
|
+
export function greatCircleDistance(point1, point2) {
|
|
9
|
+
return sql `greatCircleDistance(${point1}, ${point2})`;
|
|
10
|
+
}
|
|
11
|
+
export function euclideanDistance(point1, point2) {
|
|
12
|
+
return sql `sqrt(pow(${point1}.1 - ${point2}.1, 2) + pow(${point1}.2 - ${point2}.2, 2))`;
|
|
13
|
+
}
|
|
14
|
+
export function manhattanDistance(point1, point2) {
|
|
15
|
+
return sql `abs(${point1}.1 - ${point2}.1) + abs(${point1}.2 - ${point2}.2)`;
|
|
16
|
+
}
|
|
17
|
+
export function geoPoint(longitude, latitude) {
|
|
18
|
+
return sql `(${longitude}, ${latitude})`;
|
|
19
|
+
}
|
|
20
|
+
export function geoLongitude(point) {
|
|
21
|
+
return sql `${point}.1`;
|
|
22
|
+
}
|
|
23
|
+
export function geoLatitude(point) {
|
|
24
|
+
return sql `${point}.2`;
|
|
25
|
+
}
|
|
26
|
+
export function geoX(point) {
|
|
27
|
+
return sql `${point}.1`;
|
|
28
|
+
}
|
|
29
|
+
export function geoY(point) {
|
|
30
|
+
return sql `${point}.2`;
|
|
31
|
+
}
|
|
32
|
+
export function pointInPolygon(point, polygon) {
|
|
33
|
+
return sql `pointInPolygon(${point}, ${polygon})`;
|
|
34
|
+
}
|
|
35
|
+
export function polygonContains(polygon1, polygon2) {
|
|
36
|
+
return sql `polygonContains(${polygon1}, ${polygon2})`;
|
|
37
|
+
}
|
|
38
|
+
export function polygonsIntersect(polygon1, polygon2) {
|
|
39
|
+
return sql `polygonsIntersect(${polygon1}, ${polygon2})`;
|
|
40
|
+
}
|
|
41
|
+
export function boundingBox(point1, point2) {
|
|
42
|
+
return sql `boundingBox(${point1}, ${point2})`;
|
|
43
|
+
}
|
|
44
|
+
export function pointInBoundingBox(point, bbox) {
|
|
45
|
+
return sql `pointInBoundingBox(${point}, ${bbox})`;
|
|
46
|
+
}
|
|
47
|
+
export function bboxMin(bbox) {
|
|
48
|
+
return sql `bboxMin(${bbox})`;
|
|
49
|
+
}
|
|
50
|
+
export function bboxMax(bbox) {
|
|
51
|
+
return sql `bboxMax(${bbox})`;
|
|
52
|
+
}
|
|
53
|
+
export function polygonArea(polygon) {
|
|
54
|
+
return sql `polygonArea(${polygon})`;
|
|
55
|
+
}
|
|
56
|
+
export function polygonPerimeter(polygon) {
|
|
57
|
+
return sql `polygonPerimeter(${polygon})`;
|
|
58
|
+
}
|
|
59
|
+
export function polygonCentroid(polygon) {
|
|
60
|
+
return sql `polygonCentroid(${polygon})`;
|
|
61
|
+
}
|
|
62
|
+
export function polygonSimplify(polygon, epsilon) {
|
|
63
|
+
return sql `polygonSimplify(${polygon}, ${epsilon})`;
|
|
64
|
+
}
|
|
65
|
+
export function polygonBuffer(polygon, distance) {
|
|
66
|
+
return sql `polygonBuffer(${polygon}, ${distance})`;
|
|
67
|
+
}
|
|
68
|
+
export function geoHashEncode(point, precision = 10) {
|
|
69
|
+
return sql `geoHashEncode(${point}, ${precision})`;
|
|
70
|
+
}
|
|
71
|
+
export function geoHashDecode(geohash) {
|
|
72
|
+
return sql `geoHashDecode(${geohash})`;
|
|
73
|
+
}
|
|
74
|
+
export function geoHashNeighbors(geohash) {
|
|
75
|
+
return sql `geoHashNeighbors(${geohash})`;
|
|
76
|
+
}
|
|
77
|
+
export function geoHashAreNeighbors(geohash1, geohash2) {
|
|
78
|
+
return sql `geoHashAreNeighbors(${geohash1}, ${geohash2})`;
|
|
79
|
+
}
|
|
80
|
+
export function pointsWithinRadius(center, radius, points) {
|
|
81
|
+
return sql `arrayFilter(x -> greatCircleDistance(${center}, x) <= ${radius}, ${points})`;
|
|
82
|
+
}
|
|
83
|
+
export function nearestNeighbors(point, points, k) {
|
|
84
|
+
return sql `arraySlice(arraySort(x -> greatCircleDistance(${point}, x), ${points}), 1, ${k})`;
|
|
85
|
+
}
|
|
86
|
+
export function kMeansClustering(points, k) {
|
|
87
|
+
return sql `kMeans(${points}, ${k})`;
|
|
88
|
+
}
|
|
89
|
+
export function degreesToRadians(degrees) {
|
|
90
|
+
return sql `radians(${degrees})`;
|
|
91
|
+
}
|
|
92
|
+
export function radiansToDegrees(radians) {
|
|
93
|
+
return sql `degrees(${radians})`;
|
|
94
|
+
}
|
|
95
|
+
export function webMercatorToWGS84(point) {
|
|
96
|
+
return sql `webMercatorToWGS84(${point})`;
|
|
97
|
+
}
|
|
98
|
+
export function wGS84ToWebMercator(point) {
|
|
99
|
+
return sql `wGS84ToWebMercator(${point})`;
|
|
100
|
+
}
|
|
101
|
+
export function isValidGeometry(geometry) {
|
|
102
|
+
return sql `isValidGeometry(${geometry})`;
|
|
103
|
+
}
|
|
104
|
+
export function geometryType(geometry) {
|
|
105
|
+
return sql `geometryType(${geometry})`;
|
|
106
|
+
}
|
|
107
|
+
export function geometryNumPoints(geometry) {
|
|
108
|
+
return sql `geometryNumPoints(${geometry})`;
|
|
109
|
+
}
|
|
110
|
+
export function polygonNumInteriorRings(polygon) {
|
|
111
|
+
return sql `polygonNumInteriorRings(${polygon})`;
|
|
112
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './array';
|
|
2
|
+
export * from './json';
|
|
3
|
+
export * from './geo';
|
|
4
|
+
export * from './time';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './aggregates';
|
|
7
|
+
export * from './conditional';
|
|
8
|
+
export * from './conversion';
|
|
9
|
+
export * from './string';
|
|
10
|
+
export * from './math';
|
|
11
|
+
export * from './hash';
|
|
12
|
+
export * from './window';
|
package/dist/modules/json.d.ts
CHANGED
|
@@ -1,130 +1,24 @@
|
|
|
1
1
|
import { ClickHouseColumn } from '../core';
|
|
2
2
|
import { SQLExpression } from '../expressions';
|
|
3
3
|
type Expr<T = any> = ClickHouseColumn<T, any, any> | SQLExpression<T>;
|
|
4
|
-
/**
|
|
5
|
-
* Extract string value from JSON
|
|
6
|
-
* @param col - JSON column or expression
|
|
7
|
-
* @param path - JSONPath expression (e.g., 'user.name', '$.items[0].price')
|
|
8
|
-
*/
|
|
9
4
|
export declare function jsonExtractString(col: Expr, path: string): SQLExpression<string>;
|
|
10
|
-
/**
|
|
11
|
-
* Extract integer value from JSON
|
|
12
|
-
* @param col - JSON column or expression
|
|
13
|
-
* @param path - JSONPath expression (e.g., 'user.age', '$.count')
|
|
14
|
-
*/
|
|
15
5
|
export declare function jsonExtractInt(col: Expr, path: string): SQLExpression<number>;
|
|
16
|
-
/**
|
|
17
|
-
* Extract float value from JSON
|
|
18
|
-
* @param col - JSON column or expression
|
|
19
|
-
* @param path - JSONPath expression (e.g., 'user.score', '$.price')
|
|
20
|
-
*/
|
|
21
6
|
export declare function jsonExtractFloat(col: Expr, path: string): SQLExpression<number>;
|
|
22
|
-
/**
|
|
23
|
-
* Extract boolean value from JSON
|
|
24
|
-
* @param col - JSON column or expression
|
|
25
|
-
* @param path - JSONPath expression (e.g., 'user.active', '$.enabled')
|
|
26
|
-
*/
|
|
27
7
|
export declare function jsonExtractBool(col: Expr, path: string): SQLExpression<boolean>;
|
|
28
|
-
/**
|
|
29
|
-
* Generic JSON extraction with type specification
|
|
30
|
-
* @param col - JSON column or expression
|
|
31
|
-
* @param path - JSONPath expression
|
|
32
|
-
* @param type - ClickHouse type literal (e.g., 'String', 'Int', 'Float', 'Bool', 'Array(String)')
|
|
33
|
-
*/
|
|
34
8
|
export declare function jsonExtract(col: Expr, path: string, type: string): SQLExpression<any>;
|
|
35
|
-
/**
|
|
36
|
-
* Extract raw JSON value as string
|
|
37
|
-
* Useful when you want to preserve the JSON structure
|
|
38
|
-
* @param col - JSON column or expression
|
|
39
|
-
* @param path - JSONPath expression
|
|
40
|
-
*/
|
|
41
9
|
export declare function jsonExtractRaw(col: Expr, path: string): SQLExpression<string>;
|
|
42
|
-
/**
|
|
43
|
-
* Check if JSON has a specific path
|
|
44
|
-
* @param col - JSON column or expression
|
|
45
|
-
* @param path - JSONPath expression
|
|
46
|
-
*/
|
|
47
10
|
export declare function jsonHas(col: Expr, path: string): SQLExpression<boolean>;
|
|
48
|
-
/**
|
|
49
|
-
* Extract all keys from JSON object at specified path
|
|
50
|
-
* Useful for introspecting JSON blobs
|
|
51
|
-
* @param col - JSON column or expression
|
|
52
|
-
* @param path - JSONPath expression (optional, defaults to root)
|
|
53
|
-
*/
|
|
54
11
|
export declare function jsonExtractKeys(col: Expr, path?: string): SQLExpression<any>;
|
|
55
|
-
/**
|
|
56
|
-
* Extract all values from JSON object at specified path
|
|
57
|
-
* Useful for introspecting JSON blobs
|
|
58
|
-
* @param col - JSON column or expression
|
|
59
|
-
* @param path - JSONPath expression (optional, defaults to root)
|
|
60
|
-
*/
|
|
61
12
|
export declare function jsonExtractValues(col: Expr, path?: string): SQLExpression<any>;
|
|
62
|
-
/**
|
|
63
|
-
* Extract keys and values as tuples from JSON object
|
|
64
|
-
* Useful for introspecting JSON blobs
|
|
65
|
-
* @param col - JSON column or expression
|
|
66
|
-
* @param path - JSONPath expression (optional, defaults to root)
|
|
67
|
-
*/
|
|
68
13
|
export declare function jsonExtractKeysAndValues(col: Expr, path?: string): SQLExpression<any>;
|
|
69
|
-
/**
|
|
70
|
-
* Get the length of JSON array or object
|
|
71
|
-
* @param col - JSON column or expression
|
|
72
|
-
* @param path - JSONPath expression (optional, defaults to root)
|
|
73
|
-
*/
|
|
74
14
|
export declare function jsonLength(col: Expr, path?: string): SQLExpression<number>;
|
|
75
|
-
/**
|
|
76
|
-
* Get the type of JSON value at specified path
|
|
77
|
-
* Returns: 'null', 'bool', 'number', 'string', 'array', 'object'
|
|
78
|
-
* @param col - JSON column or expression
|
|
79
|
-
* @param path - JSONPath expression (optional, defaults to root)
|
|
80
|
-
*/
|
|
81
15
|
export declare function jsonType(col: Expr, path?: string): SQLExpression<string>;
|
|
82
|
-
/**
|
|
83
|
-
* Insert value into JSON at specified path
|
|
84
|
-
* @param col - JSON column or expression
|
|
85
|
-
* @param path - JSONPath expression
|
|
86
|
-
* @param value - Value to insert
|
|
87
|
-
*/
|
|
88
16
|
export declare function jsonInsert(col: Expr, path: string, value: any): SQLExpression<any>;
|
|
89
|
-
/**
|
|
90
|
-
* Replace value in JSON at specified path
|
|
91
|
-
* @param col - JSON column or expression
|
|
92
|
-
* @param path - JSONPath expression
|
|
93
|
-
* @param value - Value to replace with
|
|
94
|
-
*/
|
|
95
17
|
export declare function jsonReplace(col: Expr, path: string, value: any): SQLExpression<any>;
|
|
96
|
-
/**
|
|
97
|
-
* Remove value from JSON at specified path
|
|
98
|
-
* @param col - JSON column or expression
|
|
99
|
-
* @param path - JSONPath expression
|
|
100
|
-
*/
|
|
101
18
|
export declare function jsonRemove(col: Expr, path: string): SQLExpression<any>;
|
|
102
|
-
/**
|
|
103
|
-
* Parse string as JSON
|
|
104
|
-
* @param col - String column or expression containing JSON
|
|
105
|
-
*/
|
|
106
19
|
export declare function parseJSON(col: Expr): SQLExpression<any>;
|
|
107
|
-
/**
|
|
108
|
-
* Parse string as JSONBestEffort (more tolerant)
|
|
109
|
-
* @param col - String column or expression containing JSON
|
|
110
|
-
*/
|
|
111
20
|
export declare function parseJSONBestEffort(col: Expr): SQLExpression<any>;
|
|
112
|
-
/**
|
|
113
|
-
* Convert JSON to string
|
|
114
|
-
* @param col - JSON column or expression
|
|
115
|
-
*/
|
|
116
21
|
export declare function jsonStringify(col: Expr): SQLExpression<string>;
|
|
117
|
-
/**
|
|
118
|
-
* Extract JSON array as ClickHouse array
|
|
119
|
-
* @param col - JSON column or expression
|
|
120
|
-
* @param path - JSONPath expression
|
|
121
|
-
* @param type - ClickHouse type for array elements (e.g., 'String', 'Int')
|
|
122
|
-
*/
|
|
123
22
|
export declare function jsonArrayExtract(col: Expr, path: string, type: string): SQLExpression<any>;
|
|
124
|
-
/**
|
|
125
|
-
* Get length of JSON array
|
|
126
|
-
* @param col - JSON column or expression
|
|
127
|
-
* @param path - JSONPath expression
|
|
128
|
-
*/
|
|
129
23
|
export declare function jsonArrayLength(col: Expr, path: string): SQLExpression<number>;
|
|
130
24
|
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { sql } from '../expressions';
|
|
2
|
+
export function jsonExtractString(col, path) {
|
|
3
|
+
return sql `JSONExtractString(${col}, ${path})`;
|
|
4
|
+
}
|
|
5
|
+
export function jsonExtractInt(col, path) {
|
|
6
|
+
return sql `JSONExtractInt(${col}, ${path})`;
|
|
7
|
+
}
|
|
8
|
+
export function jsonExtractFloat(col, path) {
|
|
9
|
+
return sql `JSONExtractFloat(${col}, ${path})`;
|
|
10
|
+
}
|
|
11
|
+
export function jsonExtractBool(col, path) {
|
|
12
|
+
return sql `JSONExtractBool(${col}, ${path})`;
|
|
13
|
+
}
|
|
14
|
+
export function jsonExtract(col, path, type) {
|
|
15
|
+
return sql `JSONExtract(${col}, ${path}, '${type}')`;
|
|
16
|
+
}
|
|
17
|
+
export function jsonExtractRaw(col, path) {
|
|
18
|
+
return sql `JSONExtractRaw(${col}, ${path})`;
|
|
19
|
+
}
|
|
20
|
+
export function jsonHas(col, path) {
|
|
21
|
+
return sql `JSONHas(${col}, ${path})`;
|
|
22
|
+
}
|
|
23
|
+
export function jsonExtractKeys(col, path) {
|
|
24
|
+
if (path) {
|
|
25
|
+
return sql `JSONKeys(${col}, ${path})`;
|
|
26
|
+
}
|
|
27
|
+
return sql `JSONKeys(${col})`;
|
|
28
|
+
}
|
|
29
|
+
export function jsonExtractValues(col, path) {
|
|
30
|
+
if (path) {
|
|
31
|
+
return sql `JSONValues(${col}, ${path})`;
|
|
32
|
+
}
|
|
33
|
+
return sql `JSONValues(${col})`;
|
|
34
|
+
}
|
|
35
|
+
export function jsonExtractKeysAndValues(col, path) {
|
|
36
|
+
if (path) {
|
|
37
|
+
return sql `JSONKeysAndValues(${col}, ${path})`;
|
|
38
|
+
}
|
|
39
|
+
return sql `JSONKeysAndValues(${col})`;
|
|
40
|
+
}
|
|
41
|
+
export function jsonLength(col, path) {
|
|
42
|
+
if (path) {
|
|
43
|
+
return sql `JSONLength(${col}, ${path})`;
|
|
44
|
+
}
|
|
45
|
+
return sql `JSONLength(${col})`;
|
|
46
|
+
}
|
|
47
|
+
export function jsonType(col, path) {
|
|
48
|
+
if (path) {
|
|
49
|
+
return sql `JSONType(${col}, ${path})`;
|
|
50
|
+
}
|
|
51
|
+
return sql `JSONType(${col})`;
|
|
52
|
+
}
|
|
53
|
+
export function jsonInsert(col, path, value) {
|
|
54
|
+
return sql `JSONInsert(${col}, ${path}, ${value})`;
|
|
55
|
+
}
|
|
56
|
+
export function jsonReplace(col, path, value) {
|
|
57
|
+
return sql `JSONReplace(${col}, ${path}, ${value})`;
|
|
58
|
+
}
|
|
59
|
+
export function jsonRemove(col, path) {
|
|
60
|
+
return sql `JSONRemove(${col}, ${path})`;
|
|
61
|
+
}
|
|
62
|
+
export function parseJSON(col) {
|
|
63
|
+
return sql `parseJSON(${col})`;
|
|
64
|
+
}
|
|
65
|
+
export function parseJSONBestEffort(col) {
|
|
66
|
+
return sql `parseJSONBestEffort(${col})`;
|
|
67
|
+
}
|
|
68
|
+
export function jsonStringify(col) {
|
|
69
|
+
return sql `JSONString(${col})`;
|
|
70
|
+
}
|
|
71
|
+
export function jsonArrayExtract(col, path, type) {
|
|
72
|
+
return sql `JSONArrayExtract(${col}, ${path}, '${type}')`;
|
|
73
|
+
}
|
|
74
|
+
export function jsonArrayLength(col, path) {
|
|
75
|
+
return sql `JSONArrayLength(${col}, ${path})`;
|
|
76
|
+
}
|
package/dist/modules/math.d.ts
CHANGED
|
@@ -6,23 +6,7 @@ export declare const floor: (col: ClickHouseColumn | SQLExpression) => SQLExpres
|
|
|
6
6
|
export declare const ceil: (col: ClickHouseColumn | SQLExpression) => SQLExpression<any>;
|
|
7
7
|
export declare const sqrt: (col: ClickHouseColumn | SQLExpression) => SQLExpression<any>;
|
|
8
8
|
export declare const power: (col: ClickHouseColumn | SQLExpression, exponent: number) => SQLExpression<any>;
|
|
9
|
-
/**
|
|
10
|
-
* ⚠️ Advanced: Low-value arithmetic wrapper.
|
|
11
|
-
* Consider using `sql`${a} + ${b}`` directly.
|
|
12
|
-
*/
|
|
13
9
|
export declare const plus: (a: ClickHouseColumn | SQLExpression | number, b: ClickHouseColumn | SQLExpression | number) => SQLExpression<any>;
|
|
14
|
-
/**
|
|
15
|
-
* ⚠️ Advanced: Low-value arithmetic wrapper.
|
|
16
|
-
* Consider using `sql`${a} - ${b}`` directly.
|
|
17
|
-
*/
|
|
18
10
|
export declare const minus: (a: ClickHouseColumn | SQLExpression | number, b: ClickHouseColumn | SQLExpression | number) => SQLExpression<any>;
|
|
19
|
-
/**
|
|
20
|
-
* ⚠️ Advanced: Low-value arithmetic wrapper.
|
|
21
|
-
* Consider using `sql`${a} * ${b}`` directly.
|
|
22
|
-
*/
|
|
23
11
|
export declare const mult: (a: ClickHouseColumn | SQLExpression | number, b: ClickHouseColumn | SQLExpression | number) => SQLExpression<any>;
|
|
24
|
-
/**
|
|
25
|
-
* ⚠️ Advanced: Low-value arithmetic wrapper.
|
|
26
|
-
* Consider using `sql`${a} / ${b}`` directly.
|
|
27
|
-
*/
|
|
28
12
|
export declare const div: (a: ClickHouseColumn | SQLExpression | number, b: ClickHouseColumn | SQLExpression | number) => SQLExpression<any>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { sql } from '../expressions';
|
|
2
|
+
export const abs = (col) => sql `abs(${col})`;
|
|
3
|
+
export const round = (col, precision) => {
|
|
4
|
+
if (precision !== undefined) {
|
|
5
|
+
return sql `round(${col}, ${precision})`;
|
|
6
|
+
}
|
|
7
|
+
return sql `round(${col})`;
|
|
8
|
+
};
|
|
9
|
+
export const floor = (col) => sql `floor(${col})`;
|
|
10
|
+
export const ceil = (col) => sql `ceil(${col})`;
|
|
11
|
+
export const sqrt = (col) => sql `sqrt(${col})`;
|
|
12
|
+
export const power = (col, exponent) => sql `power(${col}, ${exponent})`;
|
|
13
|
+
export const plus = (a, b) => sql `${a} + ${b}`;
|
|
14
|
+
export const minus = (a, b) => sql `${a} - ${b}`;
|
|
15
|
+
export const mult = (a, b) => sql `${a} * ${b}`;
|
|
16
|
+
export const div = (a, b) => sql `${a} / ${b}`;
|
package/dist/modules/string.d.ts
CHANGED
|
@@ -1,167 +1,31 @@
|
|
|
1
1
|
import { ClickHouseColumn } from '../core';
|
|
2
2
|
import { SQLExpression } from '../expressions';
|
|
3
|
-
/**
|
|
4
|
-
* Get string length
|
|
5
|
-
* @param col - Column or expression
|
|
6
|
-
*/
|
|
7
3
|
export declare function length(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
8
|
-
/**
|
|
9
|
-
* Get string length in UTF-8 bytes
|
|
10
|
-
* @param col - Column or expression
|
|
11
|
-
*/
|
|
12
4
|
export declare function lengthUTF8(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
13
|
-
/**
|
|
14
|
-
* Convert to lowercase
|
|
15
|
-
* @param col - Column or expression
|
|
16
|
-
*/
|
|
17
5
|
export declare function lower(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
18
|
-
/**
|
|
19
|
-
* Convert to uppercase
|
|
20
|
-
* @param col - Column or expression
|
|
21
|
-
*/
|
|
22
6
|
export declare function upper(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
23
|
-
/**
|
|
24
|
-
* Reverse string
|
|
25
|
-
* @param col - Column or expression
|
|
26
|
-
*/
|
|
27
7
|
export declare function reverse(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
28
|
-
/**
|
|
29
|
-
* Repeat string N times
|
|
30
|
-
* @param col - Column or expression
|
|
31
|
-
* @param n - Number of repetitions
|
|
32
|
-
*/
|
|
33
8
|
export declare function repeat(col: ClickHouseColumn | SQLExpression, n: number): SQLExpression;
|
|
34
|
-
/**
|
|
35
|
-
* Get substring
|
|
36
|
-
* @param col - Column or expression
|
|
37
|
-
* @param offset - Starting position (1-based)
|
|
38
|
-
* @param length - Length of substring
|
|
39
|
-
*/
|
|
40
9
|
export declare function substring(col: ClickHouseColumn | SQLExpression, offset: number, length?: number): SQLExpression;
|
|
41
|
-
/**
|
|
42
|
-
* Get substring from left
|
|
43
|
-
* @param col - Column or expression
|
|
44
|
-
* @param length - Length from left
|
|
45
|
-
*/
|
|
46
10
|
export declare function left(col: ClickHouseColumn | SQLExpression, length: number): SQLExpression;
|
|
47
|
-
/**
|
|
48
|
-
* Get substring from right
|
|
49
|
-
* @param col - Column or expression
|
|
50
|
-
* @param length - Length from right
|
|
51
|
-
*/
|
|
52
11
|
export declare function right(col: ClickHouseColumn | SQLExpression, length: number): SQLExpression;
|
|
53
|
-
/**
|
|
54
|
-
* Trim whitespace from string
|
|
55
|
-
* @param col - Column or expression
|
|
56
|
-
*/
|
|
57
12
|
export declare function stringTrim(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
58
|
-
/**
|
|
59
|
-
* Trim left whitespace
|
|
60
|
-
* @param col - Column or expression
|
|
61
|
-
*/
|
|
62
13
|
export declare function stringTrimLeft(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
63
|
-
/**
|
|
64
|
-
* Trim right whitespace
|
|
65
|
-
* @param col - Column or expression
|
|
66
|
-
*/
|
|
67
14
|
export declare function stringTrimRight(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
68
|
-
/**
|
|
69
|
-
* Check if string contains substring
|
|
70
|
-
* @param col - Column or expression
|
|
71
|
-
* @param substring - Substring to search for
|
|
72
|
-
*/
|
|
73
15
|
export declare function contains(col: ClickHouseColumn | SQLExpression, substring: string): SQLExpression;
|
|
74
|
-
/**
|
|
75
|
-
* Check if string starts with substring
|
|
76
|
-
* @param col - Column or expression
|
|
77
|
-
* @param substring - Substring to check
|
|
78
|
-
*/
|
|
79
16
|
export declare function startsWith(col: ClickHouseColumn | SQLExpression, substring: string): SQLExpression;
|
|
80
|
-
/**
|
|
81
|
-
* Check if string ends with substring
|
|
82
|
-
* @param col - Column or expression
|
|
83
|
-
* @param substring - Substring to check
|
|
84
|
-
*/
|
|
85
17
|
export declare function endsWith(col: ClickHouseColumn | SQLExpression, substring: string): SQLExpression;
|
|
86
|
-
/**
|
|
87
|
-
* Find position of substring
|
|
88
|
-
* @param col - Column or expression
|
|
89
|
-
* @param substring - Substring to find
|
|
90
|
-
*/
|
|
91
18
|
export declare function position(col: ClickHouseColumn | SQLExpression, substring: string): SQLExpression;
|
|
92
|
-
/**
|
|
93
|
-
* Count occurrences of substring
|
|
94
|
-
* @param col - Column or expression
|
|
95
|
-
* @param substring - Substring to count
|
|
96
|
-
*/
|
|
97
19
|
export declare function countMatches(col: ClickHouseColumn | SQLExpression, substring: string): SQLExpression;
|
|
98
|
-
/**
|
|
99
|
-
* Concatenate strings
|
|
100
|
-
* @param cols - Strings to concatenate
|
|
101
|
-
*/
|
|
102
20
|
export declare function concat(...cols: (ClickHouseColumn | SQLExpression | string)[]): SQLExpression;
|
|
103
|
-
/**
|
|
104
|
-
* Replace all occurrences of substring
|
|
105
|
-
* @param col - Column or expression
|
|
106
|
-
* @param pattern - Pattern to replace
|
|
107
|
-
* @param replacement - Replacement string
|
|
108
|
-
*/
|
|
109
21
|
export declare function replace(col: ClickHouseColumn | SQLExpression, pattern: string, replacement: string): SQLExpression;
|
|
110
|
-
/**
|
|
111
|
-
* Replace using regex
|
|
112
|
-
* @param col - Column or expression
|
|
113
|
-
* @param pattern - Regex pattern
|
|
114
|
-
* @param replacement - Replacement string
|
|
115
|
-
*/
|
|
116
22
|
export declare function replaceRegexpAll(col: ClickHouseColumn | SQLExpression, pattern: string, replacement: string): SQLExpression;
|
|
117
|
-
/**
|
|
118
|
-
* Match using regex (returns 1 if matches, 0 if not)
|
|
119
|
-
* @param col - Column or expression
|
|
120
|
-
* @param pattern - Regex pattern
|
|
121
|
-
*/
|
|
122
23
|
export declare function match(col: ClickHouseColumn | SQLExpression, pattern: string): SQLExpression;
|
|
123
|
-
/**
|
|
124
|
-
* Check if string matches pattern (LIKE)
|
|
125
|
-
* @param col - Column or expression
|
|
126
|
-
* @param pattern - Pattern to match
|
|
127
|
-
*/
|
|
128
24
|
export declare function like(col: ClickHouseColumn | SQLExpression, pattern: string): SQLExpression;
|
|
129
|
-
/**
|
|
130
|
-
* Check if string matches pattern (NOT LIKE)
|
|
131
|
-
* @param col - Column or expression
|
|
132
|
-
* @param pattern - Pattern to match
|
|
133
|
-
*/
|
|
134
25
|
export declare function notLike(col: ClickHouseColumn | SQLExpression, pattern: string): SQLExpression;
|
|
135
|
-
/**
|
|
136
|
-
* Check if string matches pattern (ILIKE - case insensitive)
|
|
137
|
-
* @param col - Column or expression
|
|
138
|
-
* @param pattern - Pattern to match
|
|
139
|
-
*/
|
|
140
26
|
export declare function ilike(col: ClickHouseColumn | SQLExpression, pattern: string): SQLExpression;
|
|
141
|
-
/**
|
|
142
|
-
* Check if string matches pattern (NOT ILIKE)
|
|
143
|
-
* @param col - Column or expression
|
|
144
|
-
* @param pattern - Pattern to match
|
|
145
|
-
*/
|
|
146
27
|
export declare function notIlike(col: ClickHouseColumn | SQLExpression, pattern: string): SQLExpression;
|
|
147
|
-
/**
|
|
148
|
-
* Calculate SHA1 hash
|
|
149
|
-
* @param col - Column or expression
|
|
150
|
-
*/
|
|
151
28
|
export declare function sha1(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
152
|
-
/**
|
|
153
|
-
* Calculate SIP hash
|
|
154
|
-
* @param col - Column or expression
|
|
155
|
-
*/
|
|
156
29
|
export declare function sipHash64(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
157
|
-
/**
|
|
158
|
-
* Split string by delimiter
|
|
159
|
-
* @param col - Column or expression
|
|
160
|
-
* @param delimiter - Delimiter string
|
|
161
|
-
*/
|
|
162
30
|
export declare function splitByChar(col: ClickHouseColumn | SQLExpression, delimiter: string): SQLExpression;
|
|
163
|
-
/**
|
|
164
|
-
* Split string by whitespace
|
|
165
|
-
* @param col - Column or expression
|
|
166
|
-
*/
|
|
167
31
|
export declare function splitByWhitespace(col: ClickHouseColumn | SQLExpression): SQLExpression;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { sql } from '../expressions';
|
|
2
|
+
export function length(col) {
|
|
3
|
+
return sql `length(${col})`;
|
|
4
|
+
}
|
|
5
|
+
export function lengthUTF8(col) {
|
|
6
|
+
return sql `lengthUTF8(${col})`;
|
|
7
|
+
}
|
|
8
|
+
export function lower(col) {
|
|
9
|
+
return sql `lower(${col})`;
|
|
10
|
+
}
|
|
11
|
+
export function upper(col) {
|
|
12
|
+
return sql `upper(${col})`;
|
|
13
|
+
}
|
|
14
|
+
export function reverse(col) {
|
|
15
|
+
return sql `reverse(${col})`;
|
|
16
|
+
}
|
|
17
|
+
export function repeat(col, n) {
|
|
18
|
+
return sql `repeat(${col}, ${n})`;
|
|
19
|
+
}
|
|
20
|
+
export function substring(col, offset, length) {
|
|
21
|
+
return length ? sql `substring(${col}, ${offset}, ${length})` : sql `substring(${col}, ${offset})`;
|
|
22
|
+
}
|
|
23
|
+
export function left(col, length) {
|
|
24
|
+
return sql `left(${col}, ${length})`;
|
|
25
|
+
}
|
|
26
|
+
export function right(col, length) {
|
|
27
|
+
return sql `right(${col}, ${length})`;
|
|
28
|
+
}
|
|
29
|
+
export function stringTrim(col) {
|
|
30
|
+
return sql `trim(${col})`;
|
|
31
|
+
}
|
|
32
|
+
export function stringTrimLeft(col) {
|
|
33
|
+
return sql `trimLeft(${col})`;
|
|
34
|
+
}
|
|
35
|
+
export function stringTrimRight(col) {
|
|
36
|
+
return sql `trimRight(${col})`;
|
|
37
|
+
}
|
|
38
|
+
export function contains(col, substring) {
|
|
39
|
+
return sql `contains(${col}, ${substring})`;
|
|
40
|
+
}
|
|
41
|
+
export function startsWith(col, substring) {
|
|
42
|
+
return sql `startsWith(${col}, ${substring})`;
|
|
43
|
+
}
|
|
44
|
+
export function endsWith(col, substring) {
|
|
45
|
+
return sql `endsWith(${col}, ${substring})`;
|
|
46
|
+
}
|
|
47
|
+
export function position(col, substring) {
|
|
48
|
+
return sql `position(${substring}, ${col})`;
|
|
49
|
+
}
|
|
50
|
+
export function countMatches(col, substring) {
|
|
51
|
+
return sql `countMatches(${col}, ${substring})`;
|
|
52
|
+
}
|
|
53
|
+
export function concat(...cols) {
|
|
54
|
+
const params = cols.map(col => sql `${col}`).join(', ');
|
|
55
|
+
return sql `concat(${params})`;
|
|
56
|
+
}
|
|
57
|
+
export function replace(col, pattern, replacement) {
|
|
58
|
+
return sql `replace(${col}, ${pattern}, ${replacement})`;
|
|
59
|
+
}
|
|
60
|
+
export function replaceRegexpAll(col, pattern, replacement) {
|
|
61
|
+
return sql `replaceRegexpAll(${col}, ${pattern}, ${replacement})`;
|
|
62
|
+
}
|
|
63
|
+
export function match(col, pattern) {
|
|
64
|
+
return sql `match(${col}, ${pattern})`;
|
|
65
|
+
}
|
|
66
|
+
export function like(col, pattern) {
|
|
67
|
+
return sql `${col} LIKE ${pattern}`;
|
|
68
|
+
}
|
|
69
|
+
export function notLike(col, pattern) {
|
|
70
|
+
return sql `${col} NOT LIKE ${pattern}`;
|
|
71
|
+
}
|
|
72
|
+
export function ilike(col, pattern) {
|
|
73
|
+
return sql `${col} ILIKE ${pattern}`;
|
|
74
|
+
}
|
|
75
|
+
export function notIlike(col, pattern) {
|
|
76
|
+
return sql `${col} NOT ILIKE ${pattern}`;
|
|
77
|
+
}
|
|
78
|
+
export function sha1(col) {
|
|
79
|
+
return sql `sha1(${col})`;
|
|
80
|
+
}
|
|
81
|
+
export function sipHash64(col) {
|
|
82
|
+
return sql `sipHash64(${col})`;
|
|
83
|
+
}
|
|
84
|
+
export function splitByChar(col, delimiter) {
|
|
85
|
+
return sql `splitByChar(${col}, ${delimiter})`;
|
|
86
|
+
}
|
|
87
|
+
export function splitByWhitespace(col) {
|
|
88
|
+
return sql `splitByWhitespace(${col})`;
|
|
89
|
+
}
|