bun-sqlite-for-rxdb 1.0.1

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.
Files changed (68) hide show
  1. package/.serena/project.yml +84 -0
  2. package/CHANGELOG.md +300 -0
  3. package/LICENSE +21 -0
  4. package/README.md +87 -0
  5. package/ROADMAP.md +532 -0
  6. package/benchmarks/benchmark.ts +145 -0
  7. package/benchmarks/case-insensitive-10runs.ts +156 -0
  8. package/benchmarks/fts5-1m-scale.ts +126 -0
  9. package/benchmarks/fts5-before-after.ts +104 -0
  10. package/benchmarks/indexed-benchmark.ts +141 -0
  11. package/benchmarks/new-operators-benchmark.ts +140 -0
  12. package/benchmarks/query-builder-benchmark.ts +88 -0
  13. package/benchmarks/query-builder-consistency.ts +109 -0
  14. package/benchmarks/raw-better-sqlite3-10m.ts +85 -0
  15. package/benchmarks/raw-better-sqlite3.ts +86 -0
  16. package/benchmarks/raw-bun-sqlite-10m.ts +85 -0
  17. package/benchmarks/raw-bun-sqlite.ts +86 -0
  18. package/benchmarks/regex-10runs-all.ts +216 -0
  19. package/benchmarks/regex-comparison-benchmark.ts +161 -0
  20. package/benchmarks/regex-real-comparison.ts +213 -0
  21. package/benchmarks/run-10x.sh +19 -0
  22. package/benchmarks/smart-regex-benchmark.ts +148 -0
  23. package/benchmarks/sql-vs-mingo-benchmark.ts +210 -0
  24. package/benchmarks/sql-vs-mingo-comparison.ts +175 -0
  25. package/benchmarks/text-vs-jsonb.ts +167 -0
  26. package/benchmarks/wal-benchmark.ts +112 -0
  27. package/docs/architectural-patterns.md +1336 -0
  28. package/docs/id1-testsuite-journey.md +839 -0
  29. package/docs/official-test-suite-setup.md +393 -0
  30. package/nul +0 -0
  31. package/package.json +44 -0
  32. package/src/changestream.test.ts +182 -0
  33. package/src/cleanup.test.ts +110 -0
  34. package/src/collection-isolation.test.ts +74 -0
  35. package/src/connection-pool.test.ts +102 -0
  36. package/src/connection-pool.ts +38 -0
  37. package/src/findDocumentsById.test.ts +122 -0
  38. package/src/index.ts +2 -0
  39. package/src/instance.ts +382 -0
  40. package/src/multi-instance-events.test.ts +204 -0
  41. package/src/query/and-operator.test.ts +39 -0
  42. package/src/query/builder.test.ts +96 -0
  43. package/src/query/builder.ts +154 -0
  44. package/src/query/elemMatch-operator.test.ts +24 -0
  45. package/src/query/exists-operator.test.ts +28 -0
  46. package/src/query/in-operators.test.ts +54 -0
  47. package/src/query/mod-operator.test.ts +22 -0
  48. package/src/query/nested-query.test.ts +198 -0
  49. package/src/query/not-operators.test.ts +49 -0
  50. package/src/query/operators.test.ts +70 -0
  51. package/src/query/operators.ts +185 -0
  52. package/src/query/or-operator.test.ts +68 -0
  53. package/src/query/regex-escaping-regression.test.ts +43 -0
  54. package/src/query/regex-operator.test.ts +44 -0
  55. package/src/query/schema-mapper.ts +27 -0
  56. package/src/query/size-operator.test.ts +22 -0
  57. package/src/query/smart-regex.ts +52 -0
  58. package/src/query/type-operator.test.ts +37 -0
  59. package/src/query-cache.test.ts +286 -0
  60. package/src/rxdb-helpers.test.ts +348 -0
  61. package/src/rxdb-helpers.ts +262 -0
  62. package/src/schema-version-isolation.test.ts +126 -0
  63. package/src/statement-manager.ts +69 -0
  64. package/src/storage.test.ts +589 -0
  65. package/src/storage.ts +21 -0
  66. package/src/types.ts +14 -0
  67. package/test/rxdb-test-suite.ts +27 -0
  68. package/tsconfig.json +31 -0
