@hypequery/clickhouse 1.5.0 → 1.6.1
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/LICENSE +201 -0
- package/README.md +19 -14
- package/dist/cli/generate-types.js +5 -12
- package/dist/core/adapters/clickhouse-adapter.d.ts +14 -0
- package/dist/core/adapters/clickhouse-adapter.d.ts.map +1 -0
- package/dist/core/adapters/clickhouse-adapter.js +58 -0
- package/dist/core/adapters/database-adapter.d.ts +13 -0
- package/dist/core/adapters/database-adapter.d.ts.map +1 -0
- package/dist/core/adapters/database-adapter.js +1 -0
- package/dist/core/cache/cache-manager.d.ts.map +1 -1
- package/dist/core/cache/cache-manager.js +6 -5
- package/dist/core/dialects/clickhouse-dialect.d.ts +10 -0
- package/dist/core/dialects/clickhouse-dialect.d.ts.map +1 -0
- package/dist/core/dialects/clickhouse-dialect.js +47 -0
- package/dist/core/dialects/sql-dialect.d.ts +11 -0
- package/dist/core/dialects/sql-dialect.d.ts.map +1 -0
- package/dist/core/dialects/sql-dialect.js +1 -0
- package/dist/core/features/aggregations.d.ts +5 -5
- package/dist/core/features/analytics.d.ts +822 -4
- package/dist/core/features/analytics.d.ts.map +1 -1
- package/dist/core/features/analytics.js +15 -9
- package/dist/core/features/executor.d.ts.map +1 -1
- package/dist/core/features/executor.js +26 -53
- package/dist/core/features/filtering.d.ts +5 -5
- package/dist/core/features/joins.d.ts +1 -1
- package/dist/core/features/query-modifiers.d.ts +6 -6
- package/dist/core/query-builder.d.ts +20 -7
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +45 -32
- package/dist/core/tests/integration/setup.d.ts +3 -1
- package/dist/core/tests/integration/setup.d.ts.map +1 -1
- package/dist/core/tests/test-utils.d.ts.map +1 -1
- package/dist/core/tests/test-utils.js +16 -4
- package/dist/core/types/builder-state.d.ts +7 -5
- package/dist/core/types/builder-state.d.ts.map +1 -1
- package/dist/core/types/select-types.d.ts +4 -3
- package/dist/core/types/select-types.d.ts.map +1 -1
- package/dist/core/utils/predicate-builder.d.ts +4 -0
- package/dist/core/utils/predicate-builder.d.ts.map +1 -1
- package/dist/core/utils/predicate-builder.js +4 -1
- package/dist/core/utils/streaming-helpers.d.ts.map +1 -1
- package/dist/core/utils/streaming-helpers.js +8 -0
- package/dist/core/utils.d.ts.map +1 -1
- package/dist/core/utils.js +3 -0
- package/dist/dataset/definition.d.ts +135 -0
- package/dist/dataset/definition.d.ts.map +1 -0
- package/dist/dataset/definition.js +265 -0
- package/dist/dataset/helpers.d.ts +136 -0
- package/dist/dataset/helpers.d.ts.map +1 -0
- package/dist/dataset/helpers.js +189 -0
- package/dist/dataset/index.d.ts +51 -0
- package/dist/dataset/index.d.ts.map +1 -0
- package/dist/dataset/index.js +59 -0
- package/dist/dataset/introspection.d.ts +133 -0
- package/dist/dataset/introspection.d.ts.map +1 -0
- package/dist/dataset/introspection.js +239 -0
- package/dist/dataset/sql-tag.d.ts +51 -0
- package/dist/dataset/sql-tag.d.ts.map +1 -0
- package/dist/dataset/sql-tag.js +86 -0
- package/dist/dataset/types.d.ts +300 -0
- package/dist/dataset/types.d.ts.map +1 -0
- package/dist/dataset/types.js +11 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -15
- package/dist/migrations/config/index.d.ts +3 -0
- package/dist/migrations/config/index.d.ts.map +1 -0
- package/dist/migrations/config/index.js +1 -0
- package/dist/migrations/config/types.d.ts +45 -0
- package/dist/migrations/config/types.d.ts.map +1 -0
- package/dist/migrations/config/types.js +28 -0
- package/dist/migrations/diff/diff.d.ts +11 -0
- package/dist/migrations/diff/diff.d.ts.map +1 -0
- package/dist/migrations/diff/diff.js +240 -0
- package/dist/migrations/diff/index.d.ts +3 -0
- package/dist/migrations/diff/index.d.ts.map +1 -0
- package/dist/migrations/diff/index.js +1 -0
- package/dist/migrations/diff/types.d.ts +74 -0
- package/dist/migrations/diff/types.d.ts.map +1 -0
- package/dist/migrations/diff/types.js +1 -0
- package/dist/migrations/schema/column.d.ts +71 -0
- package/dist/migrations/schema/column.d.ts.map +1 -0
- package/dist/migrations/schema/column.js +123 -0
- package/dist/migrations/schema/define.d.ts +24 -0
- package/dist/migrations/schema/define.d.ts.map +1 -0
- package/dist/migrations/schema/define.js +47 -0
- package/dist/migrations/schema/index.d.ts +4 -0
- package/dist/migrations/schema/index.d.ts.map +1 -0
- package/dist/migrations/schema/index.js +2 -0
- package/dist/migrations/schema/types.d.ts +74 -0
- package/dist/migrations/schema/types.d.ts.map +1 -0
- package/dist/migrations/schema/types.js +1 -0
- package/dist/migrations/snapshot/index.d.ts +3 -0
- package/dist/migrations/snapshot/index.d.ts.map +1 -0
- package/dist/migrations/snapshot/index.js +1 -0
- package/dist/migrations/snapshot/serialize.d.ts +21 -0
- package/dist/migrations/snapshot/serialize.d.ts.map +1 -0
- package/dist/migrations/snapshot/serialize.js +127 -0
- package/dist/migrations/snapshot/types.d.ts +47 -0
- package/dist/migrations/snapshot/types.d.ts.map +1 -0
- package/dist/migrations/snapshot/types.js +1 -0
- package/dist/migrations/sql/index.d.ts +4 -0
- package/dist/migrations/sql/index.d.ts.map +1 -0
- package/dist/migrations/sql/index.js +2 -0
- package/dist/migrations/sql/render.d.ts +11 -0
- package/dist/migrations/sql/render.d.ts.map +1 -0
- package/dist/migrations/sql/render.js +334 -0
- package/dist/migrations/sql/types.d.ts +48 -0
- package/dist/migrations/sql/types.d.ts.map +1 -0
- package/dist/migrations/sql/types.js +1 -0
- package/dist/migrations/sql/write.d.ts +9 -0
- package/dist/migrations/sql/write.d.ts.map +1 -0
- package/dist/migrations/sql/write.js +31 -0
- package/dist/types/base.d.ts +2 -1
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/clickhouse-types.d.ts +3 -1
- package/dist/types/clickhouse-types.d.ts.map +1 -1
- package/package.json +20 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are advised to review the applicable
|
|
150
|
+
documentation for the specific language governing permissions and
|
|
151
|
+
limitations under each license.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 hypequery
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h1>@hypequery/clickhouse</h1>
|
|
3
|
-
<p>A
|
|
3
|
+
<p>A TypeScript-first query builder for ClickHouse and the foundation of the hypequery path.</p>
|
|
4
4
|
|
|
5
5
|
[](https://github.com/hypequery/hypequery/blob/main/LICENSE)
|
|
6
6
|
[](https://badge.fury.io/js/@hypequery%2Fclickhouse)
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
hypequery is
|
|
13
|
+
`@hypequery/clickhouse` is the first step in the main hypequery flow. Generate types from your ClickHouse schema, build typed queries locally, then promote important queries into `query({ ... })` and `serve({ queries })` when they need to be reused across your app.
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
@@ -41,6 +41,13 @@ npm install @hypequery/clickhouse @clickhouse/client-web
|
|
|
41
41
|
|
|
42
42
|
## Quick Start
|
|
43
43
|
|
|
44
|
+
Main path:
|
|
45
|
+
|
|
46
|
+
1. Generate schema types
|
|
47
|
+
2. Create a typed `db` with `createQueryBuilder(...)`
|
|
48
|
+
3. Build and execute queries locally
|
|
49
|
+
4. Add `@hypequery/serve` later if a query needs a reusable contract or HTTP surface
|
|
50
|
+
|
|
44
51
|
### Node.js Environments
|
|
45
52
|
|
|
46
53
|
```typescript
|
|
@@ -126,18 +133,15 @@ const rows = await db
|
|
|
126
133
|
await db.cache.invalidateTags(['users']);
|
|
127
134
|
```
|
|
128
135
|
|
|
129
|
-
Use `.cache()` to attach defaults to a fluent chain, pass `execute({ cache: { ... } })` for one-off overrides, or call `db.cache.*` for manual invalidation. For a deep dive on cache modes, invalidation, advanced serialization, and bring-your-own-provider recipes (Redis/Upstash, compression, etc.), see the [Caching guide](https://hypequery.com/docs/
|
|
136
|
+
Use `.cache()` to attach defaults to a fluent chain, pass `execute({ cache: { ... } })` for one-off overrides, or call `db.cache.*` for manual invalidation. For a deep dive on cache modes, invalidation, advanced serialization, and bring-your-own-provider recipes (Redis/Upstash, compression, etc.), see the [Caching guide](https://hypequery.com/docs/caching).
|
|
130
137
|
|
|
131
138
|
## Schema Generation
|
|
132
139
|
|
|
133
|
-
|
|
140
|
+
Use the hypequery CLI to generate TypeScript types from your ClickHouse schema:
|
|
134
141
|
|
|
135
142
|
```bash
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
# Generate schema types
|
|
140
|
-
npx hypequery-generate-types --host your-clickhouse-host --database your-database
|
|
143
|
+
npm install -D @hypequery/cli
|
|
144
|
+
npx hypequery generate
|
|
141
145
|
```
|
|
142
146
|
|
|
143
147
|
This creates a `generated-schema.ts` file that you can import in your application:
|
|
@@ -278,12 +282,13 @@ hypequery follows semantic versioning and provides multiple release channels:
|
|
|
278
282
|
|
|
279
283
|
## Documentation
|
|
280
284
|
|
|
281
|
-
For detailed documentation and examples, visit
|
|
285
|
+
For detailed documentation and examples, visit the main docs flow.
|
|
282
286
|
|
|
283
|
-
- [
|
|
284
|
-
- [
|
|
285
|
-
- [
|
|
286
|
-
- [
|
|
287
|
+
- [Quick Start](https://hypequery.com/docs/quick-start)
|
|
288
|
+
- [Core Concepts](https://hypequery.com/docs/core-concepts)
|
|
289
|
+
- [Query Building](https://hypequery.com/docs/query-building/basics)
|
|
290
|
+
- [Filtering](https://hypequery.com/docs/query-building/where)
|
|
291
|
+
- [API Reference](https://hypequery.com/docs/reference/query-builder)
|
|
287
292
|
|
|
288
293
|
|
|
289
294
|
## Troubleshooting
|
|
@@ -23,7 +23,7 @@ dotenv.config();
|
|
|
23
23
|
* @param {string} type - The ClickHouse type to convert
|
|
24
24
|
* @returns {string} - The corresponding TypeScript type
|
|
25
25
|
*/
|
|
26
|
-
const clickhouseToTsType = (type) => {
|
|
26
|
+
export const clickhouseToTsType = (type) => {
|
|
27
27
|
if (type.startsWith('Array(')) {
|
|
28
28
|
const innerType = type.slice(6, -1);
|
|
29
29
|
return `Array<${clickhouseToTsType(innerType)}>`;
|
|
@@ -44,14 +44,6 @@ const clickhouseToTsType = (type) => {
|
|
|
44
44
|
const keyType = mapContent.substring(0, commaIndex).trim();
|
|
45
45
|
const valueType = mapContent.substring(commaIndex + 1).trim();
|
|
46
46
|
|
|
47
|
-
// Handle different key types
|
|
48
|
-
let keyTsType = 'string';
|
|
49
|
-
if (keyType === 'LowCardinality(String)') {
|
|
50
|
-
keyTsType = 'string';
|
|
51
|
-
} else if (keyType.includes('Int') || keyType.includes('UInt')) {
|
|
52
|
-
keyTsType = 'number';
|
|
53
|
-
}
|
|
54
|
-
|
|
55
47
|
// Handle different value types
|
|
56
48
|
let valueTsType = 'unknown';
|
|
57
49
|
if (valueType.startsWith('Array(')) {
|
|
@@ -64,7 +56,8 @@ const clickhouseToTsType = (type) => {
|
|
|
64
56
|
valueTsType = clickhouseToTsType(valueType);
|
|
65
57
|
}
|
|
66
58
|
|
|
67
|
-
|
|
59
|
+
// JSON object keys are strings even when ClickHouse map keys are numeric.
|
|
60
|
+
return `Record<string, ${valueTsType}>`;
|
|
68
61
|
}
|
|
69
62
|
return 'Record<string, unknown>';
|
|
70
63
|
}
|
|
@@ -77,11 +70,11 @@ const clickhouseToTsType = (type) => {
|
|
|
77
70
|
case 'int16':
|
|
78
71
|
case 'int32':
|
|
79
72
|
case 'uint8':
|
|
80
|
-
case 'int64':
|
|
81
73
|
case 'uint16':
|
|
82
74
|
case 'uint32':
|
|
83
|
-
case 'uint64':
|
|
84
75
|
return 'number';
|
|
76
|
+
case 'int64':
|
|
77
|
+
case 'uint64':
|
|
85
78
|
case 'uint128':
|
|
86
79
|
case 'uint256':
|
|
87
80
|
case 'int128':
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DatabaseAdapter, QueryExecutionOptions } from './database-adapter.js';
|
|
2
|
+
import type { ClickHouseConfig } from '../query-builder.js';
|
|
3
|
+
export declare class ClickHouseAdapter implements DatabaseAdapter {
|
|
4
|
+
private config;
|
|
5
|
+
readonly name = "clickhouse";
|
|
6
|
+
readonly namespace?: string;
|
|
7
|
+
private client;
|
|
8
|
+
constructor(config: ClickHouseConfig);
|
|
9
|
+
query<T>(sql: string, params?: unknown[], options?: QueryExecutionOptions): Promise<T[]>;
|
|
10
|
+
stream<T>(sql: string, params?: unknown[], options?: QueryExecutionOptions): Promise<ReadableStream<T[]>>;
|
|
11
|
+
render(sql: string, params?: unknown[]): string;
|
|
12
|
+
}
|
|
13
|
+
export declare function createClickHouseAdapter(config: ClickHouseConfig): DatabaseAdapter;
|
|
14
|
+
//# sourceMappingURL=clickhouse-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clickhouse-adapter.d.ts","sourceRoot":"","sources":["../../../src/core/adapters/clickhouse-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAGpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AA2B5D,qBAAa,iBAAkB,YAAW,eAAe;IAK3C,OAAO,CAAC,MAAM;IAJ1B,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,MAAM,CAAmB;gBAEb,MAAM,EAAE,gBAAgB;IAKtC,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAW5F,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;IAYnH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,MAAM;CAGpD;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,gBAAgB,GAAG,eAAe,CAEjF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isClientConfig } from '../query-builder.js';
|
|
2
|
+
import { substituteParameters } from '../utils.js';
|
|
3
|
+
import { createJsonEachRowStream } from '../utils/streaming-helpers.js';
|
|
4
|
+
import { getAutoClientModule } from '../env/auto-client.js';
|
|
5
|
+
function createClickHouseClient(config) {
|
|
6
|
+
if (isClientConfig(config)) {
|
|
7
|
+
return config.client;
|
|
8
|
+
}
|
|
9
|
+
const clientModule = getAutoClientModule();
|
|
10
|
+
return clientModule.createClient(config);
|
|
11
|
+
}
|
|
12
|
+
function deriveNamespace(config) {
|
|
13
|
+
if ('client' in config && config.client) {
|
|
14
|
+
return 'client';
|
|
15
|
+
}
|
|
16
|
+
const host = 'host' in config ? config.host : 'unknown-host';
|
|
17
|
+
const database = 'database' in config ? config.database : 'default';
|
|
18
|
+
const username = 'username' in config ? config.username : 'default';
|
|
19
|
+
return `${host || 'unknown-host'}|${database || 'default'}|${username || 'default'}`;
|
|
20
|
+
}
|
|
21
|
+
export class ClickHouseAdapter {
|
|
22
|
+
config;
|
|
23
|
+
name = 'clickhouse';
|
|
24
|
+
namespace;
|
|
25
|
+
client;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.namespace = deriveNamespace(config);
|
|
29
|
+
this.client = createClickHouseClient(config);
|
|
30
|
+
}
|
|
31
|
+
async query(sql, params = [], options) {
|
|
32
|
+
const finalSQL = substituteParameters(sql, params);
|
|
33
|
+
const result = await this.client.query({
|
|
34
|
+
query: finalSQL,
|
|
35
|
+
format: 'JSONEachRow',
|
|
36
|
+
clickhouse_settings: options?.clickhouseSettings,
|
|
37
|
+
query_id: options?.queryId,
|
|
38
|
+
});
|
|
39
|
+
return result.json();
|
|
40
|
+
}
|
|
41
|
+
async stream(sql, params = [], options) {
|
|
42
|
+
const finalSQL = substituteParameters(sql, params);
|
|
43
|
+
const result = await this.client.query({
|
|
44
|
+
query: finalSQL,
|
|
45
|
+
format: 'JSONEachRow',
|
|
46
|
+
clickhouse_settings: options?.clickhouseSettings,
|
|
47
|
+
query_id: options?.queryId,
|
|
48
|
+
});
|
|
49
|
+
const stream = result.stream();
|
|
50
|
+
return createJsonEachRowStream(stream);
|
|
51
|
+
}
|
|
52
|
+
render(sql, params = []) {
|
|
53
|
+
return substituteParameters(sql, params);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function createClickHouseAdapter(config) {
|
|
57
|
+
return new ClickHouseAdapter(config);
|
|
58
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ClickHouseSettings } from '@clickhouse/client-common';
|
|
2
|
+
export interface QueryExecutionOptions {
|
|
3
|
+
clickhouseSettings?: ClickHouseSettings;
|
|
4
|
+
queryId?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface DatabaseAdapter {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly namespace?: string;
|
|
9
|
+
query<T>(sql: string, params?: unknown[], options?: QueryExecutionOptions): Promise<T[]>;
|
|
10
|
+
stream?<T>(sql: string, params?: unknown[], options?: QueryExecutionOptions): Promise<ReadableStream<T[]>>;
|
|
11
|
+
render?(sql: string, params?: unknown[]): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=database-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-adapter.d.ts","sourceRoot":"","sources":["../../../src/core/adapters/database-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,WAAW,qBAAqB;IACpC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IACzF,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3G,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;CAClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-manager.d.ts","sourceRoot":"","sources":["../../../src/core/cache/cache-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"cache-manager.d.ts","sourceRoot":"","sources":["../../../src/core/cache/cache-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AA4DnF,wBAAsB,gBAAgB,CACpC,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACvC,KAAK,SAAS,eAAe,EAE7B,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,EACpC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CA4J5B"}
|
|
@@ -14,11 +14,10 @@ function deriveTags(builder) {
|
|
|
14
14
|
joins.forEach(join => tags.add(join.table));
|
|
15
15
|
return Array.from(tags);
|
|
16
16
|
}
|
|
17
|
-
async function logCacheHit({
|
|
18
|
-
const finalSQL = substituteParameters(sql, parameters);
|
|
17
|
+
async function logCacheHit({ renderSql, parameters, status, cacheKey, options, rowCount, ageMs, queryId }) {
|
|
19
18
|
const timestamp = Date.now();
|
|
20
19
|
logger.logQuery({
|
|
21
|
-
query:
|
|
20
|
+
query: renderSql,
|
|
22
21
|
parameters,
|
|
23
22
|
startTime: timestamp,
|
|
24
23
|
endTime: timestamp,
|
|
@@ -46,13 +45,15 @@ export async function executeWithCache(builder, options) {
|
|
|
46
45
|
}
|
|
47
46
|
const activeProvider = provider;
|
|
48
47
|
const { sql, parameters } = builder.toSQLWithParams();
|
|
48
|
+
const adapter = builder.getAdapter();
|
|
49
|
+
const renderSql = adapter.render ? adapter.render(sql, parameters) : substituteParameters(sql, parameters);
|
|
49
50
|
const tableName = builder.getTableName();
|
|
50
51
|
const namespace = mergedOptions.namespace || runtime.namespace;
|
|
51
52
|
const key = mergedOptions.key || computeCacheKey({
|
|
52
53
|
namespace,
|
|
53
54
|
sql,
|
|
54
55
|
parameters,
|
|
55
|
-
settings: builder.getConfig().settings
|
|
56
|
+
settings: builder.getConfig().settings,
|
|
56
57
|
version: runtime.versionTag,
|
|
57
58
|
tableName
|
|
58
59
|
});
|
|
@@ -82,7 +83,7 @@ export async function executeWithCache(builder, options) {
|
|
|
82
83
|
runtime.stats.staleHits += 1;
|
|
83
84
|
}
|
|
84
85
|
await logCacheHit({
|
|
85
|
-
|
|
86
|
+
renderSql,
|
|
86
87
|
parameters,
|
|
87
88
|
status,
|
|
88
89
|
cacheKey: key,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { QueryConfig } from '../../types/index.js';
|
|
2
|
+
import type { CompileQueryContext, SqlDialect } from './sql-dialect.js';
|
|
3
|
+
export declare class ClickHouseDialect implements SqlDialect {
|
|
4
|
+
readonly name = "clickhouse";
|
|
5
|
+
private formatter;
|
|
6
|
+
compileQuery(config: QueryConfig<any, any>, context: CompileQueryContext): string;
|
|
7
|
+
formatTimeInterval(column: string, interval: string, method: string): string;
|
|
8
|
+
formatSettings(settings: Record<string, unknown>): string;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=clickhouse-dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clickhouse-dialect.d.ts","sourceRoot":"","sources":["../../../src/core/dialects/clickhouse-dialect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAExE,qBAAa,iBAAkB,YAAW,UAAU;IAClD,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,OAAO,CAAC,SAAS,CAAsB;IAEvC,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM;IAyCjF,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAQ5E,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;CAK1D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SQLFormatter } from '../formatters/sql-formatter.js';
|
|
2
|
+
export class ClickHouseDialect {
|
|
3
|
+
name = 'clickhouse';
|
|
4
|
+
formatter = new SQLFormatter();
|
|
5
|
+
compileQuery(config, context) {
|
|
6
|
+
const parts = [];
|
|
7
|
+
if (config.ctes?.length) {
|
|
8
|
+
parts.push(`WITH ${config.ctes.join(', ')}`);
|
|
9
|
+
}
|
|
10
|
+
parts.push(`SELECT ${this.formatter.formatSelect(config)}`);
|
|
11
|
+
parts.push(`FROM ${context.tableName}`);
|
|
12
|
+
if (config.joins?.length) {
|
|
13
|
+
parts.push(this.formatter.formatJoins(config));
|
|
14
|
+
}
|
|
15
|
+
if (config.where?.length) {
|
|
16
|
+
parts.push(`WHERE ${this.formatter.formatWhere(config)}`);
|
|
17
|
+
}
|
|
18
|
+
if (config.groupBy?.length) {
|
|
19
|
+
parts.push(`GROUP BY ${this.formatter.formatGroupBy(config)}`);
|
|
20
|
+
}
|
|
21
|
+
if (config.having?.length) {
|
|
22
|
+
parts.push(`HAVING ${config.having.join(' AND ')}`);
|
|
23
|
+
}
|
|
24
|
+
if (config.orderBy?.length) {
|
|
25
|
+
const orderBy = config.orderBy
|
|
26
|
+
.map(({ column, direction }) => `${String(column)} ${direction}`.trim())
|
|
27
|
+
.join(', ');
|
|
28
|
+
parts.push(`ORDER BY ${orderBy}`);
|
|
29
|
+
}
|
|
30
|
+
if (config.limit) {
|
|
31
|
+
const offsetClause = config.offset ? `OFFSET ${config.offset}` : '';
|
|
32
|
+
parts.push(`LIMIT ${config.limit} ${offsetClause}`);
|
|
33
|
+
}
|
|
34
|
+
return parts.join(' ').trim();
|
|
35
|
+
}
|
|
36
|
+
formatTimeInterval(column, interval, method) {
|
|
37
|
+
if (method === 'toStartOfInterval') {
|
|
38
|
+
return `${method}(${column}, INTERVAL ${interval})`;
|
|
39
|
+
}
|
|
40
|
+
return `${method}(${column})`;
|
|
41
|
+
}
|
|
42
|
+
formatSettings(settings) {
|
|
43
|
+
return Object.entries(settings)
|
|
44
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
45
|
+
.join(', ');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { QueryConfig } from '../../types/index.js';
|
|
2
|
+
export interface CompileQueryContext {
|
|
3
|
+
tableName: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SqlDialect {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
compileQuery(config: QueryConfig<any, any>, context: CompileQueryContext): string;
|
|
8
|
+
formatTimeInterval(column: string, interval: string, method: string): string;
|
|
9
|
+
formatSettings(settings: Record<string, unknown>): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=sql-dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-dialect.d.ts","sourceRoot":"","sources":["../../../src/core/dialects/sql-dialect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAClF,kBAAkB,CAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC;IACV,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;CAC3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -20,7 +20,7 @@ export declare class AggregationFeature<Schema extends SchemaDefinition<Schema>,
|
|
|
20
20
|
parameters?: any[];
|
|
21
21
|
ctes?: string[];
|
|
22
22
|
unionQueries?: string[];
|
|
23
|
-
settings?:
|
|
23
|
+
settings?: import("@clickhouse/client-common").ClickHouseSettings;
|
|
24
24
|
};
|
|
25
25
|
count(column: string, alias: string): {
|
|
26
26
|
select: string[];
|
|
@@ -38,7 +38,7 @@ export declare class AggregationFeature<Schema extends SchemaDefinition<Schema>,
|
|
|
38
38
|
parameters?: any[];
|
|
39
39
|
ctes?: string[];
|
|
40
40
|
unionQueries?: string[];
|
|
41
|
-
settings?:
|
|
41
|
+
settings?: import("@clickhouse/client-common").ClickHouseSettings;
|
|
42
42
|
};
|
|
43
43
|
avg(column: string, alias: string): {
|
|
44
44
|
select: string[];
|
|
@@ -56,7 +56,7 @@ export declare class AggregationFeature<Schema extends SchemaDefinition<Schema>,
|
|
|
56
56
|
parameters?: any[];
|
|
57
57
|
ctes?: string[];
|
|
58
58
|
unionQueries?: string[];
|
|
59
|
-
settings?:
|
|
59
|
+
settings?: import("@clickhouse/client-common").ClickHouseSettings;
|
|
60
60
|
};
|
|
61
61
|
min(column: string, alias: string): {
|
|
62
62
|
select: string[];
|
|
@@ -74,7 +74,7 @@ export declare class AggregationFeature<Schema extends SchemaDefinition<Schema>,
|
|
|
74
74
|
parameters?: any[];
|
|
75
75
|
ctes?: string[];
|
|
76
76
|
unionQueries?: string[];
|
|
77
|
-
settings?:
|
|
77
|
+
settings?: import("@clickhouse/client-common").ClickHouseSettings;
|
|
78
78
|
};
|
|
79
79
|
max(column: string, alias: string): {
|
|
80
80
|
select: string[];
|
|
@@ -92,7 +92,7 @@ export declare class AggregationFeature<Schema extends SchemaDefinition<Schema>,
|
|
|
92
92
|
parameters?: any[];
|
|
93
93
|
ctes?: string[];
|
|
94
94
|
unionQueries?: string[];
|
|
95
|
-
settings?:
|
|
95
|
+
settings?: import("@clickhouse/client-common").ClickHouseSettings;
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
//# sourceMappingURL=aggregations.d.ts.map
|