Skip to content

Commit 88796bb

Browse files
committed
docs: clarify indexeddb adapter architecture and add json/prepared capabilities
- Updated all docs to clarify IndexedDB adapter is sql.js + IndexedDB persistence wrapper - Added 'json' and 'prepared' capabilities to IndexedDB and sql.js adapters - Updated README, PLATFORM_STRATEGY, and ARCHITECTURE docs - Version bump to 0.3.2
1 parent 2e81d76 commit 88796bb

File tree

7 files changed

+68
-24
lines changed

7 files changed

+68
-24
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.3.2] - 2025-11-07
9+
10+
### Changed
11+
- **Documentation clarifications**: Updated all docs to clarify that IndexedDB adapter is sql.js + IndexedDB persistence wrapper (not a separate SQL engine)
12+
- **Capability updates**: Added `json` and `prepared` capabilities to IndexedDB and sql.js adapters
13+
- Both adapters now correctly declare JSON support (via SQLite JSON1 extension)
14+
- Prepared statements capability added for both adapters
15+
- **README updates**: Clarified IndexedDB adapter relationship with sql.js throughout documentation
16+
17+
### Documentation
18+
- Updated README.md adapter matrix to clarify IndexedDB is sql.js wrapper
19+
- Updated PLATFORM_STRATEGY.md with detailed explanation of IndexedDB + sql.js architecture
20+
- Updated ARCHITECTURE.md to note IndexedDB adapter is not a separate SQL engine
21+
- Added notes about JSON support via SQLite JSON1 extension for IndexedDB/sql.js adapters
22+
823
## [0.3.0] - 2025-11-06
924

1025
### Added
11-
- **IndexedDB Adapter** (`IndexedDbAdapter`) - Browser-native SQL storage using IndexedDB with sql.js for full client-side operation
26+
- **IndexedDB Adapter** (`IndexedDbAdapter`) - sql.js + IndexedDB persistence wrapper for browser-native SQL storage
27+
- **Note**: This adapter uses sql.js (WASM SQLite) for all SQL execution and IndexedDB only for storing the database file as a binary blob
1228
- Automatic persistence to IndexedDB with configurable auto-save intervals
1329
- Full SQL support via sql.js (SQLite compiled to WebAssembly)
1430
- Export/import functionality for data portability

