@quereus/plugin-indexeddb 0.2.2
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/README.md +127 -0
- package/package.json +88 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @quereus/plugin-indexeddb
|
|
2
|
+
|
|
3
|
+
IndexedDB storage plugin for Quereus. Provides persistent storage for browser environments using the [`@quereus/store`](../quereus-store/) module.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Browser-native**: Uses IndexedDB for reliable persistent storage
|
|
8
|
+
- **Cross-tab sync**: BroadcastChannel-based synchronization across browser tabs
|
|
9
|
+
- **Async iteration**: Efficient range queries with cursor-based iteration
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @quereus/plugin-indexeddb @quereus/store
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### With registerPlugin (Recommended)
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Database, registerPlugin } from '@quereus/quereus';
|
|
23
|
+
import indexeddbPlugin from '@quereus/plugin-indexeddb/plugin';
|
|
24
|
+
|
|
25
|
+
const db = new Database();
|
|
26
|
+
await registerPlugin(db, indexeddbPlugin, { prefix: 'myapp' });
|
|
27
|
+
|
|
28
|
+
await db.exec(`create table users (id integer primary key, name text) using store`);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Direct Usage with Provider
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { Database } from '@quereus/quereus';
|
|
35
|
+
import { createIndexedDBProvider } from '@quereus/plugin-indexeddb';
|
|
36
|
+
import { StoreModule } from '@quereus/store';
|
|
37
|
+
|
|
38
|
+
const db = new Database();
|
|
39
|
+
const provider = createIndexedDBProvider({ prefix: 'myapp' });
|
|
40
|
+
const storeModule = new StoreModule(provider);
|
|
41
|
+
db.registerVtabModule('store', storeModule);
|
|
42
|
+
|
|
43
|
+
await db.exec(`create table users (id integer primary key, name text) using store`);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API
|
|
47
|
+
|
|
48
|
+
### IndexedDBStore
|
|
49
|
+
|
|
50
|
+
Low-level KVStore implementation:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { IndexedDBStore } from '@quereus/plugin-indexeddb';
|
|
54
|
+
|
|
55
|
+
const store = await IndexedDBStore.open({ path: 'myapp_main_users' });
|
|
56
|
+
|
|
57
|
+
await store.put(key, value);
|
|
58
|
+
const data = await store.get(key);
|
|
59
|
+
await store.delete(key);
|
|
60
|
+
|
|
61
|
+
// Range iteration
|
|
62
|
+
for await (const { key, value } of store.iterate({ gte: startKey, lt: endKey })) {
|
|
63
|
+
console.log(key, value);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
await store.close();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### IndexedDBProvider
|
|
70
|
+
|
|
71
|
+
Factory for managing multiple stores:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { createIndexedDBProvider } from '@quereus/plugin-indexeddb';
|
|
75
|
+
|
|
76
|
+
const provider = createIndexedDBProvider({ prefix: 'myapp' });
|
|
77
|
+
|
|
78
|
+
const userStore = await provider.getStore('main', 'users');
|
|
79
|
+
const catalogStore = await provider.getCatalogStore();
|
|
80
|
+
|
|
81
|
+
await provider.closeAll();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### CrossTabSync
|
|
85
|
+
|
|
86
|
+
Synchronize changes across browser tabs:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { CrossTabSync } from '@quereus/plugin-indexeddb';
|
|
90
|
+
|
|
91
|
+
const sync = new CrossTabSync('myapp');
|
|
92
|
+
|
|
93
|
+
sync.onDataChange((event) => {
|
|
94
|
+
console.log('Tab change:', event.storeName, event.type, event.key);
|
|
95
|
+
refreshUI();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Broadcast a change to other tabs
|
|
99
|
+
sync.notifyDataChange('main.users', 'put', key);
|
|
100
|
+
|
|
101
|
+
sync.close();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Configuration
|
|
105
|
+
|
|
106
|
+
### Plugin Settings
|
|
107
|
+
|
|
108
|
+
| Setting | Type | Default | Description |
|
|
109
|
+
|---------|------|---------|-------------|
|
|
110
|
+
| `prefix` | string | `'quereus'` | Prefix for IndexedDB database names |
|
|
111
|
+
| `moduleName` | string | `'store'` | Name to register the virtual table module under |
|
|
112
|
+
|
|
113
|
+
### IndexedDBProvider Options
|
|
114
|
+
|
|
115
|
+
| Option | Type | Default | Description |
|
|
116
|
+
|--------|------|---------|-------------|
|
|
117
|
+
| `prefix` | string | `'quereus'` | Prefix for database names: `${prefix}_${schema}_${table}` |
|
|
118
|
+
|
|
119
|
+
## Related Packages
|
|
120
|
+
|
|
121
|
+
- [`@quereus/store`](../quereus-store/) - Core storage module (StoreModule, StoreTable)
|
|
122
|
+
- [`@quereus/plugin-leveldb`](../quereus-plugin-leveldb/) - LevelDB plugin for Node.js
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
127
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quereus/plugin-indexeddb",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "IndexedDB storage plugin for Quereus - browser persistent storage",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"quereus",
|
|
8
|
+
"quereus-plugin",
|
|
9
|
+
"sql",
|
|
10
|
+
"database",
|
|
11
|
+
"storage",
|
|
12
|
+
"indexeddb",
|
|
13
|
+
"kv-store",
|
|
14
|
+
"browser",
|
|
15
|
+
"persistent"
|
|
16
|
+
],
|
|
17
|
+
"publisher": "Got Choices Foundation",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/gotchoices/quereus.git",
|
|
21
|
+
"directory": "packages/quereus-plugin-indexeddb"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"main": "dist/src/index.js",
|
|
25
|
+
"types": "./dist/src/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"!**/*.tsbuildinfo"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/src/index.d.ts",
|
|
33
|
+
"import": "./dist/src/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./plugin": {
|
|
36
|
+
"types": "./dist/src/plugin.d.ts",
|
|
37
|
+
"import": "./dist/src/plugin.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@quereus/quereus": "^0.24.0",
|
|
42
|
+
"@quereus/store": "^0.3.5"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"quereus": "^0.24.0"
|
|
46
|
+
},
|
|
47
|
+
"quereus": {
|
|
48
|
+
"provides": {
|
|
49
|
+
"vtables": [
|
|
50
|
+
"store"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"settings": [
|
|
54
|
+
{
|
|
55
|
+
"key": "prefix",
|
|
56
|
+
"label": "Database Prefix",
|
|
57
|
+
"type": "string",
|
|
58
|
+
"default": "quereus",
|
|
59
|
+
"help": "Prefix for IndexedDB database names"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"key": "moduleName",
|
|
63
|
+
"label": "Module Name",
|
|
64
|
+
"type": "string",
|
|
65
|
+
"default": "store",
|
|
66
|
+
"help": "Name to register the virtual table module under"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"clean": "rimraf dist",
|
|
72
|
+
"build": "tsc",
|
|
73
|
+
"typecheck": "tsc --noEmit",
|
|
74
|
+
"test": "cd ../.. && node --import ./packages/quereus-plugin-indexeddb/register.mjs node_modules/mocha/bin/mocha.js \"packages/quereus-plugin-indexeddb/test/**/*.spec.ts\" --colors"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@quereus/quereus": "*",
|
|
78
|
+
"@quereus/store": "*",
|
|
79
|
+
"@types/chai": "^5.2.2",
|
|
80
|
+
"@types/mocha": "^10.0.10",
|
|
81
|
+
"chai": "^5.2.0",
|
|
82
|
+
"fake-indexeddb": "^6.0.0",
|
|
83
|
+
"mocha": "^11.1.0",
|
|
84
|
+
"rimraf": "^6.1.2",
|
|
85
|
+
"ts-node": "^10.9.2",
|
|
86
|
+
"typescript": "^5.8.3"
|
|
87
|
+
}
|
|
88
|
+
}
|