@housekit/orm 0.1.2 → 0.1.4

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 CHANGED
@@ -152,9 +152,10 @@ const builder = db.insert(webEvents)
152
152
  flushIntervalMs: 5000
153
153
  });
154
154
 
155
- // These calls return immediately, flushing happens in the background
156
- builder.values(row1).execute();
157
- builder.values(row2).execute();
155
+ // Add rows to the background queue.
156
+ // Proccessing and flushing happen automatically.
157
+ await builder.append(row1);
158
+ await builder.append(row2);
158
159
  ```
159
160
 
160
161
  ---
@@ -64,6 +64,16 @@ export declare class ClickHouseInsertBuilder<TTable extends TableDefinition<Tabl
64
64
  * Default: 1000
65
65
  */
66
66
  batchSize(size: number): this;
67
+ /**
68
+ * Add a row to the background batcher.
69
+ *
70
+ * If batching is not yet configured, it will use default settings
71
+ * (10,000 rows or 5 seconds).
72
+ *
73
+ * Note: This method is "fire-and-forget" and does not wait for
74
+ * the database to acknowledge the insert.
75
+ */
76
+ append(row: TableInsert<TTable['$columns']>): Promise<void>;
67
77
  /**
68
78
  * Force JSON format (useful for debugging or compatibility).
69
79
  *
@@ -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, single match)
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
- * Key improvements over standard ORMs:
29
- * - Automatic GLOBAL JOIN detection for distributed tables
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.2",
3
+ "version": "0.1.4",
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",