@quereus/plugin-leveldb 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 +146 -0
- package/package.json +96 -0
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @quereus/plugin-leveldb
|
|
2
|
+
|
|
3
|
+
LevelDB storage plugin for Quereus. Provides persistent storage for Node.js environments using the [`@quereus/store`](../quereus-store/) module.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Fast**: LevelDB offers excellent read/write performance for key-value workloads
|
|
8
|
+
- **Sorted keys**: Efficient range queries with ordered iteration
|
|
9
|
+
- **ACID batches**: Atomic writes across multiple keys
|
|
10
|
+
- **Compression**: Built-in Snappy compression for reduced disk usage
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @quereus/plugin-leveldb @quereus/store
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
### With registerPlugin (Recommended)
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { Database, registerPlugin } from '@quereus/quereus';
|
|
24
|
+
import leveldbPlugin from '@quereus/plugin-leveldb/plugin';
|
|
25
|
+
|
|
26
|
+
const db = new Database();
|
|
27
|
+
await registerPlugin(db, leveldbPlugin, { basePath: './data' });
|
|
28
|
+
|
|
29
|
+
await db.exec(`
|
|
30
|
+
create table users (id integer primary key, name text)
|
|
31
|
+
using store
|
|
32
|
+
`);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Direct Usage with Provider
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Database } from '@quereus/quereus';
|
|
39
|
+
import { createLevelDBProvider } from '@quereus/plugin-leveldb';
|
|
40
|
+
import { StoreModule } from '@quereus/store';
|
|
41
|
+
|
|
42
|
+
const db = new Database();
|
|
43
|
+
const provider = createLevelDBProvider({ basePath: './data' });
|
|
44
|
+
const storeModule = new StoreModule(provider);
|
|
45
|
+
db.registerVtabModule('store', storeModule);
|
|
46
|
+
|
|
47
|
+
await db.exec(`
|
|
48
|
+
create table users (id integer primary key, name text)
|
|
49
|
+
using store
|
|
50
|
+
`);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
### LevelDBStore
|
|
56
|
+
|
|
57
|
+
Low-level KVStore implementation:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { LevelDBStore } from '@quereus/plugin-leveldb';
|
|
61
|
+
|
|
62
|
+
const store = await LevelDBStore.open({ path: './data/mystore' });
|
|
63
|
+
|
|
64
|
+
await store.put(key, value);
|
|
65
|
+
const data = await store.get(key);
|
|
66
|
+
await store.delete(key);
|
|
67
|
+
|
|
68
|
+
// Range iteration
|
|
69
|
+
for await (const { key, value } of store.iterate({ gte: startKey, lt: endKey })) {
|
|
70
|
+
console.log(key, value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Batch writes
|
|
74
|
+
const batch = store.batch();
|
|
75
|
+
batch.put(key1, value1);
|
|
76
|
+
batch.put(key2, value2);
|
|
77
|
+
batch.delete(key3);
|
|
78
|
+
await batch.write();
|
|
79
|
+
|
|
80
|
+
await store.close();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### LevelDBProvider
|
|
84
|
+
|
|
85
|
+
Factory for managing multiple stores:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { createLevelDBProvider } from '@quereus/plugin-leveldb';
|
|
89
|
+
|
|
90
|
+
const provider = createLevelDBProvider({ basePath: './data' });
|
|
91
|
+
|
|
92
|
+
const userStore = await provider.getStore('main', 'users'); // ./data/main/users
|
|
93
|
+
const catalogStore = await provider.getCatalogStore(); // ./data/__catalog__
|
|
94
|
+
|
|
95
|
+
await provider.closeStore('main', 'users');
|
|
96
|
+
await provider.closeAll();
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Configuration
|
|
100
|
+
|
|
101
|
+
### Plugin Settings
|
|
102
|
+
|
|
103
|
+
| Setting | Type | Default | Description |
|
|
104
|
+
|---------|------|---------|-------------|
|
|
105
|
+
| `basePath` | string | `'./data'` | Base directory for all stores |
|
|
106
|
+
| `createIfMissing` | boolean | `true` | Create directories if they don't exist |
|
|
107
|
+
| `moduleName` | string | `'store'` | Name to register the virtual table module under |
|
|
108
|
+
|
|
109
|
+
### LevelDBStore Options
|
|
110
|
+
|
|
111
|
+
| Option | Type | Default | Description |
|
|
112
|
+
|--------|------|---------|-------------|
|
|
113
|
+
| `path` | string | required | Directory path for the database |
|
|
114
|
+
| `createIfMissing` | boolean | `true` | Create database if it doesn't exist |
|
|
115
|
+
|
|
116
|
+
## Example with Transactions
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { Database, registerPlugin } from '@quereus/quereus';
|
|
120
|
+
import leveldbPlugin from '@quereus/plugin-leveldb/plugin';
|
|
121
|
+
|
|
122
|
+
const db = new Database();
|
|
123
|
+
await registerPlugin(db, leveldbPlugin, { basePath: './data' });
|
|
124
|
+
|
|
125
|
+
await db.exec(`create table accounts (id integer primary key, balance real) using store`);
|
|
126
|
+
|
|
127
|
+
await db.exec('begin');
|
|
128
|
+
try {
|
|
129
|
+
await db.exec(`update accounts set balance = balance - 100 where id = 1`);
|
|
130
|
+
await db.exec(`update accounts set balance = balance + 100 where id = 2`);
|
|
131
|
+
await db.exec('commit');
|
|
132
|
+
} catch (e) {
|
|
133
|
+
await db.exec('rollback');
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Related Packages
|
|
139
|
+
|
|
140
|
+
- [`@quereus/store`](../quereus-store/) - Core storage module (StoreModule, StoreTable)
|
|
141
|
+
- [`@quereus/plugin-indexeddb`](../quereus-plugin-indexeddb/) - IndexedDB plugin for browsers
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT
|
|
146
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quereus/plugin-leveldb",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "LevelDB storage plugin for Quereus - Node.js persistent storage",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"quereus",
|
|
8
|
+
"quereus-plugin",
|
|
9
|
+
"sql",
|
|
10
|
+
"database",
|
|
11
|
+
"storage",
|
|
12
|
+
"leveldb",
|
|
13
|
+
"kv-store",
|
|
14
|
+
"persistent"
|
|
15
|
+
],
|
|
16
|
+
"publisher": "Got Choices Foundation",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/gotchoices/quereus.git",
|
|
20
|
+
"directory": "packages/quereus-plugin-leveldb"
|
|
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
|
+
"./plugin": {
|
|
35
|
+
"types": "./dist/src/plugin.d.ts",
|
|
36
|
+
"import": "./dist/src/plugin.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@quereus/quereus": "^0.24.0",
|
|
41
|
+
"@quereus/store": "^0.3.5"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"quereus": "^0.24.0"
|
|
45
|
+
},
|
|
46
|
+
"quereus": {
|
|
47
|
+
"provides": {
|
|
48
|
+
"vtables": [
|
|
49
|
+
"store"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"settings": [
|
|
53
|
+
{
|
|
54
|
+
"key": "basePath",
|
|
55
|
+
"label": "Base Path",
|
|
56
|
+
"type": "string",
|
|
57
|
+
"default": "./data",
|
|
58
|
+
"help": "Base directory for all LevelDB stores"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"key": "createIfMissing",
|
|
62
|
+
"label": "Create If Missing",
|
|
63
|
+
"type": "boolean",
|
|
64
|
+
"default": true,
|
|
65
|
+
"help": "Create directories if they don't exist"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"key": "moduleName",
|
|
69
|
+
"label": "Module Name",
|
|
70
|
+
"type": "string",
|
|
71
|
+
"default": "store",
|
|
72
|
+
"help": "Name to register the virtual table module under"
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"clean": "rimraf dist",
|
|
78
|
+
"build": "tsc",
|
|
79
|
+
"typecheck": "tsc --noEmit",
|
|
80
|
+
"test": "cd ../.. && node --import ./packages/quereus-plugin-leveldb/register.mjs node_modules/mocha/bin/mocha.js \"packages/quereus-plugin-leveldb/test/**/*.spec.ts\" --colors"
|
|
81
|
+
},
|
|
82
|
+
"dependencies": {
|
|
83
|
+
"classic-level": "^2.0.0"
|
|
84
|
+
},
|
|
85
|
+
"devDependencies": {
|
|
86
|
+
"@quereus/quereus": "*",
|
|
87
|
+
"@quereus/store": "*",
|
|
88
|
+
"@types/mocha": "^10.0.10",
|
|
89
|
+
"@types/node": "^22.15.29",
|
|
90
|
+
"chai": "^5.2.0",
|
|
91
|
+
"mocha": "^11.5.0",
|
|
92
|
+
"rimraf": "^6.1.2",
|
|
93
|
+
"ts-node": "^10.9.2",
|
|
94
|
+
"typescript": "^5.8.3"
|
|
95
|
+
}
|
|
96
|
+
}
|