@housekit/orm 0.1.13 → 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/index.d.ts +1 -1
- package/dist/table.d.ts +5 -5
- package/package.json +1 -1
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.
|
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
|
@@ -71,10 +71,8 @@ export type TableRow<TCols extends TableColumns> = {
|
|
|
71
71
|
[K in keyof TCols]: TCols[K] extends ClickHouseColumn<infer T, infer NotNull, any> ? NotNull extends true ? T : T | null : never;
|
|
72
72
|
};
|
|
73
73
|
export type TableInsert<TCols extends TableColumns> = {
|
|
74
|
-
[K in keyof TCols as TCols[K] extends ClickHouseColumn<any, infer NotNull, infer Auto> ? NotNull extends true ? Auto extends true ? never : K :
|
|
75
|
-
}
|
|
76
|
-
[K in keyof TCols as TCols[K] extends ClickHouseColumn<any, infer NotNull, infer Auto> ? NotNull extends true ? Auto extends true ? K : never : K : never]: TCols[K] extends ClickHouseColumn<infer T, any, any> ? T : never;
|
|
77
|
-
}>;
|
|
74
|
+
[K in keyof TCols as TCols[K] extends ClickHouseColumn<any, infer NotNull, infer Auto> ? NotNull extends true ? Auto extends true ? never : K : K : never]: TCols[K] extends ClickHouseColumn<infer T, any, any> ? T : never;
|
|
75
|
+
};
|
|
78
76
|
type GetColumnType<T extends ClickHouseColumn> = T extends ClickHouseColumn<infer Type, infer IsNotNull, any> ? IsNotNull extends true ? Type : Type | null : never;
|
|
79
77
|
export type InferSelectModel<T extends {
|
|
80
78
|
$columns: TableColumns;
|
|
@@ -83,7 +81,9 @@ export type InferSelectModel<T extends {
|
|
|
83
81
|
};
|
|
84
82
|
export type InferInsertModel<T extends {
|
|
85
83
|
$columns: TableColumns;
|
|
86
|
-
}> = TableInsert<T['$columns']
|
|
84
|
+
}> = TableInsert<T['$columns']> & {
|
|
85
|
+
(): TableInsert<T['$columns']>;
|
|
86
|
+
};
|
|
87
87
|
export type TableDefinition<TCols extends TableColumns, TOptions = TableOptions> = {
|
|
88
88
|
$table: string;
|
|
89
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",
|