@quereus/store 0.3.6
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 +179 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# @quereus/store
|
|
2
|
+
|
|
3
|
+
Abstract key-value storage module for [Quereus](https://github.com/gotchoices/quereus). Provides platform-agnostic interfaces and a generic `StoreModule` virtual table implementation.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
This package provides the **abstract layer** that separates virtual table logic from platform-specific storage:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
@quereus/store (this package)
|
|
11
|
+
├── KVStore interface - Abstract key-value store
|
|
12
|
+
├── KVStoreProvider interface - Store factory/management
|
|
13
|
+
├── StoreModule - Generic VirtualTableModule
|
|
14
|
+
├── StoreTable - Generic virtual table implementation
|
|
15
|
+
├── StoreConnection - Generic transaction support
|
|
16
|
+
└── Common utilities - Encoding, serialization, events
|
|
17
|
+
|
|
18
|
+
@quereus/plugin-leveldb (Node.js) @quereus/plugin-indexeddb (Browser)
|
|
19
|
+
├── LevelDBStore ├── IndexedDBStore
|
|
20
|
+
├── LevelDBProvider ├── IndexedDBProvider
|
|
21
|
+
└── Plugin registration ├── IndexedDBManager
|
|
22
|
+
└── CrossTabSync
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This architecture enables:
|
|
26
|
+
- **Platform portability** - Same SQL tables work across Node.js, browsers, and mobile
|
|
27
|
+
- **Custom storage backends** - Implement `KVStore` for SQLite, LMDB, or cloud storage
|
|
28
|
+
- **Dependency injection** - Use `KVStoreProvider` for store management
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @quereus/store
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For platform-specific implementations:
|
|
37
|
+
```bash
|
|
38
|
+
# Node.js
|
|
39
|
+
npm install @quereus/plugin-leveldb
|
|
40
|
+
|
|
41
|
+
# Browser
|
|
42
|
+
npm install @quereus/plugin-indexeddb
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
### With a Provider
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { Database } from '@quereus/quereus';
|
|
51
|
+
import { StoreModule } from '@quereus/store';
|
|
52
|
+
import { createLevelDBProvider } from '@quereus/plugin-leveldb';
|
|
53
|
+
// OR: import { createIndexedDBProvider } from '@quereus/plugin-indexeddb';
|
|
54
|
+
|
|
55
|
+
const db = new Database();
|
|
56
|
+
|
|
57
|
+
// Create provider for your platform
|
|
58
|
+
const provider = createLevelDBProvider({ basePath: './data' });
|
|
59
|
+
|
|
60
|
+
// Create the generic store module with your provider
|
|
61
|
+
const storeModule = new StoreModule(provider);
|
|
62
|
+
db.registerVtabModule('store', storeModule);
|
|
63
|
+
|
|
64
|
+
// Use it in SQL
|
|
65
|
+
await db.exec(`
|
|
66
|
+
create table users (id integer primary key, name text)
|
|
67
|
+
using store
|
|
68
|
+
`);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Custom Storage Backend
|
|
72
|
+
|
|
73
|
+
Implement `KVStore` and `KVStoreProvider` to create custom storage backends:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import type { KVStore, KVStoreProvider } from '@quereus/store';
|
|
77
|
+
|
|
78
|
+
class MyCustomStore implements KVStore {
|
|
79
|
+
async get(key: Uint8Array) { /* ... */ }
|
|
80
|
+
async put(key: Uint8Array, value: Uint8Array) { /* ... */ }
|
|
81
|
+
async delete(key: Uint8Array) { /* ... */ }
|
|
82
|
+
async has(key: Uint8Array) { /* ... */ }
|
|
83
|
+
iterate(options?: IterateOptions) { /* ... */ }
|
|
84
|
+
batch() { /* ... */ }
|
|
85
|
+
async close() { /* ... */ }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class MyCustomProvider implements KVStoreProvider {
|
|
89
|
+
async getStore(schemaName: string, tableName: string) {
|
|
90
|
+
return new MyCustomStore(/* ... */);
|
|
91
|
+
}
|
|
92
|
+
async getCatalogStore() { /* ... */ }
|
|
93
|
+
async closeStore(schemaName: string, tableName: string) { /* ... */ }
|
|
94
|
+
async closeAll() { /* ... */ }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Use it with StoreModule
|
|
98
|
+
const provider = new MyCustomProvider();
|
|
99
|
+
const module = new StoreModule(provider);
|
|
100
|
+
db.registerVtabModule('store', module);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## KVStore Interface
|
|
104
|
+
|
|
105
|
+
The `KVStore` interface is the foundation for all storage backends:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
interface KVStore {
|
|
109
|
+
get(key: Uint8Array): Promise<Uint8Array | undefined>;
|
|
110
|
+
put(key: Uint8Array, value: Uint8Array): Promise<void>;
|
|
111
|
+
delete(key: Uint8Array): Promise<void>;
|
|
112
|
+
has(key: Uint8Array): Promise<boolean>;
|
|
113
|
+
iterate(options?: IterateOptions): AsyncIterable<KVEntry>;
|
|
114
|
+
batch(): WriteBatch;
|
|
115
|
+
close(): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface KVStoreProvider {
|
|
119
|
+
getStore(schemaName: string, tableName: string): Promise<KVStore>;
|
|
120
|
+
getCatalogStore(): Promise<KVStore>;
|
|
121
|
+
closeStore(schemaName: string, tableName: string): Promise<void>;
|
|
122
|
+
closeAll(): Promise<void>;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## API
|
|
127
|
+
|
|
128
|
+
### Core Exports
|
|
129
|
+
|
|
130
|
+
| Export | Description |
|
|
131
|
+
|--------|-------------|
|
|
132
|
+
| `KVStore` | Key-value store interface (type) |
|
|
133
|
+
| `KVStoreProvider` | Store factory interface (type) |
|
|
134
|
+
| `WriteBatch` | Batch write interface (type) |
|
|
135
|
+
| `IterateOptions` | Iteration options (type) |
|
|
136
|
+
| `StoreModule` | Generic VirtualTableModule |
|
|
137
|
+
| `StoreTable` | Virtual table implementation |
|
|
138
|
+
| `StoreConnection` | Transaction connection |
|
|
139
|
+
| `TransactionCoordinator` | Transaction management |
|
|
140
|
+
| `StoreEventEmitter` | Event system for data/schema changes |
|
|
141
|
+
|
|
142
|
+
### Encoding Utilities
|
|
143
|
+
|
|
144
|
+
| Export | Description |
|
|
145
|
+
|--------|-------------|
|
|
146
|
+
| `encodeValue` | Encode a SQL value to sortable bytes |
|
|
147
|
+
| `decodeValue` | Decode bytes back to SQL value |
|
|
148
|
+
| `encodeCompositeKey` | Encode multiple values as composite key |
|
|
149
|
+
| `decodeCompositeKey` | Decode composite key to values |
|
|
150
|
+
| `registerCollationEncoder` | Register custom collation |
|
|
151
|
+
|
|
152
|
+
### Serialization Utilities
|
|
153
|
+
|
|
154
|
+
| Export | Description |
|
|
155
|
+
|--------|-------------|
|
|
156
|
+
| `serializeRow` | Serialize a row to bytes |
|
|
157
|
+
| `deserializeRow` | Deserialize bytes to row |
|
|
158
|
+
| `serializeValue` | Serialize a single value |
|
|
159
|
+
| `deserializeValue` | Deserialize a single value |
|
|
160
|
+
|
|
161
|
+
### Key Building
|
|
162
|
+
|
|
163
|
+
| Export | Description |
|
|
164
|
+
|--------|-------------|
|
|
165
|
+
| `buildDataKey` | Build key for row data |
|
|
166
|
+
| `buildIndexKey` | Build key for index entry |
|
|
167
|
+
| `buildMetaKey` | Build key for metadata |
|
|
168
|
+
| `buildTableScanBounds` | Build bounds for table scan |
|
|
169
|
+
|
|
170
|
+
## Related Packages
|
|
171
|
+
|
|
172
|
+
- [`@quereus/plugin-leveldb`](../quereus-plugin-leveldb/) - LevelDB implementation for Node.js
|
|
173
|
+
- [`@quereus/plugin-indexeddb`](../quereus-plugin-indexeddb/) - IndexedDB implementation for browsers
|
|
174
|
+
- [`@quereus/plugin-sync`](../quereus-plugin-sync/) - CRDT sync layer
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT
|
|
179
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quereus/store",
|
|
3
|
+
"version": "0.3.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Abstract key-value storage module for Quereus",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"quereus",
|
|
8
|
+
"sql",
|
|
9
|
+
"database",
|
|
10
|
+
"storage",
|
|
11
|
+
"kv-store",
|
|
12
|
+
"persistent",
|
|
13
|
+
"virtual-table",
|
|
14
|
+
"abstract"
|
|
15
|
+
],
|
|
16
|
+
"publisher": "Got Choices Foundation",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/gotchoices/quereus.git",
|
|
20
|
+
"directory": "packages/quereus-store"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"main": "dist/src/index.js",
|
|
24
|
+
"types": "./dist/src/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"!**/*.tsbuildinfo"
|
|
28
|
+
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/src/index.d.ts",
|
|
32
|
+
"import": "./dist/src/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"clean": "rimraf dist",
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"test": "cd ../.. && node --import ./packages/quereus-store/register.mjs node_modules/mocha/bin/mocha.js \"packages/quereus-store/test/**/*.spec.ts\" --colors",
|
|
40
|
+
"test:single": "cd ../.. && node --import ./packages/quereus-store/register.mjs node_modules/mocha/bin/mocha.js --bail"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@quereus/quereus": "*"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@quereus/quereus": "*",
|
|
47
|
+
"@types/mocha": "^10.0.10",
|
|
48
|
+
"@types/node": "^22.15.29",
|
|
49
|
+
"chai": "^5.2.0",
|
|
50
|
+
"mocha": "^11.5.0",
|
|
51
|
+
"rimraf": "^6.1.2",
|
|
52
|
+
"ts-node": "^10.9.2",
|
|
53
|
+
"typescript": "^5.8.3"
|
|
54
|
+
}
|
|
55
|
+
}
|