@housekit/orm 0.1.3 → 0.1.5
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 +26 -0
- package/dist/relational.d.ts +39 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
**The high-performance, type-safe ClickHouse ORM for Node.js and Bun.**
|
|
4
4
|
|
|
5
|
+
> ⚠️ **Public Beta**: This package is currently in public beta. Feedback is highly appreciated as we polish the API for v1.0.
|
|
6
|
+
|
|
5
7
|
HouseKit ORM is a modern database toolkit designed specifically for ClickHouse. It bridges the gap between ergonomic developer experiences and the extreme performance requirements of high-volume OLAP workloads.
|
|
6
8
|
|
|
7
9
|
[](https://www.npmjs.com/package/@housekit/orm)
|
|
@@ -180,6 +182,30 @@ const usersWithData = await db.query.users.findMany({
|
|
|
180
182
|
// [{ id: 1, name: 'Alice', posts: [{ title: '...', ... }], profile: { bio: '...' } }]
|
|
181
183
|
```
|
|
182
184
|
|
|
185
|
+
### Advanced Relational Engine
|
|
186
|
+
HouseKit's relational API is optimized for ClickHouse:
|
|
187
|
+
- **Filtered Relations**: Where clauses in `with` blocks are executed server-side using `groupUniqArrayIf`.
|
|
188
|
+
- **Nested Pagination**: Control the size of related collections with `limit` and `offset` directly in the relation config.
|
|
189
|
+
- **Smart Deduplication**: Merges results in-memory to handle row multiplication from complex joins.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 🛠 SQL Utilities
|
|
194
|
+
|
|
195
|
+
### Dynamic Queries with `sql.join`
|
|
196
|
+
Easily build complex queries by joining SQL fragments with separators.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const conditions = [
|
|
200
|
+
eq(users.active, true),
|
|
201
|
+
gte(users.age, 18)
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
const query = db.select()
|
|
205
|
+
.from(users)
|
|
206
|
+
.where(sql.join(conditions, sql` AND `));
|
|
207
|
+
```
|
|
208
|
+
|
|
183
209
|
---
|
|
184
210
|
|
|
185
211
|
## 🔍 Specialized ClickHouse Joins
|
package/dist/relational.d.ts
CHANGED
|
@@ -1,33 +1,61 @@
|
|
|
1
1
|
import { type TableDefinition } from './core';
|
|
2
2
|
import type { SQLExpression } from './expressions';
|
|
3
3
|
/**
|
|
4
|
-
* Join strategy for relational queries
|
|
4
|
+
* Join strategy for relational queries.
|
|
5
|
+
*
|
|
6
|
+
* ClickHouse performance varies significantly depending on the join strategy used,
|
|
7
|
+
* especially in distributed environments.
|
|
5
8
|
*/
|
|
6
9
|
export type JoinStrategy = 'auto' | 'standard' | 'global' | 'any' | 'global_any';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for the Relational Query API (`findMany`, `findFirst`).
|
|
12
|
+
*/
|
|
7
13
|
export type RelationalFindOptions<TTable = any> = {
|
|
14
|
+
/**
|
|
15
|
+
* Filter conditions for the main query.
|
|
16
|
+
* Can be a SQL expression or a callback receiving the table columns.
|
|
17
|
+
*
|
|
18
|
+
* @example where: (users) => eq(users.active, true)
|
|
19
|
+
*/
|
|
8
20
|
where?: SQLExpression | ((columns: TTable extends TableDefinition<infer TCols> ? TCols : any) => SQLExpression);
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of records to return from the primary table.
|
|
23
|
+
*/
|
|
9
24
|
limit?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Number of records to skip from the primary table.
|
|
27
|
+
*/
|
|
10
28
|
offset?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Nested relations to include in the result set.
|
|
31
|
+
* Set to `true` for all columns or provide a `RelationalFindOptions` object for nested filtering/limiting.
|
|
32
|
+
*
|
|
33
|
+
* @example with: { posts: { limit: 5 }, profile: true }
|
|
34
|
+
*/
|
|
11
35
|
with?: Record<string, boolean | RelationalFindOptions>;
|
|
12
36
|
/**
|
|
13
37
|
* Join strategy for related data.
|
|
14
38
|
*
|
|
15
|
-
* - 'auto': Automatically uses GLOBAL when table has onCluster option
|
|
16
|
-
* - 'standard': Regular LEFT JOIN
|
|
17
|
-
* - 'global': Force GLOBAL JOIN (for clusters)
|
|
18
|
-
* - 'any': Use ANY JOIN (faster,
|
|
19
|
-
* - 'global_any': Combine GLOBAL and ANY
|
|
39
|
+
* - 'auto': Automatically uses GLOBAL when table has onCluster option.
|
|
40
|
+
* - 'standard': Regular LEFT JOIN.
|
|
41
|
+
* - 'global': Force GLOBAL JOIN (for sharded clusters).
|
|
42
|
+
* - 'any': Use ANY JOIN (faster, optimized for 1:1 relations).
|
|
43
|
+
* - 'global_any': Combine GLOBAL and ANY.
|
|
20
44
|
*
|
|
21
45
|
* @default 'auto'
|
|
22
46
|
*/
|
|
23
47
|
joinStrategy?: JoinStrategy;
|
|
24
48
|
};
|
|
25
49
|
/**
|
|
26
|
-
* Build a modern relational API with ClickHouse optimizations.
|
|
50
|
+
* Build a modern relational API with ClickHouse-specific optimizations.
|
|
51
|
+
*
|
|
52
|
+
* Key architectural features:
|
|
53
|
+
* - **groupUniqArray Optimization**: Instead of flat-joining which causes row explosion,
|
|
54
|
+
* HouseKit uses ClickHouse aggregation to fetch nested relations as arrays of tuples.
|
|
55
|
+
* - **Automatic Cluster Handling**: Detects sharded tables and applies GLOBAL JOINs.
|
|
56
|
+
* - **Smart Deduplication**: Merges results in-memory when flat joins are unavoidable.
|
|
27
57
|
*
|
|
28
|
-
*
|
|
29
|
-
* -
|
|
30
|
-
* - Join strategy selection for performance tuning
|
|
31
|
-
* - Support for dictionary lookups as alternative to JOINs
|
|
58
|
+
* @param client - The ClickHouse client instance.
|
|
59
|
+
* @param schema - The shared schema definition containing all table and relation metadata.
|
|
32
60
|
*/
|
|
33
61
|
export declare function buildRelationalAPI(client: any, schema?: Record<string, TableDefinition<any>>): Record<string, any> | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@housekit/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Type-safe ClickHouse ORM with modern DX and ClickHouse-specific optimizations. Features Turbo Mode (RowBinary), full engine support, and advanced query capabilities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|