bun-sqlite-for-rxdb 1.3.1 → 1.5.0

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/CHANGELOG.md DELETED
@@ -1,722 +0,0 @@
1
- # Changelog
2
-
3
- ## [1.3.0] - 2026-02-26
4
-
5
- ### Added
6
- - **Bun-optimized stable-stringify for deterministic JSON**
7
- - Custom implementation optimized for Bun's JavaScriptCore engine
8
- - 25x faster than baseline (536K ops/sec average)
9
- - 49x faster for Mango queries (1.04M ops/sec)
10
- - Eliminates cache key collisions between undefined and null
11
- - Safe toJSON error handling (returns "[Error: message]" instead of crashing)
12
-
13
- ### Performance 🔥
14
- - **stable-stringify optimizations: 10-65% faster**
15
- - Small objects: +65% faster (691K → 1.1M ops/sec)
16
- - Overall average: +10% faster (646K → 714K ops/sec)
17
- - Optimized for common case (simple Mango queries with 5-20 keys)
18
- - **SQL query optimizations**
19
- - Push ORDER BY/LIMIT/OFFSET to SQL layer (eliminates in-memory sorting overhead)
20
- - Batch INSERT operations for better throughput
21
- - **Regex cache: O(1) FIFO eviction**
22
- - Eliminates cache management overhead
23
- - Constant-time eviction vs linear scan
24
-
25
- ### Fixed 🔥
26
- - **Query cache collision between undefined and null**
27
- - Fixed cache key collision where `{ age: undefined }` and `{ age: null }` produced identical keys
28
- - stable-stringify now omits undefined values (matches JSON.stringify behavior)
29
- - Prevents cache pollution and wrong SQL being returned
30
- - 30x faster performance (645K ops/sec)
31
- - **toJSON error handling in stableStringify**
32
- - Add callSafe helper to catch toJSON errors instead of crashing
33
- - Returns "[Error: <message>]" format for failed toJSON calls
34
- - Prevents application crashes from buggy toJSON implementations
35
- - **$elemMatch operator fixes**
36
- - Handle non-operator fields and nested operators correctly
37
- - Added 6 missing operators: $exists, $size, $mod, $not, $and, $or
38
- - Fixed 3 edge cases: multi-field objects, nested object values, dot notation paths
39
- - **SQL operator precedence**
40
- - Add proper parentheses for $or operator precedence (AND > OR in SQL)
41
- - Fixed 3 test expectations that were checking for incorrect SQL
42
- - **Input validation to prevent data corruption crashes**
43
- - Validate at function boundaries (buildWhereClause, processSelector, operators)
44
- - Prevents crashes on null/undefined/wrong types
45
- - Fixed 17 data corruption test failures
46
- - **Null checks in not-operators tests**
47
- - Add proper null validation to prevent edge case failures
48
-
49
- ### Changed
50
- - **Removed Mingo dependency**
51
- - Simplified query routing by using ourMemory regex matcher for all fallback cases
52
- - Eliminates 519 lines from lockfile
53
- - Reduces bundle size and dependency complexity
54
- - All regex queries now use custom LRU-cached matcher
55
- - **buildWhereClause now returns nullable**
56
- - Returns null for untranslatable queries (cleaner API)
57
- - Enables proper fallback to in-memory filtering
58
- - Updated all unit tests for new signature
59
-
60
- ### Technical Details
61
- - All 346 tests passing (17 data corruption tests fixed)
62
- - No regressions in query or write performance
63
- - stable-stringify uses manual loops (no .map() overhead)
64
- - Custom insertion sort for arrays <100 elements (threshold optimized)
65
- - Proper type safety: no `any` types in stable-stringify implementation
66
- - Query cache now properly handles undefined vs null distinction
67
-
68
- ---
69
-
70
- ## [1.2.8] - 2026-02-25
71
-
72
- ### Performance 🔥
73
- - **PRAGMA optimizations for read-heavy workloads**
74
- - Added `PRAGMA mmap_size = 268435456` (256MB, configurable via `mmapSize` setting)
75
- - Added `PRAGMA temp_store = MEMORY` (10-20% faster complex queries)
76
- - Added `PRAGMA locking_mode = NORMAL` (multi-instance compatibility)
77
- - 256MB mmap_size is industry standard (GrapheneOS, Android apps, desktop tools)
78
- - Eliminates double-copy for reads, shares OS page cache directly
79
-
80
- ### Added
81
- - **Configurable mmap_size setting**
82
- - New `mmapSize` option in `BunSQLiteStorageSettings`
83
- - Default: 268435456 bytes (256MB) - industry standard
84
- - Set to 0 to disable (recommended for iOS)
85
- - Automatically skipped for in-memory databases
86
- - **4 comprehensive behavior tests**
87
- - Transaction queue prevents race conditions
88
- - mmap_size improves read performance at scale
89
- - temp_store MEMORY improves complex query performance
90
- - mmapSize can be disabled without breaking functionality
91
-
92
- ### Technical Details
93
- - mmap_size default validated against production libraries:
94
- - GrapheneOS AttestationServer: 256MB
95
- - WechatExporter: 256MB
96
- - Android ArchiveTune: 256MB
97
- - better-sqlite3 tests: Fresh DB per test pattern
98
- - temp_store = MEMORY: Keeps temporary tables/indexes in RAM
99
- - locking_mode = NORMAL: Allows multiple connections (vs EXCLUSIVE)
100
- - All 215 tests passing (211 + 4 behavior tests)
101
- - No regressions in query or write performance
102
-
103
- ---
104
-
105
- ## [1.2.7] - 2026-02-25
106
-
107
- ### Fixed 🔥
108
- - **Transaction queue for bulkWrite: Prevents race conditions**
109
- - Added `sqliteTransaction()` helper to serialize concurrent writes
110
- - Wraps bulkWrite in transaction queue (BEGIN IMMEDIATE → COMMIT/ROLLBACK)
111
- - Prevents data corruption from parallel bulkWrite calls
112
- - SQLite doesn't support concurrent writes - queue ensures serialization
113
-
114
- ### Added
115
- - **7 comprehensive transaction queue tests**
116
- - Tests for successful transactions, rollback on error
117
- - Concurrent write serialization verification
118
- - Race condition prevention tests
119
- - Error preservation and handler result tests
120
-
121
- ### Technical Details
122
- - Transaction queue uses WeakMap to track per-database queues
123
- - BEGIN IMMEDIATE ensures exclusive write lock
124
- - Automatic ROLLBACK on errors
125
- - All 211 tests passing (7 new transaction queue tests)
126
- - No performance regression (transactions were already implicit)
127
-
128
- ---
129
-
130
- ## [1.2.6] - 2026-02-25
131
-
132
- ### Performance 🔥
133
- - **Statement caching in all() and get(): 35% variance reduction**
134
- - Added LRU statement caching to all() and get() methods
135
- - Previously only run() had caching, causing 22% query variance
136
- - queryEq: 5.43ms → 3.52ms StdDev (35% reduction)
137
- - queryRepeated: 4.25ms → 3.87ms StdDev (9% reduction)
138
- - 6.8x faster for cached queries (performance test)
139
-
140
- ### Added
141
- - **Linus-style close() safety**
142
- - close() now throws on use-after-close (prevents resource leaks)
143
- - Matches industry standard (file handles, DB connections, streams)
144
- - Prevents silent failures and memory leaks
145
- - **20 comprehensive StatementManager tests**
146
- - Cache hits/misses, LRU eviction, boundary conditions
147
- - Multiple managers isolation, statement finalization
148
- - Stress tests: 10k queries in 81ms (8.17µs per query)
149
-
150
- ### Technical Details
151
- - Statement cache uses same LRU pattern as run() method
152
- - MAX_STATEMENTS = 500 with proper finalization on eviction
153
- - close() sets flag and throws Error on subsequent use
154
- - All 204 tests passing (20 new StatementManager tests)
155
- - No regressions in query or write performance
156
-
157
- ---
158
-
159
- ## [1.2.5] - 2026-02-25
160
-
161
- ### Performance 🔥
162
- - **Bounded statement cache: Prevents memory leaks**
163
- - Added MAX_STATEMENTS = 500 with LRU eviction
164
- - Calls finalize() on evicted statements to free resources
165
- - No performance regression - cache hit path unchanged
166
- - **bulkWrite(100) optimization: 2.1x faster**
167
- - 3.83ms → 1.82ms (Phase 1 PRAGMA optimizations showing impact at scale)
168
-
169
- ### Changed
170
- - **Document cache removed** (Phase 2 Iteration 5)
171
- - Industry research: PouchDB, Dexie, LokiJS, WatermelonDB don't use document-level caching
172
- - SQLite page cache (PRAGMA cache_size = -32000) is sufficient
173
- - Simpler architecture, no cache invalidation complexity
174
-
175
- ### Fixed
176
- - **Timing test reliability on Windows**
177
- - Switched from performance.now() to process.hrtime.bigint() for nanosecond precision
178
- - Fixes flaky tests caused by ~1ms resolution on Windows
179
- - Applied to "Production Scenario 3" and "Edge Case 13" tests
180
-
181
- ### Added
182
- - bulkWrite(100) benchmark test to measure Phase 2 impact at scale
183
-
184
- ### Technical Details
185
- - Statement cache bounded at 500 entries (prevents unbounded growth)
186
- - LRU eviction: moves accessed statements to end, evicts oldest
187
- - All 184 tests passing with reliable timing
188
- - No regressions in query or write performance
189
-
190
- ---
191
-
192
- ## [1.2.4] - 2026-02-25
193
-
194
- ### Performance 🔥
195
- - **count() optimization: 4.5x faster at scale**
196
- - Fixed to use `SELECT COUNT(*)` instead of fetching all documents
197
- - 10k docs: 21.74ms → 5.03ms (4.32x faster)
198
- - 100k docs: 219.44ms → 48.41ms (4.53x faster)
199
- - **PRAGMA optimizations: 2x faster writes**
200
- - Added `PRAGMA wal_autocheckpoint = 1000` (+12% write performance)
201
- - Added `PRAGMA cache_size = -32000` (32MB cache for better query performance)
202
- - Added `PRAGMA analysis_limit = 400` (faster query planning)
203
- - bulkWrite: 0.36ms → 0.18ms (2x faster for single doc)
204
- - **Query cache increase: 500 → 1000**
205
- - Prevents cache thrashing in multi-collection apps
206
- - Supports 5-10 collections × 10-20 queries each
207
-
208
- ### Added
209
- - Comprehensive Phase 1 benchmark suite (200 runs @ 10k docs, 100 runs @ 100k docs)
210
- - Optimization journey documentation with baseline results and Phase 2-4 roadmap
211
-
212
- ### Technical Details
213
- - count() changed from O(n) to O(1) complexity
214
- - All optimizations verified with 260/260 tests passing
215
- - No regressions in query performance (1.01-1.03x, within margin of error)
216
- - Low standard deviation confirms stable, reliable results
217
-
218
- ---
219
-
220
- ## [1.2.3] - 2026-02-25
221
-
222
- ### Changed
223
- - **Code Organization**
224
- - Reorganized tests into unit/integration/benchmarks structure
225
- - Added TypeScript path aliases ($app/* → src/*) for cleaner imports
226
- - Updated all test imports to use path aliases
227
- - Eliminated all `any` types from core modules (src/)
228
- - Removed obsolete test files and old benchmark directory
229
-
230
- ### Technical Details
231
- - Zero `any` types in src/ (instance.ts, rxdb-helpers.ts, statement-manager.ts, builder.ts)
232
- - Proper TypeScript types: `SQLQueryBindings[]`, `RxAttachmentData`, generic `all<T>()`
233
- - Test structure: test/unit/, test/unit/operators/, test/integration/, test/benchmarks/
234
- - Path aliases configured in tsconfig.json
235
-
236
- ### Test Results
237
- - 181/184 tests passing (3 pre-existing regex bugs)
238
- - All type safety improvements verified
239
-
240
- ---
241
-
242
- ## [1.2.2] - 2026-02-24
243
-
244
- ### Fixed
245
- - **$type Operator** (SQL Translation)
246
- - Fixed translateType() signature: now requires jsonColumn, fieldName, and type parameters
247
- - Rewritten to use SQLite's json_type() for all 6 RxDB types (was using typeof() for only 3)
248
- - All types now translate to SQL: null, boolean, number, string, array, object
249
- - Removed redundant canTranslateToSQL check (all types now supported)
250
- - Fixed TypeScript error: "Expected 3 arguments, but got 2"
251
-
252
- ### Changed
253
- - **Architecture Simplification**
254
- - Removed redundant ternary in translateType() (both branches identical)
255
- - Cleaner jsonPath construction: `$.${fieldName}`
256
-
257
- ### Test Results
258
- - 181/184 tests passing (3 pre-existing regex bugs unrelated to $type)
259
- - All 6 $type operator tests passing
260
-
261
- ---
262
-
263
- ## [1.2.1] - 2026-02-24
264
-
265
- ### Added
266
- - **$elemMatch with $and/$or/$nor** (SQL Fast Path)
267
- - Implemented nested logical operators inside $elemMatch queries
268
- - Uses single EXISTS pattern with combined WHERE clause (SQLite best practice)
269
- - Eliminates Mingo fallback for complex array matching
270
- - 8 integration tests for $elemMatch with logical operators
271
-
272
- ### Changed
273
- - **Architecture Simplification**
274
- - Removed redundant $and/$or/$nor validation from canTranslateToSQL()
275
- - Simplified routing logic (processSelector handles all cases)
276
-
277
- ### Performance
278
- - $elemMatch with $and: ~24.44ms (SQL fast path)
279
- - $elemMatch with $or: ~25.23ms (SQL fast path)
280
- - $elemMatch with $nor: ~25.33ms (SQL fast path)
281
-
282
- ### Test Results
283
- - 8/8 new integration tests passing
284
- - 180/183 total tests passing (3 pre-existing regex bugs)
285
-
286
- ---
287
-
288
- ## [1.2.0] - 2026-02-24
289
-
290
- ### Added
291
- - **$elemMatch Operator** (SQL Translation)
292
- - Implemented with EXISTS + json_each() pattern
293
- - Supports simple field matching inside arrays
294
- - Foundation for nested logical operators
295
- - **$type Array Operator**
296
- - Added json_type check for 'array' type detection
297
- - Completes $type operator support
298
- - **ourMemory Regex Matcher**
299
- - Custom LRU-cached regex matcher (100 entries, 53 lines)
300
- - Replaces Mingo for simple case-insensitive $regex queries
301
- - Expression index support: LOWER(field) parsing
302
- - 6.1% performance improvement (37.41ms → 35.11ms)
303
- - **Mingo Routing Architecture**
304
- - Added canTranslateToSQL() for intelligent query routing
305
- - SQL fast path for translatable queries
306
- - Mingo fallback for complex patterns
307
- - Schema-aware query builder
308
-
309
- ### Changed
310
- - **Query Builder Schema-Aware**
311
- - translateRegex() now accepts schema and fieldName parameters
312
- - Enables expression index detection
313
- - Better optimization decisions
314
-
315
- ### Fixed
316
- - Disabled case-insensitive regex translation to SQL (correctness over performance)
317
-
318
- ### Performance
319
- - ourMemory regex matcher: 6.1% faster than Mingo (37.41ms → 35.11ms)
320
- - $elemMatch: SQL fast path for simple queries
321
-
322
- ### Test Results
323
- - Comprehensive array edge case tests added
324
- - All $type array tests passing
325
-
326
- ---
327
-
328
- ## [1.1.4] - 2026-02-24
329
-
330
- ### Fixed
331
- - **$nor Operator Bug** (Critical)
332
- - Fixed $nor generating raw field names instead of json_extract() paths
333
- - Was causing "no such column" SQLite errors
334
- - Now schema-aware and handles JSONB storage correctly
335
- - **Query Cache Collision** (Critical)
336
- - Fixed cache collisions between different collections
337
- - Cache key now includes collectionName: `v${version}_${collectionName}_${selector}`
338
- - Prevents wrong SQL being used across collections with same schema
339
-
340
- ### Changed
341
- - **DRY Refactor: Unified $or/$nor Handling**
342
- - Created `buildLogicalOperator()` helper for both operators
343
- - Eliminated code duplication (15 lines of inline $or code)
344
- - Both operators now use same schema-aware logic
345
- - **buildWhereClause Signature**
346
- - Added `collectionName` as 3rd parameter
347
- - Ensures cache isolation between collections
348
- - All unit tests updated for new signature
349
-
350
- ### Added
351
- - **DEBUG_QUERIES Logging**
352
- - Added fallback error logging via `DEBUG_QUERIES=1` env var
353
- - Helps debug which queries trigger fallback path
354
- - **Comprehensive Integration Tests**
355
- - 27 new integration tests for all SQL operators
356
- - Covers: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $regex (simple), $and, $or, $not, $nor, $type (simple), $size, $mod
357
- - Tests include edge cases and complex nested queries
358
- - **TDD Tests for Complex Operators**
359
- - 6 failing tests documenting fallback bug
360
- - Tests for: complex $regex (character classes, flags), $elemMatch, $type (array/object)
361
- - Will pass once Mingo fallback is implemented
362
-
363
- ### Test Results
364
- - **Local tests: 162/162 pass (100%)** ✅
365
- - **Failing tests: 6/6 (expected - TDD tests for Mingo fallback)** ⏳
366
- - All SQL operators working correctly
367
- - $nor bug fixed and tested
368
-
369
- ### Technical Details
370
- - Removed broken `translateNor()` function
371
- - Kept `processOperatorValue()` (used by `translateNot()`)
372
- - Cache key now: `v${schema.version}_${collectionName}_${stringify(selector)}`
373
- - RxDB integration verified: `this.collectionName` available and passed correctly
374
-
375
- ---
376
-
377
- ## [1.1.0] - 2026-02-23
378
-
379
- ### Added
380
- - **schema.indexes Support** (v1.1.0)
381
- - Dynamic index creation from schema.indexes definitions
382
- - Supports single-field indexes: `['age']`
383
- - Supports compound indexes: `['age', 'status']`
384
- - Uses `json_extract()` for JSONB fields
385
- - Proper index naming: `idx_users_v0_age_status`
386
- - 9 lines of implementation code
387
- - Research validated: 4/5 RxDB storage plugins implement this
388
-
389
- ### Changed
390
- - **ORDER BY Optimization** (v1.1.0)
391
- - Removed redundant SQL `ORDER BY id` (we sort in-memory anyway)
392
- - Eliminates temp B-tree overhead in SQLite
393
- - Research finding: We already sort at line 226, SQL ORDER BY was redundant
394
-
395
- ### Performance
396
- - **29.8% faster queries** (165.43ms → 116.09ms avg on 100k docs)
397
- - Test 1 (age > 50): 20.6% faster
398
- - Test 2 (status = "active"): 22.1% faster
399
- - Test 3 (age > 30 AND status): 26.8% faster
400
- - Test 4 (age BETWEEN 25-35): 51.5% faster!
401
-
402
- ### Test Results
403
- - **Local tests: 138/138 pass (100%)** ✅
404
- - **Official RxDB tests: 122/122 pass (100%)** ✅
405
- - **Total: 260/260 tests pass (100%)** 🎉
406
-
407
- ### Research
408
- - **3 research agents deployed** (2 codebase + 1 web)
409
- - Verified implementation correctness vs other RxDB storages
410
- - Analyzed ORDER BY patterns in storage plugins
411
- - Researched SQLite covering indexes and optimization
412
- - **Key findings:**
413
- - Our implementation matches standard RxDB patterns
414
- - Better than official SQLite Trial (which has no indexes)
415
- - ORDER BY id was causing temp B-tree overhead
416
- - Removing it eliminated redundant sorting
417
-
418
- ### Documentation
419
- - Added Pattern #28: schema.indexes Support
420
- - Added Pattern #29: ORDER BY Optimization
421
- - Updated ROADMAP.md with implementation results
422
-
423
- ---
424
-
425
- ## [1.0.1] - 2026-02-23
426
-
427
- ### Added
428
- - **EXPLAIN QUERY PLAN Debug Mode** (Development Tool)
429
- - Activated via `DEBUG_QUERIES=1` environment variable
430
- - Logs query plans, SQL, and args to console
431
- - Helps verify query builder generates optimal SQL
432
- - Validates SQLite index usage
433
- - Zero production overhead (env var check only)
434
-
435
- ### Usage
436
- ```bash
437
- DEBUG_QUERIES=1 bun test
438
- ```
439
-
440
- ---
441
-
442
- ## [1.0.0] - 2026-02-23
443
-
444
- ### Added
445
- - **Attachments Support** (Phase 4)
446
- - Storage-level implementation with 4 comprehensive tests
447
- - `getAttachmentData()` returns base64 strings with digest validation
448
- - Preserves `_attachments` metadata in documents
449
- - Attachments table with composite keys (documentId||attachmentId)
450
- - 122/122 official RxDB tests passing (includes 5 attachment tests)
451
- - **RxDB Helper Functions** (Phase 4)
452
- - `categorizeBulkWriteRows()` - Battle-tested conflict detection + attachment extraction
453
- - `stripAttachmentsDataFromDocument()` - Remove attachment .data field, keep metadata
454
- - `stripAttachmentsDataFromRow()` - Strip attachments from bulk write rows
455
- - `attachmentWriteDataToNormalData()` - Convert attachment write format to storage format
456
- - `getAttachmentSize()` - Calculate attachment size from base64
457
-
458
- ### Changed
459
- - **bulkWrite Refactored** - Now uses `categorizeBulkWriteRows()` helper
460
- - Cleaner architecture with proper conflict handling
461
- - Automatic attachment extraction
462
- - Matches official adapter patterns (Dexie, MongoDB, SQLite)
463
-
464
- ### Test Results
465
- - **Local tests: 138/138 pass (100%)** ✅
466
- - **Official RxDB tests: 122/122 pass (100%)** ✅
467
- - **Total: 260/260 tests pass (100%)** 🎉
468
-
469
- ### Performance
470
- - Database operations: 1.06-1.68x faster than better-sqlite3
471
- - Query builder cache: 5.2-57.9x speedup for cached queries
472
- - All optimizations from v0.4.0 included
473
-
474
- ### Documentation
475
- - Updated ROADMAP.md - Phase 4 marked COMPLETE
476
- - Removed redundant Phase 4 TDD implementation details
477
- - All helper functions documented with line numbers
478
-
479
- ---
480
-
481
- ## [0.4.0] - 2026-02-23
482
-
483
- ### Added
484
- - **Query Builder LRU Cache** (Phase 2.5)
485
- - 5.2-57.9x speedup for repeated queries
486
- - High-frequency: 505K-808K queries/sec
487
- - Bounded at 500 entries (no memory leak)
488
- - True LRU eviction with canonical key generation (fast-stable-stringify)
489
- - Zero dependencies except fast-stable-stringify (5KB)
490
- - **RxDB Official Test Suite Integration** (Phase 3.1)
491
- - 112/112 official RxDB tests passing (100%)
492
- - StatementManager abstraction for automatic statement lifecycle
493
- - Connection pooling with reference counting for multi-instance support
494
- - Official `addRxStorageMultiInstanceSupport()` integration
495
- - Composite primary key support
496
- - Bun test suite compatibility (Mocha through Bun)
497
- - **Performance Benchmarks** (Phase 3.2)
498
- - Bun:sqlite 1.06-1.68x faster than better-sqlite3
499
- - Benchmarked at 1M documents with WAL + PRAGMA synchronous = 1
500
- - Query builder cache benchmarks
501
- - Raw database comparison benchmarks
502
- - **New Query Operators** (8 operators added)
503
- - `$exists` - Field existence check with IS NULL/IS NOT NULL
504
- - `$regex` - Pattern matching with LIKE translation and Mingo fallback
505
- - `$elemMatch` - Array element matching (Mingo fallback)
506
- - `$not` - Negation operator
507
- - `$nor` - Logical NOR
508
- - `$type` - Type checking with typeof()
509
- - `$size` - Array size with json_array_length()
510
- - `$mod` - Modulo operations
511
-
512
- ### Changed
513
- - **BREAKING**: Statement lifecycle management
514
- - Static SQL uses db.query() (cached, max 20)
515
- - Dynamic SQL uses db.prepare() + finalize() (no cache pollution)
516
- - StatementManager abstraction eliminates manual try-finally boilerplate
517
- - Connection pooling now mandatory for multi-instance support
518
- - Switched from custom multi-instance to RxDB's official implementation
519
-
520
- ### Fixed
521
- - Statement resource leaks (7 locations in instance.ts)
522
- - Collection isolation bug (events leaked across collections)
523
- - Composite primary key handling (string vs object format)
524
- - EventBulk.id generation (empty string → unique timestamp + random)
525
- - Multi-instance event propagation via BroadcastChannel
526
- - Bun test suite compatibility (node:sqlite import, test globals)
527
-
528
- ### Performance
529
- - Query builder cache: 5.2-57.9x speedup for cached queries
530
- - Database operations: 1.06-1.68x faster than better-sqlite3
531
- - No OOM errors (proper statement finalization)
532
- - Tests complete in 12.91s (no hangs)
533
-
534
- ### Test Results
535
- - **Local tests: 134/134 pass (100%)**
536
- - **Official RxDB tests: 112/112 pass (100%)**
537
- - **Total: 246/246 tests pass (100%)** 🎉
538
-
539
- ### Documentation
540
- - Added `docs/id1-testsuite-journey.md` - Complete debugging journey (15 iterations)
541
- - Added `docs/official-test-suite-setup.md` - Guide for running RxDB tests with Bun
542
- - Updated `docs/architectural-patterns.md` - Added patterns 15-24
543
- - Updated `ROADMAP.md` - Phase 2.5 and 3.2 marked COMPLETE, Phase 4 marked READY
544
-
545
- ### Technical Debt Resolved
546
- - Statement lifecycle properly managed (no leaks)
547
- - Connection pooling with reference counting
548
- - Test architecture at correct level (RxDatabase for integration, storage for low-level)
549
- - Proper separation of concerns (we handle DB pooling, RxDB handles event coordination)
550
-
551
- ---
552
-
553
- ## [0.3.1] - 2026-02-22
554
-
555
- ### Added
556
- - **JSONB Storage**: Implemented SQLite's native binary JSON format as default storage
557
- - 1.57x faster complex queries (657ms → 418ms at 1M docs)
558
- - 1.20x faster read + parse operations
559
- - 1.04x faster simple queries
560
- - Uses `jsonb()` on INSERT, `json()` on SELECT
561
- - **Smart Regex Optimization**: Convert simple regex patterns to SQL operators
562
- - 2.03x faster exact matches (^text$ → = operator)
563
- - 1.23x faster case-insensitive (COLLATE NOCASE vs LOWER())
564
- - Overall 1.24x speedup across all patterns
565
- - **Regression Tests**: Added tests for % and _ escaping edge cases
566
-
567
- ### Fixed
568
- - Critical bug: Missing % and _ escaping in case-insensitive exact match regex patterns
569
-
570
- ### Investigated
571
- - **FTS5 Trigram Indexes**: Benchmarked at 100k and 1M scales
572
- - Result: 1.5-1.79x SLOWER at our scale
573
- - Decision: NOT implemented (only beneficial at 10M+ rows)
574
- - Documented findings in architectural-patterns.md
575
-
576
- ### Performance
577
- - Complex queries: 1.57x faster (JSONB)
578
- - Exact match regex: 2.03x faster (smart optimization)
579
- - Read operations: 1.20x faster (JSONB)
580
-
581
- ---
582
-
583
- ## [0.3.0] - 2026-02-22
584
-
585
- ### Added
586
- - **Advanced Query Operators** (4 new operators)
587
- - `$in` - Value in array (80% usage in production)
588
- - `$nin` - Value not in array
589
- - `$or` - Logical OR with proper parentheses handling
590
- - `$and` - Explicit logical AND
591
- - NULL handling for `$in` / `$nin` operators
592
- - Recursive query builder with `logicalDepth` tracking
593
- - 13 new tests for advanced operators
594
-
595
- ### Performance
596
- - Benchmark results (10k documents):
597
- - Average query time: 27.39ms
598
- - Supports complex nested queries: `{$or: [{$and: [...]}, {field: {$in: [...]}}]}`
599
-
600
- ### Technical
601
- - DRY architecture: Pure operator functions, recursive builder
602
- - Type-safe: 0 `any` types, proper TypeScript throughout
603
- - Test coverage: 44/44 tests passing
604
-
605
- ## [0.2.0] - 2026-02-22
606
-
607
- ### Added
608
- - Conflict detection for concurrent writes
609
- - Catches UNIQUE constraint violations
610
- - Returns 409 status with existing document
611
- - Enables proper RxDB replication conflict handling
612
-
613
- ### Changed
614
- - **BREAKING**: `bulkWrite` now uses individual INSERT statements instead of INSERT OR REPLACE
615
- - Conflicts are now detected and returned as errors
616
- - Enables proper RxDB replication conflict resolution
617
-
618
- ### Performance
619
- - Benchmark results (10k documents, 10-run average):
620
- - **JSON + TEXT: 23.40ms** (WINNER)
621
- - Tested alternatives: MessagePack (137ms), bun:jsc (37ms)
622
- - **Verdict: Bun's SIMD-accelerated JSON is fastest**
623
-
624
- ### Research Notes
625
- - Extensively tested binary serialization formats (MessagePack, bun:jsc)
626
- - MessagePack: 5.6x slower than JSON (pure JS implementation)
627
- - bun:jsc (optimized): 1.58x slower than JSON (Structured Clone overhead)
628
- - **Conclusion: JSON + TEXT is optimal for Bun's architecture**
629
-
630
- ## [0.1.2] - 2026-02-22
631
-
632
- ### Added
633
- - Conflict detection for concurrent writes
634
- - Catches UNIQUE constraint violations
635
- - Returns 409 status with existing document
636
- - Enables proper RxDB replication conflict handling
637
-
638
- ### Changed
639
- - **BREAKING**: `bulkWrite` now uses individual INSERT statements instead of INSERT OR REPLACE
640
- - Conflicts are now detected and returned as errors
641
- - Enables proper RxDB replication conflict resolution
642
-
643
- ### Performance
644
- - Benchmark results (10k documents):
645
- - Simple equality: 15.40ms
646
- - Greater than: 22.05ms
647
- - Multiple conditions: 23.51ms
648
- - Range query: 24.89ms
649
- - Average: 21.46ms
650
-
651
- ## [0.1.2] - 2026-02-22
652
-
653
- ### Added
654
- - WAL mode for 3-6x write speedup and better concurrency
655
- - Automatically enabled for file-based databases
656
- - Skipped for in-memory databases (not supported by SQLite)
657
- - Proper checkpoint implementation in changeStream
658
- - Checkpoint structure: `{ id: documentId, lwt: timestamp }`
659
- - Enables efficient replication tracking
660
-
661
- ### Removed
662
- - **BREAKING**: Removed `conflictResultionTasks()` method (doesn't exist in RxDB interface)
663
- - **BREAKING**: Removed `resolveConflictResultionTask()` method (doesn't exist in RxDB interface)
664
- - Conflict resolution happens at RxDB replication level, not storage level
665
-
666
- ### Changed
667
- - WAL mode test now uses file-based database instead of in-memory
668
-
669
- ### Performance
670
- - Write operations: 3-6x faster with WAL mode
671
- - Concurrent reads during writes: No blocking with WAL mode
672
-
673
- ## [0.1.1] - 2026-02-22
674
-
675
- ### Added
676
- - SQL query builder for WHERE clause generation (10-100x speedup)
677
- - 6 Mango operators: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
678
- - Functional architecture (pure functions, no state)
679
- - Column mapping for RxDB internal fields
680
- - Fallback to in-memory filtering if WHERE fails
681
- - Benchmark script for performance testing
682
- - Comprehensive test suite (27 tests total)
683
- - 19 storage tests
684
- - 6 operator tests
685
- - 10 query builder tests
686
-
687
- ### Changed
688
- - **BREAKING**: Removed per-document error handling in `bulkWrite`
689
- - Now uses atomic transactions (all or nothing)
690
- - Entire batch fails if any document fails
691
- - Removed ALL `any` types (32 instances → 0)
692
- - Proper TypeScript types throughout
693
- - `RxStorage<BunSQLiteInternals, BunSQLiteStorageSettings>`
694
- - `RxStorageInstance` with proper type parameters
695
- - `PreparedQuery<RxDocType>` for queries
696
- - `RxStorageWriteError<RxDocType>` for errors
697
-
698
- ### Fixed
699
- - Type safety: Zero `any` types in entire codebase
700
- - Test isolation: Reference folder excluded from test runs
701
- - Schema types: Proper RxDB internal fields in all schemas
702
-
703
- ### Performance
704
- - Query performance: ~20ms average for 10k documents
705
- - Uses SQL WHERE clauses with indexed columns
706
- - Expected 10-100x speedup vs in-memory filtering
707
-
708
- ## [0.1.0] - 2026-02-20
709
-
710
- ### Added
711
- - Initial RxDB storage adapter for Bun's native SQLite
712
- - Basic CRUD operations (bulkWrite, query, findById, count)
713
- - Atomic transactions via `bun:sqlite`
714
- - In-memory Mango query filtering
715
- - Streak tracking support
716
- - Change stream for reactivity
717
- - 8 passing tests
718
-
719
- ### Features
720
- - SQLite via `bun:sqlite` (no external dependencies)
721
- - RxDB v16 and v17 beta support
722
- - MIT licensed