@housekit/orm 0.1.29 → 0.1.30
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 +17 -76
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -164,30 +164,24 @@ orderBy: [desc(users.createdAt), asc(users.name)]
|
|
|
164
164
|
|
|
165
165
|
## 🚀 High-Performance Inserts
|
|
166
166
|
|
|
167
|
-
### Default Insert
|
|
167
|
+
### Default Insert (Sync Mode)
|
|
168
|
+
|
|
169
|
+
HouseKit uses synchronous inserts by default for maximum speed:
|
|
168
170
|
|
|
169
171
|
```typescript
|
|
170
|
-
// Standard insert
|
|
172
|
+
// Standard insert - uses sync mode automatically
|
|
171
173
|
await db.insert(events).values([
|
|
172
174
|
{ type: 'click', userId: '...' },
|
|
173
175
|
{ type: 'view', userId: '...' },
|
|
174
176
|
]);
|
|
175
177
|
```
|
|
176
178
|
|
|
177
|
-
###
|
|
178
|
-
|
|
179
|
-
Use `.syncInsert()` for maximum speed with batches under 5k rows:
|
|
180
|
-
|
|
181
|
-
```typescript
|
|
182
|
-
await db.insert(events).values(data).syncInsert();
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### JSONCompact Format
|
|
179
|
+
### Async Insert (Server-Side Batching)
|
|
186
180
|
|
|
187
|
-
Use `.
|
|
181
|
+
Use `.asyncInsert()` when you want ClickHouse to batch writes internally:
|
|
188
182
|
|
|
189
183
|
```typescript
|
|
190
|
-
await db.insert(events).values(data).
|
|
184
|
+
await db.insert(events).values(data).asyncInsert();
|
|
191
185
|
```
|
|
192
186
|
|
|
193
187
|
### JSON Insert with Returning
|
|
@@ -210,12 +204,6 @@ const [user1, user2] = await db
|
|
|
210
204
|
.returning();
|
|
211
205
|
```
|
|
212
206
|
|
|
213
|
-
### Force JSON Format
|
|
214
|
-
|
|
215
|
-
```typescript
|
|
216
|
-
await db.insert(events).values(data).useJsonFormat();
|
|
217
|
-
```
|
|
218
|
-
|
|
219
207
|
### Background Batching
|
|
220
208
|
|
|
221
209
|
Collect small writes into efficient batches:
|
|
@@ -320,18 +308,18 @@ Performance tested on local ClickHouse (Docker) with Bun runtime:
|
|
|
320
308
|
|
|
321
309
|
| Rows | Method | Time | Throughput |
|
|
322
310
|
|------|--------|------|------------|
|
|
323
|
-
| 1,000 | JSON |
|
|
324
|
-
| 1,000 |
|
|
325
|
-
|
|
|
326
|
-
| 5,000 | JSON |
|
|
327
|
-
|
|
|
328
|
-
| 10,000 | JSON |
|
|
329
|
-
| 10,000 | JSONCompact | 158ms | 63,291 rows/sec |
|
|
311
|
+
| 1,000 | JSON | 19ms | 52,632 rows/sec |
|
|
312
|
+
| 1,000 | JSON Sync | 13ms | 76,923 rows/sec |
|
|
313
|
+
| 5,000 | JSON | 118ms | 42,373 rows/sec |
|
|
314
|
+
| 5,000 | JSON Sync | 54ms | 92,593 rows/sec |
|
|
315
|
+
| 10,000 | JSON | 159ms | 62,893 rows/sec |
|
|
316
|
+
| 10,000 | JSON Sync | 161ms | 62,112 rows/sec |
|
|
330
317
|
|
|
331
318
|
Key findings:
|
|
332
|
-
- **Sync insert
|
|
333
|
-
-
|
|
334
|
-
- For
|
|
319
|
+
- **Sync insert is the default** - fastest for most use cases
|
|
320
|
+
- For batches <5k rows, sync is up to **2x faster**
|
|
321
|
+
- For larger batches (10k+), performance is similar
|
|
322
|
+
- Use `.asyncInsert()` only when you need server-side batching
|
|
335
323
|
|
|
336
324
|
Run the benchmark yourself:
|
|
337
325
|
```bash
|
|
@@ -374,53 +362,6 @@ const db = housekit({
|
|
|
374
362
|
await db.insert(events).values(data).skipValidation();
|
|
375
363
|
```
|
|
376
364
|
|
|
377
|
-
### Object Pooling
|
|
378
|
-
|
|
379
|
-
HouseKit automatically pools `BinaryWriter` instances to reduce GC pressure. For advanced use cases:
|
|
380
|
-
|
|
381
|
-
```typescript
|
|
382
|
-
import { acquireWriter, releaseWriter } from '@housekit/orm';
|
|
383
|
-
|
|
384
|
-
const writer = acquireWriter();
|
|
385
|
-
try {
|
|
386
|
-
// Use writer for custom serialization
|
|
387
|
-
} finally {
|
|
388
|
-
releaseWriter(writer);
|
|
389
|
-
}
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
### Optimized Serialization
|
|
393
|
-
|
|
394
|
-
For maximum performance with large batches:
|
|
395
|
-
|
|
396
|
-
```typescript
|
|
397
|
-
import {
|
|
398
|
-
buildOptimizedBinaryConfig,
|
|
399
|
-
serializeRowsOptimized
|
|
400
|
-
} from '@housekit/orm';
|
|
401
|
-
|
|
402
|
-
// Pre-compile accessors once
|
|
403
|
-
const config = buildOptimizedBinaryConfig(columns, {
|
|
404
|
-
skipValidation: true
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
// Serialize batches with pooled writer + pre-compiled accessors
|
|
408
|
-
const buffer = serializeRowsOptimized(rows, config);
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
### TypedArray for Numeric Data
|
|
412
|
-
|
|
413
|
-
For schemas with mostly numeric columns:
|
|
414
|
-
|
|
415
|
-
```typescript
|
|
416
|
-
import { isNumericHeavySchema, serializeNumericBatch } from '@housekit/orm';
|
|
417
|
-
|
|
418
|
-
if (isNumericHeavySchema(columns)) {
|
|
419
|
-
// Uses Float64Array for better memory layout
|
|
420
|
-
const { numericBuffer, otherData } = serializeNumericBatch(rows, config, numericIndices);
|
|
421
|
-
}
|
|
422
|
-
```
|
|
423
|
-
|
|
424
365
|
---
|
|
425
366
|
|
|
426
367
|
## 🛠 Observability
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@housekit/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
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",
|