@housekit/orm 0.1.14 → 0.1.16
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 +40 -0
- package/dist/builders/select.d.ts +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/table.d.ts +3 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -162,6 +162,46 @@ await builder.append(row2);
|
|
|
162
162
|
|
|
163
163
|
---
|
|
164
164
|
|
|
165
|
+
## 🛠️ Type-Safe Inserts
|
|
166
|
+
|
|
167
|
+
### Simple Repository Pattern
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
async insertEvents(events: auditEvents[]) {
|
|
171
|
+
return await db.insert(auditEvents).values(events);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Usage
|
|
175
|
+
await repository.insertEvents([
|
|
176
|
+
{ venueId: 'venue-1', ingredientId: 'ing-1', type: 'restock', quantity: 100, at: new Date() },
|
|
177
|
+
{ venueId: 'venue-2', ingredientId: 'ing-2', type: 'sale', quantity: -50, at: new Date(), referenceId: null }
|
|
178
|
+
]);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### How It Works
|
|
182
|
+
|
|
183
|
+
When you write `table.$inferInsert`, it includes a callable signature. TypeScript interprets `table[]` as invoking that callable and applying the array type, giving you `TableInsert<T>[]` automatically.
|
|
184
|
+
|
|
185
|
+
### Alternative Approaches
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { TableInsertArray } from '@housekit/orm';
|
|
189
|
+
|
|
190
|
+
// Using explicit type helper
|
|
191
|
+
async insertEvents(events: TableInsertArray<typeof salesEvents>) {
|
|
192
|
+
return await db.insert(salesEvents).values(events);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Using $inferInsert directly
|
|
196
|
+
async insertEvents(events: typeof salesEvents.$inferInsert[]) {
|
|
197
|
+
return await db.insert(salesEvents).values(events);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**Recommended**: Use `table[]` for the cleanest, most ergonomic DX.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
165
205
|
## 🤝 Smart Relational API
|
|
166
206
|
|
|
167
207
|
Traditional ORMs produce "Flat Joins" that duplicate data (the Cartesian Product problem). HouseKit's Relational API uses ClickHouse's `groupArray` internally to fetch related data as nested arrays in a single, efficient query.
|
|
@@ -217,7 +217,9 @@ export declare class ClickHouseQueryBuilder<TTable extends TableDefinition<any>
|
|
|
217
217
|
$inferSelect?: import("../table").InferSelectModel<{
|
|
218
218
|
$columns: TSelection extends SelectionShape ? { [K in keyof (TSelection extends infer T_1 ? T_1 extends TSelection ? T_1 extends SelectionShape ? SelectResult<T_1> : Record<string, any> : never : never)]: ClickHouseColumn<(TSelection extends infer T_2 ? T_2 extends TSelection ? T_2 extends SelectionShape ? SelectResult<T_2> : Record<string, any> : never : never)[K], true, false>; } : Record<string, ClickHouseColumn<any, true, false>>;
|
|
219
219
|
}> | undefined;
|
|
220
|
-
$inferInsert?: import("../table").
|
|
220
|
+
$inferInsert?: import("../table").InferInsertModel<{
|
|
221
|
+
$columns: TSelection extends SelectionShape ? { [K in keyof (TSelection extends infer T_2 ? T_2 extends TSelection ? T_2 extends SelectionShape ? SelectResult<T_2> : Record<string, any> : never : never)]: ClickHouseColumn<(TSelection extends infer T_3 ? T_3 extends TSelection ? T_3 extends SelectionShape ? SelectResult<T_3> : Record<string, any> : never : never)[K], true, false>; } : Record<string, ClickHouseColumn<any, true, false>>;
|
|
222
|
+
}> | undefined;
|
|
221
223
|
} & (TSelection extends SelectionShape ? { [K in keyof (TSelection extends infer T_3 ? T_3 extends TSelection ? T_3 extends SelectionShape ? SelectResult<T_3> : Record<string, any> : never : never)]: ClickHouseColumn<(TSelection extends infer T_4 ? T_4 extends TSelection ? T_4 extends SelectionShape ? SelectResult<T_4> : Record<string, any> : never : never)[K], true, false>; } : Record<string, ClickHouseColumn<any, true, false>>);
|
|
222
224
|
register: (mainQuery: ClickHouseQueryBuilder<any, any, any>) => ClickHouseQueryBuilder<any, any, any>;
|
|
223
225
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TableDefinition, type TableColumns } from './core';
|
|
2
2
|
import { createClientFromConfigObject, type ClientConfigWithSchema } from './client';
|
|
3
3
|
export { ClickHouseColumn } from './column';
|
|
4
|
-
export { type TableDefinition, type TableColumns, type TableOptions, type IndexDefinition, type ProjectionDefinition, index, projection, deriveTable, renderSchema } from './table';
|
|
4
|
+
export { type TableDefinition, type TableColumns, type TableOptions, type IndexDefinition, type ProjectionDefinition, type TableInsert, index, projection, deriveTable, renderSchema } from './table';
|
|
5
5
|
export { Engine, type EngineConfiguration } from './engines';
|
|
6
6
|
export * from './external';
|
|
7
7
|
export * from './expressions';
|
package/dist/table.d.ts
CHANGED
|
@@ -81,7 +81,9 @@ export type InferSelectModel<T extends {
|
|
|
81
81
|
};
|
|
82
82
|
export type InferInsertModel<T extends {
|
|
83
83
|
$columns: TableColumns;
|
|
84
|
-
}> = TableInsert<T['$columns']
|
|
84
|
+
}> = TableInsert<T['$columns']> & {
|
|
85
|
+
(): TableInsert<T['$columns']>;
|
|
86
|
+
};
|
|
85
87
|
export type TableDefinition<TCols extends TableColumns, TOptions = TableOptions> = {
|
|
86
88
|
$table: string;
|
|
87
89
|
$columns: TCols;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@housekit/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
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",
|
|
@@ -65,4 +65,4 @@
|
|
|
65
65
|
"engines": {
|
|
66
66
|
"node": ">=18.0.0"
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|