@framers/sql-storage-adapter 0.1.0 → 0.3.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/LICENSE +20 -20
- package/README.md +241 -363
- package/dist/adapters/__tests__/indexedDbAdapter.spec.d.ts +2 -0
- package/dist/adapters/__tests__/indexedDbAdapter.spec.d.ts.map +1 -0
- package/dist/adapters/__tests__/indexedDbAdapter.spec.js +137 -0
- package/dist/adapters/__tests__/indexedDbAdapter.spec.js.map +1 -0
- package/dist/adapters/baseStorageAdapter.d.ts +1 -1
- package/dist/adapters/baseStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/betterSqliteAdapter.d.ts +27 -1
- package/dist/adapters/betterSqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/betterSqliteAdapter.js +81 -16
- package/dist/adapters/betterSqliteAdapter.js.map +1 -1
- package/dist/adapters/capacitorSqliteAdapter.d.ts +1 -1
- package/dist/adapters/capacitorSqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitorSqliteAdapter.js +27 -4
- package/dist/adapters/capacitorSqliteAdapter.js.map +1 -1
- package/dist/adapters/indexedDbAdapter.d.ts +189 -0
- package/dist/adapters/indexedDbAdapter.d.ts.map +1 -0
- package/dist/adapters/indexedDbAdapter.js +367 -0
- package/dist/adapters/indexedDbAdapter.js.map +1 -0
- package/dist/adapters/postgresAdapter.d.ts +7 -1
- package/dist/adapters/postgresAdapter.d.ts.map +1 -1
- package/dist/adapters/postgresAdapter.js +19 -2
- package/dist/adapters/postgresAdapter.js.map +1 -1
- package/dist/adapters/sqlJsAdapter.d.ts +1 -1
- package/dist/adapters/sqlJsAdapter.d.ts.map +1 -1
- package/dist/adapters/sqlJsAdapter.js +16 -2
- package/dist/adapters/sqlJsAdapter.js.map +1 -1
- package/dist/adapters/supabase.d.ts +3 -3
- package/dist/adapters/supabase.d.ts.map +1 -1
- package/dist/adapters/supabase.js +11 -7
- package/dist/adapters/supabase.js.map +1 -1
- package/dist/agentos/AgentOSStorageAdapter.d.ts +320 -0
- package/dist/agentos/AgentOSStorageAdapter.d.ts.map +1 -0
- package/dist/agentos/AgentOSStorageAdapter.js +406 -0
- package/dist/agentos/AgentOSStorageAdapter.js.map +1 -0
- package/dist/agentos/index.d.ts +7 -0
- package/dist/agentos/index.d.ts.map +1 -0
- package/dist/agentos/index.js +7 -0
- package/dist/agentos/index.js.map +1 -0
- package/dist/{types → core/contracts}/context.d.ts +2 -2
- package/dist/core/contracts/context.d.ts.map +1 -0
- package/dist/core/contracts/context.js.map +1 -0
- package/dist/{types → core/contracts}/events.d.ts +1 -1
- package/dist/core/contracts/events.d.ts.map +1 -0
- package/dist/core/contracts/events.js.map +1 -0
- package/dist/{types → core/contracts}/extensions.d.ts +3 -3
- package/dist/core/contracts/extensions.d.ts.map +1 -0
- package/dist/core/contracts/extensions.js.map +1 -0
- package/dist/{types.d.ts → core/contracts/index.d.ts} +1 -1
- package/dist/core/contracts/index.d.ts.map +1 -0
- package/dist/{types.js → core/contracts/index.js} +1 -1
- package/dist/core/contracts/index.js.map +1 -0
- package/dist/core/contracts/limitations.d.ts.map +1 -0
- package/dist/core/contracts/limitations.js.map +1 -0
- package/dist/{database.d.ts → core/database.d.ts} +16 -3
- package/dist/core/database.d.ts.map +1 -0
- package/dist/{database.js → core/database.js} +39 -8
- package/dist/core/database.js.map +1 -0
- package/dist/{resolver.d.ts → core/resolver.d.ts} +4 -4
- package/dist/core/resolver.d.ts.map +1 -0
- package/dist/{resolver.js → core/resolver.js} +24 -8
- package/dist/core/resolver.js.map +1 -0
- package/dist/{utils → features/backup}/cloudBackup.d.ts +1 -1
- package/dist/features/backup/cloudBackup.d.ts.map +1 -0
- package/dist/{utils → features/backup}/cloudBackup.js +2 -2
- package/dist/features/backup/cloudBackup.js.map +1 -0
- package/dist/{utils → features/migrations}/dataExport.d.ts +1 -1
- package/dist/features/migrations/dataExport.d.ts.map +1 -0
- package/dist/features/migrations/dataExport.js.map +1 -0
- package/dist/{utils → features/migrations}/dataImport.d.ts +1 -1
- package/dist/features/migrations/dataImport.d.ts.map +1 -0
- package/dist/features/migrations/dataImport.js.map +1 -0
- package/dist/{utils → features/migrations}/migration.d.ts +2 -2
- package/dist/features/migrations/migration.d.ts.map +1 -0
- package/dist/{utils → features/migrations}/migration.js +6 -6
- package/dist/features/migrations/migration.js.map +1 -0
- package/dist/{utils → features/sync}/syncManager.d.ts +11 -5
- package/dist/features/sync/syncManager.d.ts.map +1 -0
- package/dist/{utils → features/sync}/syncManager.js +40 -10
- package/dist/features/sync/syncManager.js.map +1 -0
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -19
- package/dist/index.js.map +1 -1
- package/dist/{utils → shared}/parameterUtils.d.ts +1 -1
- package/dist/shared/parameterUtils.d.ts.map +1 -0
- package/dist/shared/parameterUtils.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +22 -6
- package/dist/database.d.ts.map +0 -1
- package/dist/database.js.map +0 -1
- package/dist/resolver.d.ts.map +0 -1
- package/dist/resolver.js.map +0 -1
- package/dist/types/context.d.ts.map +0 -1
- package/dist/types/context.js.map +0 -1
- package/dist/types/events.d.ts.map +0 -1
- package/dist/types/events.js.map +0 -1
- package/dist/types/extensions.d.ts.map +0 -1
- package/dist/types/extensions.js.map +0 -1
- package/dist/types/limitations.d.ts.map +0 -1
- package/dist/types/limitations.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/cloudBackup.d.ts.map +0 -1
- package/dist/utils/cloudBackup.js.map +0 -1
- package/dist/utils/dataExport.d.ts.map +0 -1
- package/dist/utils/dataExport.js.map +0 -1
- package/dist/utils/dataImport.d.ts.map +0 -1
- package/dist/utils/dataImport.js.map +0 -1
- package/dist/utils/migration.d.ts.map +0 -1
- package/dist/utils/migration.js.map +0 -1
- package/dist/utils/parameterUtils.d.ts.map +0 -1
- package/dist/utils/parameterUtils.js.map +0 -1
- package/dist/utils/syncManager.d.ts.map +0 -1
- package/dist/utils/syncManager.js.map +0 -1
- /package/dist/{types → core/contracts}/context.js +0 -0
- /package/dist/{types → core/contracts}/events.js +0 -0
- /package/dist/{types → core/contracts}/extensions.js +0 -0
- /package/dist/{types → core/contracts}/limitations.d.ts +0 -0
- /package/dist/{types → core/contracts}/limitations.js +0 -0
- /package/dist/{utils → features/migrations}/dataExport.js +0 -0
- /package/dist/{utils → features/migrations}/dataImport.js +0 -0
- /package/dist/{utils → shared}/parameterUtils.js +0 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Framers
|
|
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
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Framers
|
|
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
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,363 +1,241 @@
|
|
|
1
|
-
# SQL Storage Adapter
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
#
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await db.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
Auto-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
//
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
- `
|
|
170
|
-
- `
|
|
171
|
-
-
|
|
172
|
-
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
```typescript
|
|
244
|
-
import { connectDatabase } from '@framers/sql-storage-adapter';
|
|
245
|
-
|
|
246
|
-
// Auto-detect from DATABASE_URL
|
|
247
|
-
const db = await connectDatabase(process.env.DATABASE_URL);
|
|
248
|
-
|
|
249
|
-
// Or configure explicitly
|
|
250
|
-
const db = await connectDatabase({
|
|
251
|
-
host: 'db.example.com',
|
|
252
|
-
database: 'myapp',
|
|
253
|
-
user: 'dbuser',
|
|
254
|
-
password: process.env.DB_PASSWORD,
|
|
255
|
-
ssl: true,
|
|
256
|
-
max: 20 // Connection pool size
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// Same API as SQLite!
|
|
260
|
-
const users = await db.all('SELECT * FROM users');
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
📖 **[PostgreSQL Remote Guide](./guides/POSTGRES_REMOTE_CONNECTION.md)** - Cloud provider examples & SSL config
|
|
264
|
-
|
|
265
|
-
## Adapter Comparison
|
|
266
|
-
|
|
267
|
-
| Adapter | Best For | Speed | Size | Concurrent |
|
|
268
|
-
|---------|----------|-------|------|------------|
|
|
269
|
-
| **PostgreSQL** | Production servers | ⚡⚡⚡ | N/A | ✅ Yes |
|
|
270
|
-
| **better-sqlite3** | Desktop apps | ⚡⚡⚡ | 6 MB | ❌ No |
|
|
271
|
-
| **SQL.js** | Browsers | ⚡ | 2.3 MB | ❌ No |
|
|
272
|
-
| **Capacitor** | Mobile apps | ⚡⚡⚡ | ~1 MB | ❌ No |
|
|
273
|
-
|
|
274
|
-
## TypeScript Support
|
|
275
|
-
|
|
276
|
-
Full type safety with generics:
|
|
277
|
-
|
|
278
|
-
```typescript
|
|
279
|
-
interface User {
|
|
280
|
-
id: number;
|
|
281
|
-
name: string;
|
|
282
|
-
email: string;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// Type-safe queries
|
|
286
|
-
const user = await db.get<User>('SELECT * FROM users WHERE id = ?', [1]);
|
|
287
|
-
// user: User | null
|
|
288
|
-
|
|
289
|
-
const users = await db.all<User>('SELECT * FROM users');
|
|
290
|
-
// users: User[]
|
|
291
|
-
|
|
292
|
-
// Runtime introspection
|
|
293
|
-
const context = db.context;
|
|
294
|
-
console.log('Adapter:', db.kind);
|
|
295
|
-
console.log('Capabilities:', Array.from(db.capabilities));
|
|
296
|
-
console.log('Max connections:', context.getLimitations().maxConnections);
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
## Event Monitoring
|
|
300
|
-
|
|
301
|
-
Track queries and performance:
|
|
302
|
-
|
|
303
|
-
```typescript
|
|
304
|
-
db.events.on('query:error', (event) => {
|
|
305
|
-
console.error('Query failed:', event.statement, event.error);
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
db.events.on('performance:slow-query', (event) => {
|
|
309
|
-
if (event.duration > 1000) {
|
|
310
|
-
console.warn(`Slow query (${event.duration}ms):`, event.statement);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
db.events.on('transaction:rollback', (event) => {
|
|
315
|
-
console.warn('Transaction rolled back:', event.error);
|
|
316
|
-
});
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
## Examples
|
|
320
|
-
|
|
321
|
-
Real-world usage in `examples/`:
|
|
322
|
-
- `basic-usage.ts` - Getting started
|
|
323
|
-
- `remote-postgres.ts` - Cloud database connections
|
|
324
|
-
- `electron-app/` - Desktop app with better-sqlite3
|
|
325
|
-
- `browser-extension/` - Chrome extension with SQL.js
|
|
326
|
-
- `full-stack/` - Shared code frontend/backend
|
|
327
|
-
- `offline-sync.ts` - Auto-sync patterns
|
|
328
|
-
- `testing/` - Unit testing strategies
|
|
329
|
-
|
|
330
|
-
## FAQ
|
|
331
|
-
|
|
332
|
-
**Q: Which adapter should I use?**
|
|
333
|
-
Use `createDatabase()` - it auto-picks the best adapter for your environment.
|
|
334
|
-
|
|
335
|
-
**Q: Can I switch adapters later?**
|
|
336
|
-
Yes. Use migration functions to move data between adapters.
|
|
337
|
-
|
|
338
|
-
**Q: Is this production-ready?**
|
|
339
|
-
Yes. Built on battle-tested libraries (pg, better-sqlite3, sql.js). The adapter layer adds <1% overhead.
|
|
340
|
-
|
|
341
|
-
**Q: What about schema migrations?**
|
|
342
|
-
Use any migration tool: [`node-pg-migrate`](https://github.com/salsita/node-pg-migrate), [`prisma`](https://www.prisma.io/), or raw SQL.
|
|
343
|
-
|
|
344
|
-
**Q: How do I handle conflicts in sync?**
|
|
345
|
-
Use `conflictStrategy`: `last-write-wins` (default), `local-wins`, `remote-wins`, `merge`, or `keep-both`.
|
|
346
|
-
|
|
347
|
-
**Q: Can I sync only on WiFi?**
|
|
348
|
-
Yes. Use `mode: 'manual'` and call `sync()` when `isOnWiFi === true`. See [Offline Sync Guide](./guides/OFFLINE_SYNC.md#1-mobile-app-with-wifi-only-sync).
|
|
349
|
-
|
|
350
|
-
## Documentation
|
|
351
|
-
|
|
352
|
-
- **[API Documentation](https://wearetheframers.github.io/sql-storage-adapter/)** - Complete TypeDoc reference
|
|
353
|
-
- **[Offline Sync Guide](./guides/OFFLINE_SYNC.md)** - Comprehensive sync patterns
|
|
354
|
-
- **[PostgreSQL Guide](./guides/POSTGRES_REMOTE_CONNECTION.md)** - Remote database setup
|
|
355
|
-
- **[Architecture](./ARCHITECTURE.md)** - Design decisions
|
|
356
|
-
|
|
357
|
-
## Contributing
|
|
358
|
-
|
|
359
|
-
See [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
360
|
-
|
|
361
|
-
## License
|
|
362
|
-
|
|
363
|
-
MIT © [The Framers](https://frame.dev)
|
|
1
|
+
# SQL Storage Adapter
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://frame.dev" target="_blank" rel="noopener">
|
|
5
|
+
<picture>
|
|
6
|
+
<source media="(prefers-color-scheme: dark)" srcset="./logos/frame-square-blue-dark-no-tagline.svg">
|
|
7
|
+
<source media="(prefers-color-scheme: light)" srcset="./logos/frame-square-blue-no-tagline.svg">
|
|
8
|
+
<img src="./logos/frame-square-blue-no-tagline.svg" alt="Frame.dev" width="200">
|
|
9
|
+
</picture>
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/@framers/sql-storage-adapter)
|
|
14
|
+
[](https://github.com/framersai/sql-storage-adapter/actions/workflows/ci.yml)
|
|
15
|
+
[](https://codecov.io/gh/framersai/sql-storage-adapter)
|
|
16
|
+
[](https://www.typescriptlang.org/)
|
|
17
|
+
[](./LICENSE)
|
|
18
|
+
|
|
19
|
+
> Cross-platform SQL access for Node.js, web, and native runtimes with automatic adapter selection and consistent APIs.
|
|
20
|
+
|
|
21
|
+
The SQL Storage Adapter provides a single, ergonomic interface over SQLite (native and WASM), PostgreSQL, Capacitor, IndexedDB, and in-memory stores. It handles adapter discovery, capability detection, and advanced features like cloud backups so you can focus on your application logic.
|
|
22
|
+
|
|
23
|
+
**🆕 NEW:** Full IndexedDB support for browser-native, offline-first web apps!
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
- [Features](#features)
|
|
28
|
+
- [Installation](#installation)
|
|
29
|
+
- [Quick Start](#quick-start)
|
|
30
|
+
- [AgentOS Integration](#agentos-integration)
|
|
31
|
+
- [Adapter Matrix](#adapter-matrix)
|
|
32
|
+
- [Configuration & Resolution](#configuration--resolution)
|
|
33
|
+
- [Platform Strategy](#platform-strategy)
|
|
34
|
+
- [CI, Releases, and Badges](#ci-releases-and-badges)
|
|
35
|
+
- [Contributing](#contributing)
|
|
36
|
+
- [License](#license)
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **Auto-detected adapters** – `createDatabase()` inspects environment signals and picks the best backend (native SQLite, PostgreSQL, Capacitor, sql.js, **IndexedDB**, memory, etc.).
|
|
41
|
+
- **Capability-aware API** – consistent CRUD, transactions, batching, and event hooks across adapters with runtime capability introspection.
|
|
42
|
+
- **🆕 IndexedDB** – Browser-native persistence with sql.js for full SQL support in PWAs and offline-first apps.
|
|
43
|
+
- **Cloud backups & migrations** – built-in backup manager with compression, retention policies, and restore helpers plus migration utilities.
|
|
44
|
+
- **Portable packaging** – optional native dependencies; falls back to pure TypeScript/WASM adapters when native modules are unavailable.
|
|
45
|
+
- **AgentOS-first** – Pre-configured schema, typed queries, and auto-detection for AgentOS deployments.
|
|
46
|
+
- **CI-first design** – Vitest coverage, Codecov integration, and GitHub Actions workflows for linting, testing, releasing, and npm publish/tag automation.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Core package
|
|
52
|
+
npm install @framers/sql-storage-adapter
|
|
53
|
+
|
|
54
|
+
# Install only the adapters you plan to use
|
|
55
|
+
npm install better-sqlite3 # Native SQLite for Node/Electron
|
|
56
|
+
npm install pg # PostgreSQL
|
|
57
|
+
npm install @capacitor-community/sqlite # Capacitor / mobile
|
|
58
|
+
npm install sql.js # WASM SQLite (auto-included for IndexedDB)
|
|
59
|
+
# IndexedDB uses sql.js (no extra install needed)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
> Windows users: ensure the Visual Studio Build Tools (C++ workload) are installed before adding `better-sqlite3`. On Linux, install `python3`, `build-essential`, and `libssl-dev` prior to `npm install`.
|
|
63
|
+
|
|
64
|
+
> Note: If `better-sqlite3` cannot be required, install native build tools before `npm install`, ensure your Node version matches available prebuilt binaries, or fall back to `sql.js` or `indexeddb` by setting `STORAGE_ADAPTER=sqljs` or `STORAGE_ADAPTER=indexeddb`.
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { createDatabase } from '@framers/sql-storage-adapter';
|
|
70
|
+
|
|
71
|
+
async function main() {
|
|
72
|
+
// Automatically selects the best adapter for the current runtime
|
|
73
|
+
const db = await createDatabase();
|
|
74
|
+
|
|
75
|
+
await db.exec(`
|
|
76
|
+
CREATE TABLE IF NOT EXISTS todos (
|
|
77
|
+
id INTEGER PRIMARY KEY,
|
|
78
|
+
task TEXT NOT NULL,
|
|
79
|
+
done INTEGER DEFAULT 0
|
|
80
|
+
)
|
|
81
|
+
`);
|
|
82
|
+
|
|
83
|
+
await db.run('INSERT INTO todos (task) VALUES (?)', ['Ship cross-platform builds']);
|
|
84
|
+
const items = await db.all<{ id: number; task: string; done: number }>('SELECT * FROM todos');
|
|
85
|
+
console.log(items);
|
|
86
|
+
|
|
87
|
+
await db.close();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
main().catch((error) => {
|
|
91
|
+
console.error('Database bootstrap failed', error);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## AgentOS Integration
|
|
97
|
+
|
|
98
|
+
### Recommended: `createAgentOSStorage()`
|
|
99
|
+
|
|
100
|
+
The easiest way to use sql-storage-adapter with AgentOS is the **AgentOS-first API**:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { createAgentOSStorage } from '@framers/sql-storage-adapter/agentos';
|
|
104
|
+
import { AgentOS } from '@agentos/core';
|
|
105
|
+
|
|
106
|
+
// Auto-detects platform (web, electron, capacitor, node, cloud)
|
|
107
|
+
const storage = await createAgentOSStorage({
|
|
108
|
+
platform: 'auto', // Detects best adapter
|
|
109
|
+
persistence: true,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const agentos = new AgentOS();
|
|
113
|
+
await agentos.initialize({
|
|
114
|
+
storageAdapter: storage.getAdapter(), // 🆕 New field in AgentOSConfig
|
|
115
|
+
// ... other config
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Features:**
|
|
120
|
+
- ✅ Auto-creates AgentOS tables (conversations, sessions, personas, telemetry)
|
|
121
|
+
- ✅ Platform detection (web → IndexedDB, electron → better-sqlite3, etc.)
|
|
122
|
+
- ✅ Typed query builders for common operations
|
|
123
|
+
- ✅ Graceful degradation (e.g., IndexedDB → sql.js fallback)
|
|
124
|
+
|
|
125
|
+
### Platform-Specific Examples
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Web (Browser): Uses IndexedDB
|
|
129
|
+
const webStorage = await createAgentOSStorage({ platform: 'web' });
|
|
130
|
+
|
|
131
|
+
// Desktop (Electron): Uses better-sqlite3
|
|
132
|
+
const desktopStorage = await createAgentOSStorage({ platform: 'electron' });
|
|
133
|
+
|
|
134
|
+
// Mobile (Capacitor): Uses native SQLite
|
|
135
|
+
const mobileStorage = await createAgentOSStorage({ platform: 'capacitor' });
|
|
136
|
+
|
|
137
|
+
// Cloud (Node): Uses PostgreSQL
|
|
138
|
+
const cloudStorage = await createAgentOSStorage({
|
|
139
|
+
platform: 'cloud',
|
|
140
|
+
postgres: { connectionString: process.env.DATABASE_URL }
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
See [Platform Strategy Guide](./docs/PLATFORM_STRATEGY.md) for detailed pros/cons and architecture.
|
|
145
|
+
|
|
146
|
+
## Adapter Matrix
|
|
147
|
+
|
|
148
|
+
| Adapter | Package | Ideal for | Pros | Considerations |
|
|
149
|
+
| --- | --- | --- | --- | --- |
|
|
150
|
+
| **🆕 `indexeddb`** | bundled | **Browsers, PWAs** | Browser-native, async, 50MB-1GB+ quota, SQL via sql.js, offline-first | IndexedDB quotas vary, WASM overhead for SQL |
|
|
151
|
+
| `better-sqlite3` | `better-sqlite3` | Node/Electron, CLI, CI | Native performance, transactional semantics, WAL support | Needs native toolchain; version must match Node ABI |
|
|
152
|
+
| `postgres` | `pg` | Hosted or on-prem PostgreSQL | Connection pooling, rich SQL features, cloud friendly | Requires `DATABASE_URL`/credentials |
|
|
153
|
+
| `sqljs` | bundled | Browsers, serverless edge, native fallback | Pure WASM, no native deps | Write performance limited vs native, optional persistence |
|
|
154
|
+
| `capacitor` | `@capacitor-community/sqlite` | Mobile (iOS/Android, Capacitor) | Native SQLite on mobile, encryption | Requires Capacitor runtime |
|
|
155
|
+
| `memory` | built-in | Unit tests, storybooks, constrained sandboxes | Zero dependencies, instant startup | Non-durable, single-process only |
|
|
156
|
+
|
|
157
|
+
### Platform Priorities
|
|
158
|
+
|
|
159
|
+
| Platform | Primary Adapter | Fallback | Use Case |
|
|
160
|
+
|----------|----------------|----------|----------|
|
|
161
|
+
| **Web (Browser)** | IndexedDB | sql.js | PWAs, offline-first web apps |
|
|
162
|
+
| **Electron (Desktop)** | better-sqlite3 | sql.js | Desktop apps, dev tools |
|
|
163
|
+
| **Capacitor (Mobile)** | capacitor | IndexedDB | iOS/Android native apps |
|
|
164
|
+
| **Node.js** | better-sqlite3 | Postgres, sql.js | CLI tools, local servers |
|
|
165
|
+
| **Cloud (Serverless)** | Postgres | better-sqlite3 | Multi-tenant SaaS, APIs |
|
|
166
|
+
|
|
167
|
+
## Configuration & Resolution
|
|
168
|
+
|
|
169
|
+
- `resolveStorageAdapter` inspects:
|
|
170
|
+
- explicit options (`priority`, `type`, adapter configs),
|
|
171
|
+
- environment variables (`STORAGE_ADAPTER`, `DATABASE_URL`),
|
|
172
|
+
- runtime hints (Capacitor detection, browser globals, IndexedDB availability).
|
|
173
|
+
- Adapters are attempted in priority order until one opens successfully; a `StorageResolutionError` includes the full failure chain.
|
|
174
|
+
- Provide `priority: ['indexeddb', 'sqljs']` for browser bundles or tests where native modules shouldn't load.
|
|
175
|
+
- Use `createCloudBackupManager` for S3-compatible backups with gzip compression and retention limits.
|
|
176
|
+
|
|
177
|
+
### IndexedDB-Specific Config
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { IndexedDbAdapter } from '@framers/sql-storage-adapter';
|
|
181
|
+
|
|
182
|
+
const adapter = new IndexedDbAdapter({
|
|
183
|
+
dbName: 'my-app-db', // IndexedDB database name
|
|
184
|
+
storeName: 'sqliteDb', // Object store name
|
|
185
|
+
autoSave: true, // Auto-save to IndexedDB after writes
|
|
186
|
+
saveIntervalMs: 5000, // Batch writes every 5s
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
await adapter.open();
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Key Features:**
|
|
193
|
+
- ✅ Transactions (via sql.js)
|
|
194
|
+
- ✅ Persistence (IndexedDB)
|
|
195
|
+
- ✅ Export/import (Uint8Array SQLite file format)
|
|
196
|
+
- ✅ Auto-save with batching (reduce IDB overhead)
|
|
197
|
+
|
|
198
|
+
## Platform Strategy
|
|
199
|
+
|
|
200
|
+
See [**PLATFORM_STRATEGY.md**](./docs/PLATFORM_STRATEGY.md) for a comprehensive guide on:
|
|
201
|
+
- Graceful degradation patterns
|
|
202
|
+
- Platform-specific pros/cons
|
|
203
|
+
- Performance benchmarks
|
|
204
|
+
- Offline-first architectures
|
|
205
|
+
- AgentOS-specific recommendations
|
|
206
|
+
|
|
207
|
+
**TL;DR:** Use IndexedDB for web, better-sqlite3 for desktop, capacitor for mobile, Postgres for cloud.
|
|
208
|
+
|
|
209
|
+
## CI, Releases, and Badges
|
|
210
|
+
|
|
211
|
+
- GitHub Actions workflows:
|
|
212
|
+
- `ci.yml` runs lint, tests, and coverage on every branch.
|
|
213
|
+
- `release.yml` publishes new versions to npm, tags the commit (`vX.Y.Z`), and creates/updates the GitHub Release when `CHANGELOG.md` and `package.json` bump the version.
|
|
214
|
+
- Check badge health whenever builds fail:
|
|
215
|
+
- CI badge should be green for `master`.
|
|
216
|
+
- Codecov badge updates after coverage reports upload.
|
|
217
|
+
- npm badge reflects the latest published version.
|
|
218
|
+
- Manual verification commands:
|
|
219
|
+
```bash
|
|
220
|
+
npm info @framers/sql-storage-adapter version
|
|
221
|
+
pnpm --filter sql-storage-adapter test
|
|
222
|
+
pnpm --filter sql-storage-adapter build
|
|
223
|
+
```
|
|
224
|
+
- See [RELEASING.md](./RELEASING.md) for the automated release flow, required secrets (`NPM_TOKEN`), and manual fallback steps.
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
## Contributing
|
|
229
|
+
|
|
230
|
+
- Read [CONTRIBUTING.md](./CONTRIBUTING.md) for coding standards, lint/test commands, and pull request guidelines.
|
|
231
|
+
- Architecture notes live in [ARCHITECTURE.md](./ARCHITECTURE.md); API docs can be regenerated with `pnpm --filter sql-storage-adapter run docs`.
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
[MIT](./LICENSE)
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
<p align="center">
|
|
240
|
+
Built and maintained by <a href="https://frame.dev" target="_blank" rel="noopener">Frame.dev</a>
|
|
241
|
+
</p>
|