@firtoz/drizzle-sqlite-wasm 0.1.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 ADDED
@@ -0,0 +1,230 @@
1
+ # @firtoz/drizzle-sqlite-wasm
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#22](https://github.com/firtoz/fullstack-toolkit/pull/22) [`05e88e7`](https://github.com/firtoz/fullstack-toolkit/commit/05e88e775f262488d1da2b579eadd560cee2eba9) Thanks [@firtoz](https://github.com/firtoz)! - Initial release of `@firtoz/drizzle-sqlite-wasm` - TanStack DB collections backed by SQLite WASM running in Web Workers, with full Drizzle ORM integration.
8
+
9
+ > **⚠️ Early WIP Notice:** This package is in very early development and is **not production-ready**. It is TypeScript-only and may have breaking changes. While I (the maintainer) have limited time, I'm open to PRs for features, bug fixes, or additional support (like JS builds). Please feel free to try it out and contribute! See [CONTRIBUTING.md](../../CONTRIBUTING.md) for details.
10
+
11
+ ## Features
12
+
13
+ ### TanStack DB Collections (Primary Feature)
14
+
15
+ **`drizzleCollectionOptions(config)`** - The main feature: Create reactive TanStack DB collections backed by SQLite WASM:
16
+
17
+ - Type-safe CRUD operations
18
+ - Reactive subscriptions to data changes
19
+ - Soft delete support
20
+ - Query optimization with SQLite indexes
21
+ - Pagination and sorting
22
+ - Non-blocking operations via Web Workers
23
+
24
+ **IndexedDB fallback** - Re-exports `indexedDBCollectionOptions` from `@firtoz/drizzle-indexeddb`:
25
+
26
+ - Seamless integration between SQLite and IndexedDB
27
+ - Use IndexedDB for offline-first sync layer
28
+ - Consistent API across both storage backends
29
+
30
+ ### Worker-Based SQLite
31
+
32
+ **`SqliteWorkerManager`** - Manages multiple SQLite databases in a single worker:
33
+
34
+ - Efficient resource utilization with shared worker
35
+ - Database instance caching and lifecycle management
36
+ - Automatic migration handling
37
+ - Global manager for singleton worker access
38
+
39
+ **`initializeSqliteWorker()`** - Initialize the global SQLite worker:
40
+
41
+ - Accepts any Worker constructor for bundler compatibility
42
+ - Debug mode for performance tracking
43
+ - Returns manager for manual control
44
+
45
+ ### Drizzle Integration
46
+
47
+ **`drizzleSqliteWasmWorker(client, config, debug?)`** - Create Drizzle instance backed by worker:
48
+
49
+ - Full Drizzle ORM API with type safety
50
+ - Async query execution via Worker
51
+ - Automatic serialization/deserialization
52
+
53
+ **`drizzleSqliteWasm(sqliteDb, config, debug?)`** - Direct Drizzle instance (non-worker):
54
+
55
+ - Use SQLite WASM directly in main thread
56
+ - Same Drizzle ORM API
57
+ - Ideal for testing or synchronous contexts
58
+
59
+ ### Migrations
60
+
61
+ **`customSqliteMigrate(config)`** - Custom SQLite migration system:
62
+
63
+ - Compatible with Drizzle snapshots
64
+ - Handles SQL migrations
65
+ - Tracks applied migrations
66
+ - Journal-based migration history
67
+
68
+ ### React Integration
69
+
70
+ **`DrizzleSqliteProvider`** - React context provider:
71
+
72
+ - Manages worker lifecycle
73
+ - Automatic database initialization
74
+ - Collection caching with ref counting
75
+ - Type-safe context
76
+
77
+ **`useDrizzleSqliteDb(Worker, dbName, schema, migrations)`** - React hook for SQLite:
78
+
79
+ - Automatic worker management
80
+ - Migration handling
81
+ - Ready promise for initialization tracking
82
+ - Bundler-agnostic Worker support
83
+
84
+ **`useDrizzleSqlite()`** - Access Drizzle SQLite context:
85
+
86
+ - Get Drizzle instance
87
+ - Access collections with type safety
88
+
89
+ **`useSqliteCollection(tableName)`** - Hook for specific collections:
90
+
91
+ - Automatic ref counting
92
+ - Type-safe collection access
93
+
94
+ ### Performance Utilities
95
+
96
+ Built-in performance monitoring tools:
97
+
98
+ - `getPerformanceMetrics()` - Get detailed timing metrics
99
+ - `getPerformanceMarks()` - Access performance marks
100
+ - `logPerformanceMetrics()` - Log performance data
101
+ - `exportPerformanceData()` - Export metrics for analysis
102
+ - `clearPerformanceData()` - Clear performance history
103
+ - `createPerformanceObserver()` - Custom performance observers
104
+
105
+ ### Type Utilities
106
+
107
+ Re-exports from `@firtoz/drizzle-utils`:
108
+
109
+ - `syncableTable` - Create tables with timestamp tracking
110
+ - `makeId` - Type-safe ID creation
111
+ - `IdOf`, `TableId`, `Branded` - Type utilities
112
+ - `SelectSchema`, `InsertSchema` - Schema helpers
113
+
114
+ ## Bundler Support
115
+
116
+ Works with all major bundlers:
117
+
118
+ **Vite:**
119
+
120
+ ```typescript
121
+ import SqliteWorker from "@firtoz/drizzle-sqlite-wasm/worker/sqlite.worker?worker";
122
+ const { drizzle } = useDrizzleSqliteDb(
123
+ SqliteWorker,
124
+ "mydb",
125
+ schema,
126
+ migrations
127
+ );
128
+ ```
129
+
130
+ **Webpack 5+:**
131
+
132
+ ```typescript
133
+ const SqliteWorker = class extends Worker {
134
+ constructor() {
135
+ super(
136
+ new URL(
137
+ "@firtoz/drizzle-sqlite-wasm/worker/sqlite.worker",
138
+ import.meta.url
139
+ ),
140
+ { type: "module" }
141
+ );
142
+ }
143
+ };
144
+ const { drizzle } = useDrizzleSqliteDb(
145
+ SqliteWorker,
146
+ "mydb",
147
+ schema,
148
+ migrations
149
+ );
150
+ ```
151
+
152
+ **Parcel 2+:**
153
+
154
+ ```typescript
155
+ const SqliteWorker = class extends Worker {
156
+ constructor() {
157
+ super(
158
+ new URL(
159
+ "@firtoz/drizzle-sqlite-wasm/worker/sqlite.worker",
160
+ import.meta.url
161
+ )
162
+ );
163
+ }
164
+ };
165
+ const { drizzle } = useDrizzleSqliteDb(
166
+ SqliteWorker,
167
+ "mydb",
168
+ schema,
169
+ migrations
170
+ );
171
+ ```
172
+
173
+ ## Example
174
+
175
+ ```typescript
176
+ import {
177
+ DrizzleSqliteProvider,
178
+ useDrizzleSqliteDb,
179
+ } from "@firtoz/drizzle-sqlite-wasm";
180
+ import SqliteWorker from "@firtoz/drizzle-sqlite-wasm/worker/sqlite.worker?worker";
181
+ import * as schema from "./schema";
182
+ import migrations from "./migrations";
183
+
184
+ function App() {
185
+ return (
186
+ <DrizzleSqliteProvider
187
+ worker={SqliteWorker}
188
+ dbName="my-app-db"
189
+ schema={schema}
190
+ migrations={migrations}
191
+ >
192
+ <TodoList />
193
+ </DrizzleSqliteProvider>
194
+ );
195
+ }
196
+
197
+ function TodoList() {
198
+ const { drizzle } = useDrizzleSqliteDb(
199
+ SqliteWorker,
200
+ "my-app-db",
201
+ schema,
202
+ migrations
203
+ );
204
+
205
+ // Use Drizzle ORM
206
+ const todos = await drizzle.select().from(schema.todoTable);
207
+
208
+ // Or use TanStack DB collections
209
+ const collection = useSqliteCollection("todos");
210
+ }
211
+ ```
212
+
213
+ ## Dependencies
214
+
215
+ - `@firtoz/drizzle-indexeddb` (workspace)
216
+ - `@firtoz/drizzle-utils` (workspace)
217
+ - `@firtoz/maybe-error` (workspace)
218
+ - `@firtoz/worker-helper` (workspace)
219
+ - `@sqlite.org/sqlite-wasm`
220
+ - `drizzle-orm`
221
+ - `drizzle-valibot`
222
+ - `@tanstack/db`
223
+ - `react`
224
+ - `zod`
225
+
226
+ ### Patch Changes
227
+
228
+ - Updated dependencies [[`05e88e7`](https://github.com/firtoz/fullstack-toolkit/commit/05e88e775f262488d1da2b579eadd560cee2eba9), [`cf12782`](https://github.com/firtoz/fullstack-toolkit/commit/cf1278236e484e6350eb614ce2381e0afcec326e)]:
229
+ - @firtoz/drizzle-utils@0.1.0
230
+ - @firtoz/worker-helper@1.0.0