@@ -0,0 +1,84 @@
1
+ # list of languages for which language servers are started; choose from:
2
+ # al bash clojure cpp csharp csharp_omnisharp
3
+ # dart elixir elm erlang fortran go
4
+ # haskell java julia kotlin lua markdown
5
+ # nix perl php python python_jedi r
6
+ # rego ruby ruby_solargraph rust scala swift
7
+ # terraform typescript typescript_vts yaml zig
8
+ # Note:
9
+ # - For C, use cpp
10
+ # - For JavaScript, use typescript
11
+ # Special requirements:
12
+ # - csharp: Requires the presence of a .sln file in the project folder.
13
+ # When using multiple languages, the first language server that supports a given file will be used for that file.
14
+ # The first language is the default language and the respective language server will be used as a fallback.
15
+ # Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
16
+ languages:
17
+ - typescript
18
+
19
+ # the encoding used by text files in the project
20
+ # For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
21
+ encoding: "utf-8"
22
+
23
+ # whether to use the project's gitignore file to ignore files
24
+ # Added on 2025-04-07
25
+ ignore_all_files_in_gitignore: true
26
+
27
+ # list of additional paths to ignore
28
+ # same syntax as gitignore, so you can use * and **
29
+ # Was previously called `ignored_dirs`, please update your config if you are using that.
30
+ # Added (renamed) on 2025-04-07
31
+ ignored_paths: []
32
+
33
+ # whether the project is in read-only mode
34
+ # If set to true, all editing tools will be disabled and attempts to use them will result in an error
35
+ # Added on 2025-04-18
36
+ read_only: false
37
+
38
+ # list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
39
+ # Below is the complete list of tools for convenience.
40
+ # To make sure you have the latest list of tools, and to view their descriptions,
41
+ # execute `uv run scripts/print_tool_overview.py`.
42
+ #
43
+ # * `activate_project`: Activates a project by name.
44
+ # * `check_onboarding_performed`: Checks whether project onboarding was already performed.
45
+ # * `create_text_file`: Creates/overwrites a file in the project directory.
46
+ # * `delete_lines`: Deletes a range of lines within a file.
47
+ # * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
48
+ # * `execute_shell_command`: Executes a shell command.
49
+ # * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
50
+ # * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
51
+ # * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
52
+ # * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
53
+ # * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
54
+ # * `initial_instructions`: Gets the initial instructions for the current project.
55
+ # Should only be used in settings where the system prompt cannot be set,
56
+ # e.g. in clients you have no control over, like Claude Desktop.
57
+ # * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
58
+ # * `insert_at_line`: Inserts content at a given line in a file.
59
+ # * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
60
+ # * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
61
+ # * `list_memories`: Lists memories in Serena's project-specific memory store.
62
+ # * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
63
+ # * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
64
+ # * `read_file`: Reads a file within the project directory.
65
+ # * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
66
+ # * `remove_project`: Removes a project from the Serena configuration.
67
+ # * `replace_lines`: Replaces a range of lines within a file with new content.
68
+ # * `replace_symbol_body`: Replaces the full definition of a symbol.
69
+ # * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
70
+ # * `search_for_pattern`: Performs a search for a pattern in the project.
71
+ # * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
72
+ # * `switch_modes`: Activates modes by providing a list of their names
73
+ # * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
74
+ # * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
75
+ # * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
76
+ # * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
77
+ excluded_tools: []
78
+
79
+ # initial prompt for the project. It will always be given to the LLM upon activating the project
80
+ # (contrary to the memories, which are loaded on demand).
81
+ initial_prompt: ""
82
+
83
+ project_name: "bun-sqlite-for-rxdb"
84
+ included_optional_tools: []
package/CHANGELOG.md ADDED
@@ -0,0 +1,300 @@
1
+ # Changelog
2
+
3
+ ## [1.0.1] - 2026-02-23
4
+
5
+ ### Added
6
+ - **EXPLAIN QUERY PLAN Debug Mode** (Development Tool)
7
+ - Activated via `DEBUG_QUERIES=1` environment variable
8
+ - Logs query plans, SQL, and args to console
9
+ - Helps verify query builder generates optimal SQL
10
+ - Validates SQLite index usage
11
+ - Zero production overhead (env var check only)
12
+
13
+ ### Usage
14
+ ```bash
15
+ DEBUG_QUERIES=1 bun test
16
+ ```
17
+
18
+ ---
19
+
20
+ ## [1.0.0] - 2026-02-23
21
+
22
+ ### Added
23
+ - **Attachments Support** (Phase 4)
24
+ - Storage-level implementation with 4 comprehensive tests
25
+ - `getAttachmentData()` returns base64 strings with digest validation
26
+ - Preserves `_attachments` metadata in documents
27
+ - Attachments table with composite keys (documentId||attachmentId)
28
+ - 122/122 official RxDB tests passing (includes 5 attachment tests)
29
+ - **RxDB Helper Functions** (Phase 4)
30
+ - `categorizeBulkWriteRows()` - Battle-tested conflict detection + attachment extraction
31
+ - `stripAttachmentsDataFromDocument()` - Remove attachment .data field, keep metadata
32
+ - `stripAttachmentsDataFromRow()` - Strip attachments from bulk write rows
33
+ - `attachmentWriteDataToNormalData()` - Convert attachment write format to storage format
34
+ - `getAttachmentSize()` - Calculate attachment size from base64
35
+
36
+ ### Changed
37
+ - **bulkWrite Refactored** - Now uses `categorizeBulkWriteRows()` helper
38
+ - Cleaner architecture with proper conflict handling
39
+ - Automatic attachment extraction
40
+ - Matches official adapter patterns (Dexie, MongoDB, SQLite)
41
+
42
+ ### Test Results
43
+ - **Local tests: 138/138 pass (100%)** ✅
44
+ - **Official RxDB tests: 122/122 pass (100%)** ✅
45
+ - **Total: 260/260 tests pass (100%)** 🎉
46
+
47
+ ### Performance
48
+ - Database operations: 1.06-1.68x faster than better-sqlite3
49
+ - Query builder cache: 5.2-57.9x speedup for cached queries
50
+ - All optimizations from v0.4.0 included
51
+
52
+ ### Documentation
53
+ - Updated ROADMAP.md - Phase 4 marked COMPLETE
54
+ - Removed redundant Phase 4 TDD implementation details
55
+ - All helper functions documented with line numbers
56
+
57
+ ---
58
+
59
+ ## [0.4.0] - 2026-02-23
60
+
61
+ ### Added
62
+ - **Query Builder LRU Cache** (Phase 2.5)
63
+ - 5.2-57.9x speedup for repeated queries
64
+ - High-frequency: 505K-808K queries/sec
65
+ - Bounded at 500 entries (no memory leak)
66
+ - True LRU eviction with canonical key generation (fast-stable-stringify)
67
+ - Zero dependencies except fast-stable-stringify (5KB)
68
+ - **RxDB Official Test Suite Integration** (Phase 3.1)
69
+ - 112/112 official RxDB tests passing (100%)
70
+ - StatementManager abstraction for automatic statement lifecycle
71
+ - Connection pooling with reference counting for multi-instance support
72
+ - Official `addRxStorageMultiInstanceSupport()` integration
73
+ - Composite primary key support
74
+ - Bun test suite compatibility (Mocha through Bun)
75
+ - **Performance Benchmarks** (Phase 3.2)
76
+ - Bun:sqlite 1.06-1.68x faster than better-sqlite3
77
+ - Benchmarked at 1M documents with WAL + PRAGMA synchronous = 1
78
+ - Query builder cache benchmarks
79
+ - Raw database comparison benchmarks
80
+ - **New Query Operators** (8 operators added)
81
+ - `$exists` - Field existence check with IS NULL/IS NOT NULL
82
+ - `$regex` - Pattern matching with LIKE translation and Mingo fallback
83
+ - `$elemMatch` - Array element matching (Mingo fallback)
84
+ - `$not` - Negation operator
85
+ - `$nor` - Logical NOR
86
+ - `$type` - Type checking with typeof()
87
+ - `$size` - Array size with json_array_length()
88
+ - `$mod` - Modulo operations
89
+
90
+ ### Changed
91
+ - **BREAKING**: Statement lifecycle management
92
+ - Static SQL uses db.query() (cached, max 20)
93
+ - Dynamic SQL uses db.prepare() + finalize() (no cache pollution)
94
+ - StatementManager abstraction eliminates manual try-finally boilerplate
95
+ - Connection pooling now mandatory for multi-instance support
96
+ - Switched from custom multi-instance to RxDB's official implementation
97
+
98
+ ### Fixed
99
+ - Statement resource leaks (7 locations in instance.ts)
100
+ - Collection isolation bug (events leaked across collections)
101
+ - Composite primary key handling (string vs object format)
102
+ - EventBulk.id generation (empty string → unique timestamp + random)
103
+ - Multi-instance event propagation via BroadcastChannel
104
+ - Bun test suite compatibility (node:sqlite import, test globals)
105
+
106
+ ### Performance
107
+ - Query builder cache: 5.2-57.9x speedup for cached queries
108
+ - Database operations: 1.06-1.68x faster than better-sqlite3
109
+ - No OOM errors (proper statement finalization)
110
+ - Tests complete in 12.91s (no hangs)
111
+
112
+ ### Test Results
113
+ - **Local tests: 134/134 pass (100%)**
114
+ - **Official RxDB tests: 112/112 pass (100%)**
115
+ - **Total: 246/246 tests pass (100%)** 🎉
116
+
117
+ ### Documentation
118
+ - Added `docs/id1-testsuite-journey.md` - Complete debugging journey (15 iterations)
119
+ - Added `docs/official-test-suite-setup.md` - Guide for running RxDB tests with Bun
120
+ - Updated `docs/architectural-patterns.md` - Added patterns 15-24
121
+ - Updated `ROADMAP.md` - Phase 2.5 and 3.2 marked COMPLETE, Phase 4 marked READY
122
+
123
+ ### Technical Debt Resolved
124
+ - Statement lifecycle properly managed (no leaks)
125
+ - Connection pooling with reference counting
126
+ - Test architecture at correct level (RxDatabase for integration, storage for low-level)
127
+ - Proper separation of concerns (we handle DB pooling, RxDB handles event coordination)
128
+
129
+ ---
130
+
131
+ ## [0.3.1] - 2026-02-22
132
+
133
+ ### Added
134
+ - **JSONB Storage**: Implemented SQLite's native binary JSON format as default storage
135
+ - 1.57x faster complex queries (657ms → 418ms at 1M docs)
136
+ - 1.20x faster read + parse operations
137
+ - 1.04x faster simple queries
138
+ - Uses `jsonb()` on INSERT, `json()` on SELECT
139
+ - **Smart Regex Optimization**: Convert simple regex patterns to SQL operators
140
+ - 2.03x faster exact matches (^text$ → = operator)
141
+ - 1.23x faster case-insensitive (COLLATE NOCASE vs LOWER())
142
+ - Overall 1.24x speedup across all patterns
143
+ - **Regression Tests**: Added tests for % and _ escaping edge cases
144
+
145
+ ### Fixed
146
+ - Critical bug: Missing % and _ escaping in case-insensitive exact match regex patterns
147
+
148
+ ### Investigated
149
+ - **FTS5 Trigram Indexes**: Benchmarked at 100k and 1M scales
150
+ - Result: 1.5-1.79x SLOWER at our scale
151
+ - Decision: NOT implemented (only beneficial at 10M+ rows)
152
+ - Documented findings in architectural-patterns.md
153
+
154
+ ### Performance
155
+ - Complex queries: 1.57x faster (JSONB)
156
+ - Exact match regex: 2.03x faster (smart optimization)
157
+ - Read operations: 1.20x faster (JSONB)
158
+
159
+ ---
160
+
161
+ ## [0.3.0] - 2026-02-22
162
+
163
+ ### Added
164
+ - **Advanced Query Operators** (4 new operators)
165
+ - `$in` - Value in array (80% usage in production)
166
+ - `$nin` - Value not in array
167
+ - `$or` - Logical OR with proper parentheses handling
168
+ - `$and` - Explicit logical AND
169
+ - NULL handling for `$in` / `$nin` operators
170
+ - Recursive query builder with `logicalDepth` tracking
171
+ - 13 new tests for advanced operators
172
+
173
+ ### Performance
174
+ - Benchmark results (10k documents):
175
+ - Average query time: 27.39ms
176
+ - Supports complex nested queries: `{$or: [{$and: [...]}, {field: {$in: [...]}}]}`
177
+
178
+ ### Technical
179
+ - DRY architecture: Pure operator functions, recursive builder
180
+ - Type-safe: 0 `any` types, proper TypeScript throughout
181
+ - Test coverage: 44/44 tests passing
182
+
183
+ ## [0.2.0] - 2026-02-22
184
+
185
+ ### Added
186
+ - Conflict detection for concurrent writes
187
+ - Catches UNIQUE constraint violations
188
+ - Returns 409 status with existing document
189
+ - Enables proper RxDB replication conflict handling
190
+
191
+ ### Changed
192
+ - **BREAKING**: `bulkWrite` now uses individual INSERT statements instead of INSERT OR REPLACE
193
+ - Conflicts are now detected and returned as errors
194
+ - Enables proper RxDB replication conflict resolution
195
+
196
+ ### Performance
197
+ - Benchmark results (10k documents, 10-run average):
198
+ - **JSON + TEXT: 23.40ms** (WINNER)
199
+ - Tested alternatives: MessagePack (137ms), bun:jsc (37ms)
200
+ - **Verdict: Bun's SIMD-accelerated JSON is fastest**
201
+
202
+ ### Research Notes
203
+ - Extensively tested binary serialization formats (MessagePack, bun:jsc)
204
+ - MessagePack: 5.6x slower than JSON (pure JS implementation)
205
+ - bun:jsc (optimized): 1.58x slower than JSON (Structured Clone overhead)
206
+ - **Conclusion: JSON + TEXT is optimal for Bun's architecture**
207
+
208
+ ## [0.1.2] - 2026-02-22
209
+
210
+ ### Added
211
+ - Conflict detection for concurrent writes
212
+ - Catches UNIQUE constraint violations
213
+ - Returns 409 status with existing document
214
+ - Enables proper RxDB replication conflict handling
215
+
216
+ ### Changed
217
+ - **BREAKING**: `bulkWrite` now uses individual INSERT statements instead of INSERT OR REPLACE
218
+ - Conflicts are now detected and returned as errors
219
+ - Enables proper RxDB replication conflict resolution
220
+
221
+ ### Performance
222
+ - Benchmark results (10k documents):
223
+ - Simple equality: 15.40ms
224
+ - Greater than: 22.05ms
225
+ - Multiple conditions: 23.51ms
226
+ - Range query: 24.89ms
227
+ - Average: 21.46ms
228
+
229
+ ## [0.1.2] - 2026-02-22
230
+
231
+ ### Added
232
+ - WAL mode for 3-6x write speedup and better concurrency
233
+ - Automatically enabled for file-based databases
234
+ - Skipped for in-memory databases (not supported by SQLite)
235
+ - Proper checkpoint implementation in changeStream
236
+ - Checkpoint structure: `{ id: documentId, lwt: timestamp }`
237
+ - Enables efficient replication tracking
238
+
239
+ ### Removed
240
+ - **BREAKING**: Removed `conflictResultionTasks()` method (doesn't exist in RxDB interface)
241
+ - **BREAKING**: Removed `resolveConflictResultionTask()` method (doesn't exist in RxDB interface)
242
+ - Conflict resolution happens at RxDB replication level, not storage level
243
+
244
+ ### Changed
245
+ - WAL mode test now uses file-based database instead of in-memory
246
+
247
+ ### Performance
248
+ - Write operations: 3-6x faster with WAL mode
249
+ - Concurrent reads during writes: No blocking with WAL mode
250
+
251
+ ## [0.1.1] - 2026-02-22
252
+
253
+ ### Added
254
+ - SQL query builder for WHERE clause generation (10-100x speedup)
255
+ - 6 Mango operators: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
256
+ - Functional architecture (pure functions, no state)
257
+ - Column mapping for RxDB internal fields
258
+ - Fallback to in-memory filtering if WHERE fails
259
+ - Benchmark script for performance testing
260
+ - Comprehensive test suite (27 tests total)
261
+ - 19 storage tests
262
+ - 6 operator tests
263
+ - 10 query builder tests
264
+
265
+ ### Changed
266
+ - **BREAKING**: Removed per-document error handling in `bulkWrite`
267
+ - Now uses atomic transactions (all or nothing)
268
+ - Entire batch fails if any document fails
269
+ - Removed ALL `any` types (32 instances → 0)
270
+ - Proper TypeScript types throughout
271
+ - `RxStorage<BunSQLiteInternals, BunSQLiteStorageSettings>`
272
+ - `RxStorageInstance` with proper type parameters
273
+ - `PreparedQuery<RxDocType>` for queries
274
+ - `RxStorageWriteError<RxDocType>` for errors
275
+
276
+ ### Fixed
277
+ - Type safety: Zero `any` types in entire codebase
278
+ - Test isolation: Reference folder excluded from test runs
279
+ - Schema types: Proper RxDB internal fields in all schemas
280
+
281
+ ### Performance
282
+ - Query performance: ~20ms average for 10k documents
283
+ - Uses SQL WHERE clauses with indexed columns
284
+ - Expected 10-100x speedup vs in-memory filtering
285
+
286
+ ## [0.1.0] - 2026-02-20
287
+
288
+ ### Added
289
+ - Initial RxDB storage adapter for Bun's native SQLite
290
+ - Basic CRUD operations (bulkWrite, query, findById, count)
291
+ - Atomic transactions via `bun:sqlite`
292
+ - In-memory Mango query filtering
293
+ - Streak tracking support
294
+ - Change stream for reactivity
295
+ - 8 passing tests
296
+
297
+ ### Features
298
+ - SQLite via `bun:sqlite` (no external dependencies)
299
+ - RxDB v16 and v17 beta support
300
+ - MIT licensed
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 adam2am
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # bun-sqlite-for-rxdb
2
+
3
+ > Unofficial RxDB storage adapter for Bun's native SQLite (`bun:sqlite`)
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ ## Features
8
+
9
+ - ✅ Uses Bun's native SQLite
10
+ - ✅ **260/260 tests passing** (138 local + 122 official RxDB tests)
11
+ - ✅ Full RxDB storage interface implementation
12
+ - ✅ **Attachments support** (base64 storage with digest validation)
13
+ - ✅ **Query builder LRU cache** (5.2-57.9x speedup for repeated queries)
14
+ - ✅ **18 Mango operators** ($eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $or, $and, $exists, $regex, $elemMatch, $not, $nor, $type, $size, $mod)
15
+ - ✅ **Multi-instance support** with connection pooling
16
+ - ✅ **1.06-1.68x faster than better-sqlite3** (with WAL mode)
17
+ - ✅ MIT licensed
18
+
19
+ ## Performance
20
+
21
+ Benchmarked against better-sqlite3 (1M documents, WAL mode + PRAGMA synchronous = 1):
22
+
23
+ | Operation | Bun SQLite | better-sqlite3 | Speedup |
24
+ |-----------|------------|----------------|---------|
25
+ | Bulk INSERT (1M docs) | 7.42s | 7.90s | **1.06x faster** |
26
+ | SELECT by ID (10K lookups) | 170ms | 170ms | Equal |
27
+ | Complex WHERE query | 484ms | 814ms | **1.68x faster** |
28
+
29
+ **Requirements for optimal performance:**
30
+ ```typescript
31
+ db.run("PRAGMA journal_mode = WAL");
32
+ db.run("PRAGMA synchronous = 1");
33
+ ```
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ bun add bun-sqlite-for-rxdb
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```typescript
44
+ import { createRxDatabase } from 'rxdb';
45
+ import { getRxStorageBunSQLite } from 'bun-sqlite-for-rxdb';
46
+
47
+ const db = await createRxDatabase({
48
+ name: 'mydb',
49
+ storage: getRxStorageBunSQLite()
50
+ });
51
+ ```
52
+
53
+ ## Development
54
+
55
+ ```bash
56
+ # Install dependencies
57
+ bun install
58
+
59
+ # Build
60
+ bun run build
61
+
62
+ # Test
63
+ bun test
64
+
65
+ # Type check
66
+ bun run typecheck
67
+ ```
68
+
69
+ ## Architecture
70
+
71
+ **Key components:**
72
+ - `RxStorage` factory
73
+ - `RxStorageInstance` implementation (11 required methods)
74
+ - Mango query → SQL translator
75
+ - Change stream observables
76
+
77
+ ## License
78
+
79
+ MIT © adam2am
80
+
81
+ ## Contributing
82
+
83
+ Contributions welcome! This is a community project.
84
+
85
+ ---
86
+
87
+ **Not affiliated with RxDB or Bun. Community-maintained adapter.**