PLATFORM_STRATEGY.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ const storage = await createAgentOSStorage({
2020

2121
| Adapter | Pros | Cons | Best For |
2222
|---------|------|------|----------|
23-
| **IndexedDB** (NEW) | ✅ Native browser API<br>✅ Async, non-blocking<br>✅ 50MB-1GB+ quota<br>✅ Structured transactions<br>✅ No WASM overhead |Complex API (wrapped by sql.js)<br>❌ IndexedDB quotas vary by browser<br>❌ No SQL queries (need sql.js layer) | **Primary choice** for web<br>Offline PWAs<br>Privacy-first apps |
23+
| **IndexedDB** (NEW) | ✅ Native browser storage API<br>✅ Async, non-blocking<br>✅ 50MB-1GB+ quota<br>✅ sql.js wrapper (full SQL support)<br>✅ Persistent across sessions |Uses sql.js WASM (500KB load)<br>❌ IndexedDB quotas vary by browser<br>❌ Not a separate SQL engine (sql.js + IDB persistence) | **Primary choice** for web<br>Offline PWAs<br>Privacy-first apps |
2424
| **sql.js** | ✅ Full SQLite in WASM<br>✅ In-memory fast reads<br>✅ Optional IDB persistence<br>✅ Zero dependencies | ❌ 500KB WASM load<br>❌ Slow writes to IDB<br>❌ Single-threaded | Fallback for web<br>Edge functions |
2525
| **LocalStorage** | ✅ 5-10MB simple API | ❌ Synchronous (blocks UI)<br>❌ String-only<br>❌ No transactions |**NOT RECOMMENDED** |
2626

27-
**Winner:** **IndexedDB + sql.js** (our new IndexedDbAdapter)
28-
- Best of both: native IDB durability + SQL convenience
27+
**Winner:** **IndexedDB adapter** (sql.js + IndexedDB persistence wrapper)
28+
- sql.js provides SQL execution (WASM SQLite)
29+
- IndexedDB provides browser-native persistence (stores SQLite file as blob)
2930
- Auto-save batching minimizes IDB overhead
3031
- Works offline, respects privacy
32+
- **Note:** This is sql.js with IndexedDB persistence, not a separate SQL engine
3133

3234
---
3335

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The SQL Storage Adapter provides a single, ergonomic interface over SQLite (nati
3737

3838
- **Auto-detected adapters**`createDatabase()` inspects environment signals and picks the best backend (native SQLite, PostgreSQL, Capacitor, sql.js, **IndexedDB**, memory, etc.).
3939
- **Capability-aware API** – consistent CRUD, transactions, batching, and event hooks across adapters with runtime capability introspection.
40-
- **🆕 IndexedDB**Browser-native persistence with sql.js for full SQL support in PWAs and offline-first apps.
40+
- **🆕 IndexedDB**sql.js + IndexedDB persistence wrapper for browser-native, offline-first web apps (uses sql.js for SQL execution, IndexedDB for storage).
4141
- **Cloud backups & migrations** – built-in backup manager with compression, retention policies, and restore helpers plus migration utilities.
4242
- **Portable packaging** – optional native dependencies; falls back to pure TypeScript/WASM adapters when native modules are unavailable.
4343
- **AgentOS-first** – Pre-configured schema, typed queries, and auto-detection for AgentOS deployments.
@@ -145,10 +145,10 @@ See [Platform Strategy Guide](./PLATFORM_STRATEGY.md) for detailed pros/cons and
145145

146146
| Adapter | Package | Ideal for | Pros | Considerations |
147147
| --- | --- | --- | --- | --- |
148-
| **🆕 `indexeddb`** | bundled | **Browsers, PWAs** | Browser-native, async, 50MB-1GB+ quota, SQL via sql.js, offline-first | IndexedDB quotas vary, WASM overhead for SQL |
148+
| **🆕 `indexeddb`** | bundled (sql.js) | **Browsers, PWAs** | sql.js + IndexedDB persistence wrapper, browser-native storage, 50MB-1GB+ quota, offline-first | IndexedDB quotas vary, WASM overhead (sql.js), not a separate SQL engine |
149149
| `better-sqlite3` | `better-sqlite3` | Node/Electron, CLI, CI | Native performance, transactional semantics, WAL support | Needs native toolchain; version must match Node ABI |
150150
| `postgres` | `pg` | Hosted or on-prem PostgreSQL | Connection pooling, rich SQL features, cloud friendly | Requires `DATABASE_URL`/credentials |
151-
| `sqljs` | bundled | Browsers, serverless edge, native fallback | Pure WASM, no native deps | Write performance limited vs native, optional persistence |
151+
| `sqljs` | bundled | Browsers, serverless edge, native fallback | Pure WASM SQLite, no native deps, optional filesystem persistence | Write performance limited vs native, in-memory by default |
152152
| `capacitor` | `@capacitor-community/sqlite` | Mobile (iOS/Android, Capacitor) | Native SQLite on mobile, encryption | Requires Capacitor runtime |
153153
| `memory` | built-in | Unit tests, storybooks, constrained sandboxes | Zero dependencies, instant startup | Non-durable, single-process only |
154154

@@ -188,11 +188,15 @@ await adapter.open();
188188
```
189189

190190
**Key Features:**
191-
- ✅ Transactions (via sql.js)
192-
- ✅ Persistence (IndexedDB)
191+
- ✅ SQL execution via sql.js (WASM SQLite)
192+
- ✅ Persistence via IndexedDB (stores SQLite database file as blob)
193+
- ✅ JSON support (SQLite JSON1 extension: json_extract, json_object, json_array, etc.)
194+
- ✅ Prepared statements for performance and security
193195
- ✅ Export/import (Uint8Array SQLite file format)
194196
- ✅ Auto-save with batching (reduce IDB overhead)
195197

198+
**Note:** IndexedDB adapter is a wrapper around sql.js that adds IndexedDB persistence. It's not a separate SQL engine—it uses sql.js for all SQL operations and IndexedDB only for storing the database file. Since sql.js is full SQLite WASM, it supports all SQLite features including JSON functions, BLOBs, and full-text search.
199+
196200
## Platform Strategy
197201

198202
See [**PLATFORM_STRATEGY.md**](./PLATFORM_STRATEGY.md) for a comprehensive guide on:

docs/media/ARCHITECTURE.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ const db = await resolveStorageAdapter({
115115

116116
### IndexedDB Adapter (Browser-Native)
117117

118-
**Implementation**: sql.js (SQLite WASM) + IndexedDB for persistence
118+
**Implementation**: sql.js (SQLite WASM) + IndexedDB persistence wrapper
119+
120+
**Important**: This adapter is **not a separate SQL engine**. It uses sql.js for all SQL execution and IndexedDB only for storing the SQLite database file as a binary blob. Think of it as "sql.js with automatic IndexedDB persistence."
119121

120122
**When to use**:
121123
- **Browser applications** (primary use case)
@@ -247,13 +249,14 @@ const backup = adapter.exportDatabase(); // Uint8Array (SQLite file)
247249

248250
| Feature | IndexedDB Adapter | SQL.js Adapter |
249251
|---------|------------------|----------------|
250-
| **Persistence** | ✅ Automatic | ⚠️ Manual (`save()` required) |
252+
| **SQL Engine** | sql.js (WASM) | sql.js (WASM) |
253+
| **Persistence** | ✅ Automatic (IndexedDB) | ⚠️ Manual (`save()` required) |
251254
| **Auto-save** | ✅ Yes (batched) | ❌ No |
252255
| **Bundle Size** | Same (~500KB) | Same (~500KB) |
253256
| **Performance** | Same (both use sql.js) | Same |
254257
| **Use Case** | Production web apps | Prototyping, edge functions |
255258

256-
**Recommendation**: Use **IndexedDB Adapter** for production web apps (automatic persistence). Use **SQL.js Adapter** only if you need manual control over save timing.
259+
**Key Difference**: IndexedDB adapter is sql.js + automatic IndexedDB persistence wrapper. SQL.js adapter is sql.js with optional manual persistence. Both use the same SQL engine (sql.js).
257260

258261
**Configuration**:
259262
```typescript

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@framers/sql-storage-adapter",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "Robust cross-platform SQL storage abstraction with automatic fallbacks and runtime detection",
55
"type": "module",
66
"main": "dist/index.js",

src/adapters/indexedDbAdapter.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
/**
22
* @fileoverview IndexedDB Storage Adapter for AgentOS
3-
* @description Browser-native SQL storage using IndexedDB with sql.js for full client-side operation.
4-
* Supports transactions, persistence to IndexedDB, and offline-first workflows.
3+
* @description Browser-native SQL storage using sql.js (WASM) for SQL execution and IndexedDB for persistence.
4+
*
5+
* **Architecture:**
6+
* - **SQL Execution**: Uses sql.js (SQLite compiled to WebAssembly) for full SQL support
7+
* - **Persistence**: Stores the SQLite database file (as binary blob) in IndexedDB
8+
* - **Workflow**: Load DB from IndexedDB → Execute SQL in memory (sql.js) → Save back to IndexedDB
9+
*
10+
* **Why this approach?**
11+
* - IndexedDB is NOT SQL - it's a NoSQL key-value store
12+
* - sql.js provides full SQLite compatibility (transactions, joins, etc.)
13+
* - IndexedDB provides durable browser-native persistence
14+
* - Together: Full SQL capabilities + browser persistence = best of both worlds
515
*
616
* **Use cases:**
717
* - Fully client-side AgentOS (no backend needed)
818
* - Progressive Web Apps (PWAs)
919
* - Offline-capable agents
1020
* - Privacy-first applications (data never leaves browser)
1121
*
12-
* **Architecture:**
13-
* - Uses sql.js (SQLite compiled to WebAssembly) for SQL execution
14-
* - Persists database to IndexedDB for durability across sessions
15-
* - Auto-saves after each transaction
16-
* - Supports import/export for data portability
22+
* **Performance:**
23+
* - Fast reads (in-memory SQL via sql.js)
24+
* - Moderate writes (IndexedDB persistence adds ~10-50ms)
25+
* - Auto-save batching reduces IDB overhead
1726
*
1827
* @example
1928
* ```typescript
@@ -67,9 +76,19 @@ const DB_VERSION = 1;
6776
/**
6877
* Storage adapter using IndexedDB + sql.js for client-side SQL persistence.
6978
*
79+
* **How It Works:**
80+
* 1. IndexedDB stores the SQLite database file (binary blob) - this is just storage
81+
* 2. sql.js (WASM) loads the database into memory and executes SQL - this provides SQL capabilities
82+
* 3. After writes, the updated database is saved back to IndexedDB
83+
*
84+
* **Why IndexedDB + sql.js?**
85+
* - IndexedDB alone: NoSQL key-value store, no SQL support
86+
* - sql.js alone: In-memory SQL, but no persistence across sessions
87+
* - Combined: Full SQL + browser-native persistence = complete solution
88+
*
7089
* **Capabilities:**
71-
* - ✅ Transactions
72-
* - ✅ Persistence (IndexedDB)
90+
* - ✅ Transactions (via sql.js)
91+
* - ✅ Persistence (via IndexedDB)
7392
* - ✅ Full SQL support (via sql.js)
7493
* - ✅ Export/import
7594
* - ❌ Concurrent writes (single-threaded)
@@ -92,7 +111,7 @@ const DB_VERSION = 1;
92111
*/
93112
export class IndexedDbAdapter implements StorageAdapter {
94113
public readonly kind = 'indexeddb';
95-
public readonly capabilities: ReadonlySet<StorageCapability> = new Set(['transactions', 'persistence']);
114+
public readonly capabilities: ReadonlySet<StorageCapability> = new Set(['transactions', 'persistence', 'json', 'prepared']);
96115

97116
private SQL: SqlJsStatic | null = null;
98117
private db: SqlJsDatabase | null = null;

src/adapters/sqlJsAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class SqlJsAdapter implements StorageAdapter {
3737
private filePath?: string;
3838

3939
constructor(private readonly adapterOptions: SqlJsAdapterOptions = {}) {
40-
const caps: StorageCapability[] = ['transactions'];
40+
const caps: StorageCapability[] = ['transactions', 'json', 'prepared'];
4141
if (hasFsAccess()) {
4242
caps.push('persistence');
4343
}

0 commit comments

Comments
 (0)