@yydb/light-db 0.0.0 → 0.0.10
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/dist/api/database.d.ts +48 -0
- package/dist/api/database.d.ts.map +1 -0
- package/dist/api/database.js +120 -0
- package/dist/api/database.js.map +1 -0
- package/dist/api/index.d.ts +7 -22
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +5 -52
- package/dist/api/index.js.map +1 -1
- package/dist/api/schema.d.ts +33 -0
- package/dist/api/schema.d.ts.map +1 -0
- package/dist/api/schema.js +80 -0
- package/dist/api/schema.js.map +1 -0
- package/dist/api/transaction.d.ts +26 -0
- package/dist/api/transaction.d.ts.map +1 -0
- package/dist/api/transaction.js +52 -0
- package/dist/api/transaction.js.map +1 -0
- package/dist/api/types.d.ts +55 -148
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js +6 -5
- package/dist/api/types.js.map +1 -1
- package/dist/codec/binary.d.ts +196 -0
- package/dist/codec/binary.d.ts.map +1 -0
- package/dist/codec/binary.js +342 -0
- package/dist/codec/binary.js.map +1 -0
- package/dist/codec/checksum.d.ts +21 -0
- package/dist/codec/checksum.d.ts.map +1 -0
- package/dist/codec/checksum.js +46 -0
- package/dist/codec/checksum.js.map +1 -0
- package/dist/codec/index.d.ts +12 -0
- package/dist/codec/index.d.ts.map +1 -0
- package/dist/codec/index.js +10 -0
- package/dist/codec/index.js.map +1 -0
- package/dist/codec/page.d.ts +114 -0
- package/dist/codec/page.d.ts.map +1 -0
- package/dist/codec/page.js +225 -0
- package/dist/codec/page.js.map +1 -0
- package/dist/codec/record.d.ts +62 -0
- package/dist/codec/record.d.ts.map +1 -0
- package/dist/codec/record.js +82 -0
- package/dist/codec/record.js.map +1 -0
- package/dist/core/broadcast.d.ts +39 -0
- package/dist/core/broadcast.d.ts.map +1 -0
- package/dist/core/broadcast.js +54 -0
- package/dist/core/broadcast.js.map +1 -0
- package/dist/core/checkpoint.d.ts +23 -0
- package/dist/core/checkpoint.d.ts.map +1 -0
- package/dist/core/checkpoint.js +49 -0
- package/dist/core/checkpoint.js.map +1 -0
- package/dist/core/engine.d.ts +142 -0
- package/dist/core/engine.d.ts.map +1 -0
- package/dist/core/engine.js +304 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lease.d.ts +32 -0
- package/dist/core/lease.d.ts.map +1 -0
- package/dist/core/lease.js +81 -0
- package/dist/core/lease.js.map +1 -0
- package/dist/core/records.d.ts +49 -0
- package/dist/core/records.d.ts.map +1 -0
- package/dist/core/records.js +70 -0
- package/dist/core/records.js.map +1 -0
- package/dist/core/recovery.d.ts +43 -0
- package/dist/core/recovery.d.ts.map +1 -0
- package/dist/core/recovery.js +99 -0
- package/dist/core/recovery.js.map +1 -0
- package/dist/core/wal.d.ts +50 -0
- package/dist/core/wal.d.ts.map +1 -0
- package/dist/core/wal.js +114 -0
- package/dist/core/wal.js.map +1 -0
- package/dist/errors/index.d.ts +44 -66
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +43 -128
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +14 -215
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -724
- package/dist/index.js.map +1 -1
- package/dist/storage/StorageAdapter.d.ts +97 -0
- package/dist/storage/StorageAdapter.d.ts.map +1 -0
- package/dist/storage/StorageAdapter.js +9 -0
- package/dist/storage/StorageAdapter.js.map +1 -0
- package/dist/storage/index.d.ts +9 -8
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +8 -151
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/indexeddb/IndexedDbStorageAdapter.d.ts +140 -0
- package/dist/storage/indexeddb/IndexedDbStorageAdapter.d.ts.map +1 -0
- package/dist/storage/indexeddb/IndexedDbStorageAdapter.js +403 -0
- package/dist/storage/indexeddb/IndexedDbStorageAdapter.js.map +1 -0
- package/dist/storage/memory/MemoryStorageAdapter.d.ts +76 -0
- package/dist/storage/memory/MemoryStorageAdapter.d.ts.map +1 -0
- package/dist/storage/memory/MemoryStorageAdapter.js +212 -0
- package/dist/storage/memory/MemoryStorageAdapter.js.map +1 -0
- package/dist/storage/opfs/OpfsStorageAdapter.d.ts +141 -0
- package/dist/storage/opfs/OpfsStorageAdapter.d.ts.map +1 -0
- package/dist/storage/opfs/OpfsStorageAdapter.js +400 -0
- package/dist/storage/opfs/OpfsStorageAdapter.js.map +1 -0
- package/package.json +48 -36
- package/readme.md +80 -94
- package/dist/api/LightDB.d.ts +0 -194
- package/dist/api/LightDB.d.ts.map +0 -1
- package/dist/api/LightDB.js +0 -299
- package/dist/api/LightDB.js.map +0 -1
- package/dist/api/Transaction.d.ts +0 -100
- package/dist/api/Transaction.d.ts.map +0 -1
- package/dist/api/Transaction.js +0 -263
- package/dist/api/Transaction.js.map +0 -1
- package/dist/collection/Collection.d.ts +0 -235
- package/dist/collection/Collection.d.ts.map +0 -1
- package/dist/collection/Collection.js +0 -671
- package/dist/collection/Collection.js.map +0 -1
- package/dist/collection/QueryBuilder.d.ts +0 -225
- package/dist/collection/QueryBuilder.d.ts.map +0 -1
- package/dist/collection/QueryBuilder.js +0 -475
- package/dist/collection/QueryBuilder.js.map +0 -1
- package/dist/collection/QueryParser.d.ts +0 -117
- package/dist/collection/QueryParser.d.ts.map +0 -1
- package/dist/collection/QueryParser.js +0 -438
- package/dist/collection/QueryParser.js.map +0 -1
- package/dist/collection/index.d.ts +0 -42
- package/dist/collection/index.d.ts.map +0 -1
- package/dist/collection/index.js +0 -41
- package/dist/collection/index.js.map +0 -1
- package/dist/collection/types.d.ts +0 -365
- package/dist/collection/types.d.ts.map +0 -1
- package/dist/collection/types.js +0 -7
- package/dist/collection/types.js.map +0 -1
- package/dist/constants/index.d.ts +0 -51
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js +0 -68
- package/dist/constants/index.js.map +0 -1
- package/dist/indexes/BPlusTree.d.ts +0 -181
- package/dist/indexes/BPlusTree.d.ts.map +0 -1
- package/dist/indexes/BPlusTree.js +0 -528
- package/dist/indexes/BPlusTree.js.map +0 -1
- package/dist/indexes/IndexManager.d.ts +0 -236
- package/dist/indexes/IndexManager.d.ts.map +0 -1
- package/dist/indexes/IndexManager.js +0 -502
- package/dist/indexes/IndexManager.js.map +0 -1
- package/dist/indexes/PrimaryIndex.d.ts +0 -240
- package/dist/indexes/PrimaryIndex.d.ts.map +0 -1
- package/dist/indexes/PrimaryIndex.js +0 -354
- package/dist/indexes/PrimaryIndex.js.map +0 -1
- package/dist/indexes/SecondaryIndex.d.ts +0 -204
- package/dist/indexes/SecondaryIndex.d.ts.map +0 -1
- package/dist/indexes/SecondaryIndex.js +0 -480
- package/dist/indexes/SecondaryIndex.js.map +0 -1
- package/dist/indexes/errors.d.ts +0 -66
- package/dist/indexes/errors.d.ts.map +0 -1
- package/dist/indexes/errors.js +0 -117
- package/dist/indexes/errors.js.map +0 -1
- package/dist/indexes/index.d.ts +0 -52
- package/dist/indexes/index.d.ts.map +0 -1
- package/dist/indexes/index.js +0 -131
- package/dist/indexes/index.js.map +0 -1
- package/dist/indexes/types.d.ts +0 -246
- package/dist/indexes/types.d.ts.map +0 -1
- package/dist/indexes/types.js +0 -30
- package/dist/indexes/types.js.map +0 -1
- package/dist/performance/BatchWALWriter.d.ts +0 -185
- package/dist/performance/BatchWALWriter.d.ts.map +0 -1
- package/dist/performance/BatchWALWriter.js +0 -490
- package/dist/performance/BatchWALWriter.js.map +0 -1
- package/dist/performance/ColumnarStorage.d.ts +0 -138
- package/dist/performance/ColumnarStorage.d.ts.map +0 -1
- package/dist/performance/ColumnarStorage.js +0 -875
- package/dist/performance/ColumnarStorage.js.map +0 -1
- package/dist/performance/LazyQuery.d.ts +0 -307
- package/dist/performance/LazyQuery.d.ts.map +0 -1
- package/dist/performance/LazyQuery.js +0 -588
- package/dist/performance/LazyQuery.js.map +0 -1
- package/dist/performance/OptimizedBuffer.d.ts +0 -375
- package/dist/performance/OptimizedBuffer.d.ts.map +0 -1
- package/dist/performance/OptimizedBuffer.js +0 -730
- package/dist/performance/OptimizedBuffer.js.map +0 -1
- package/dist/performance/RWLock.d.ts +0 -260
- package/dist/performance/RWLock.d.ts.map +0 -1
- package/dist/performance/RWLock.js +0 -570
- package/dist/performance/RWLock.js.map +0 -1
- package/dist/performance/index.d.ts +0 -41
- package/dist/performance/index.d.ts.map +0 -1
- package/dist/performance/index.js +0 -162
- package/dist/performance/index.js.map +0 -1
- package/dist/performance/types.d.ts +0 -247
- package/dist/performance/types.d.ts.map +0 -1
- package/dist/performance/types.js +0 -26
- package/dist/performance/types.js.map +0 -1
- package/dist/storage/Checkpoint.d.ts +0 -128
- package/dist/storage/Checkpoint.d.ts.map +0 -1
- package/dist/storage/Checkpoint.js +0 -251
- package/dist/storage/Checkpoint.js.map +0 -1
- package/dist/storage/LightFile.d.ts +0 -227
- package/dist/storage/LightFile.d.ts.map +0 -1
- package/dist/storage/LightFile.js +0 -526
- package/dist/storage/LightFile.js.map +0 -1
- package/dist/storage/Recovery.d.ts +0 -172
- package/dist/storage/Recovery.d.ts.map +0 -1
- package/dist/storage/Recovery.js +0 -399
- package/dist/storage/Recovery.js.map +0 -1
- package/dist/storage/SHMFile.d.ts +0 -243
- package/dist/storage/SHMFile.d.ts.map +0 -1
- package/dist/storage/SHMFile.js +0 -436
- package/dist/storage/SHMFile.js.map +0 -1
- package/dist/storage/StorageEngine.d.ts +0 -146
- package/dist/storage/StorageEngine.d.ts.map +0 -1
- package/dist/storage/StorageEngine.js +0 -353
- package/dist/storage/StorageEngine.js.map +0 -1
- package/dist/storage/WALFile.d.ts +0 -248
- package/dist/storage/WALFile.d.ts.map +0 -1
- package/dist/storage/WALFile.js +0 -597
- package/dist/storage/WALFile.js.map +0 -1
- package/dist/types/index.d.ts +0 -220
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -7
- package/dist/types/index.js.map +0 -1
- package/dist/utils/binary.d.ts +0 -271
- package/dist/utils/binary.d.ts.map +0 -1
- package/dist/utils/binary.js +0 -454
- package/dist/utils/binary.js.map +0 -1
- package/dist/utils/file.d.ts +0 -166
- package/dist/utils/file.d.ts.map +0 -1
- package/dist/utils/file.js +0 -346
- package/dist/utils/file.js.map +0 -1
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -39
- package/dist/utils/index.js.map +0 -1
package/readme.md
CHANGED
|
@@ -1,124 +1,110 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@yydb/light-db`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Light DB** is the browser edition of YYDB: a database written in pure TypeScript that stores `.yydb`-style
|
|
4
|
+
snapshots, WAL records and checkpoints in browser storage. It has no Node built-ins, no N-API bindings and no WASM in
|
|
5
|
+
its runtime path.
|
|
4
6
|
|
|
5
|
-
##
|
|
7
|
+
## Product relationship
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
- **Memory-Mapped Files**: Efficient I/O operations
|
|
13
|
-
- **TypeScript Ready**: Full TypeScript support with type definitions
|
|
9
|
+
| Package | Role |
|
|
10
|
+
|---------|------|
|
|
11
|
+
| `@yydb/yydb` | Node product: native Rust engine, N-API, local `.yydb` / `.yydx` files and CLI |
|
|
12
|
+
| `@yydb/light-db` | Browser product: pure TypeScript, OPFS / IndexedDB storage, Web APIs, same author surface |
|
|
13
|
+
| `@yydb/yydb-client` | Remote wire client for a running `yydb serve` |
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Status
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Quick Start 🚀
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
import { LightDB } from '@yydb/light-db';
|
|
17
|
+
Light DB is a migration of the original `LightDB.ts` engine, rebuilt around a browser-native architecture. The package
|
|
18
|
+
ships as a pre-1.0 release of the browser product, so the author surface may still change between patch releases.
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
const db = await LightDB.open('./mydb');
|
|
20
|
+
Current coverage:
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
- `pnpm test` runs the Node-side runner over codec, adapter and database logic (29 cases).
|
|
23
|
+
- `pnpm test:browser` runs the conformance suite in an installed Chrome (16 cases): OPFS persistence across reopen, WAL
|
|
24
|
+
recovery, checkpoint truncation, corruption detection, single-writer exclusion, transaction rollback and commit,
|
|
25
|
+
schema and close notifications, and two-tab lease and broadcast behaviour.
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
await users.insert({ id: 1, name: 'John Doe', email: 'john@example.com' });
|
|
27
|
+
## Usage
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
console.log(user); // { id: 1, name: 'John Doe', email: 'john@example.com' }
|
|
29
|
+
```ts
|
|
30
|
+
import { LightDbError, openLightDatabase } from '@yydb/light-db';
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
await users.update({ id: 1 }, { $set: { name: 'John Smith' } });
|
|
32
|
+
const db = await openLightDatabase('app');
|
|
41
33
|
|
|
42
|
-
//
|
|
43
|
-
await
|
|
34
|
+
await db.ensureSchema('// @yydb-schema-version: 1\nkv users');
|
|
35
|
+
await db.put('user:1', new TextEncoder().encode('Ada'));
|
|
44
36
|
|
|
45
|
-
|
|
37
|
+
const value = await db.get('user:1');
|
|
38
|
+
await db.checkpoint();
|
|
46
39
|
await db.close();
|
|
47
40
|
```
|
|
48
41
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
### LightDB Class
|
|
52
|
-
|
|
53
|
-
#### `open(path: string): Promise<LightDB>`
|
|
54
|
-
Opens an existing database or creates a new one at the specified path.
|
|
55
|
-
|
|
56
|
-
#### `collection(name: string): Collection`
|
|
57
|
-
Returns a collection with the given name. Creates it if it doesn't exist.
|
|
58
|
-
|
|
59
|
-
#### `transaction(): Promise<Transaction>`
|
|
60
|
-
Starts a new transaction.
|
|
61
|
-
|
|
62
|
-
#### `close(): Promise<void>`
|
|
63
|
-
Closes the database connection.
|
|
64
|
-
|
|
65
|
-
### Collection Class
|
|
42
|
+
Public data types are browser-native: keys and values use `Uint8Array`, databases are addressed by name rather than by
|
|
43
|
+
file path, and every lifecycle call is asynchronous.
|
|
66
44
|
|
|
67
|
-
|
|
68
|
-
Inserts a new document into the collection.
|
|
45
|
+
## Author surface
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
```ts
|
|
48
|
+
const db: LightDatabase = await openLightDatabase('app', options);
|
|
72
49
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
### Transaction Class
|
|
86
|
-
|
|
87
|
-
#### `commit(): Promise<void>`
|
|
88
|
-
Commits the transaction.
|
|
89
|
-
|
|
90
|
-
#### `rollback(): Promise<void>`
|
|
91
|
-
Rolls back the transaction.
|
|
92
|
-
|
|
93
|
-
## Performance Features ⚡
|
|
50
|
+
await db.schema();
|
|
51
|
+
await db.ensureSchema(document);
|
|
52
|
+
await db.get(key);
|
|
53
|
+
await db.put(key, value);
|
|
54
|
+
await db.delete(key);
|
|
55
|
+
await db.begin();
|
|
56
|
+
await db.commit();
|
|
57
|
+
await db.rollback();
|
|
58
|
+
await db.checkpoint();
|
|
59
|
+
db.stats();
|
|
60
|
+
await db.close();
|
|
61
|
+
```
|
|
94
62
|
|
|
95
|
-
|
|
96
|
-
|
|
63
|
+
`schema()` returns the persisted schema version and document. The document is the single source of truth: a second
|
|
64
|
+
`ensureSchema` call must pass the identical document, otherwise it fails with `yydb.schema.conflict`. Keys starting with
|
|
65
|
+
`__yydb__/` are reserved for the database.
|
|
97
66
|
|
|
98
|
-
|
|
99
|
-
For certain data types, LightDB uses columnar storage to reduce disk space and improve query performance.
|
|
67
|
+
## Storage backends
|
|
100
68
|
|
|
101
|
-
|
|
102
|
-
|
|
69
|
+
| Adapter | Use |
|
|
70
|
+
|---------|-----|
|
|
71
|
+
| `OpfsStorageAdapterFactory` | Default. Origin Private File System, positional reads and writes, atomic snapshot publication |
|
|
72
|
+
| `IndexedDbStorageAdapterFactory` | Compatibility backend for hosts without OPFS |
|
|
73
|
+
| `MemoryStorageBackend` | Tests and throwaway sessions |
|
|
103
74
|
|
|
104
|
-
|
|
75
|
+
`StorageAdapter` is the only platform boundary. Transactions, recovery and checkpoint semantics live in `core`, so
|
|
76
|
+
backends implement files, not database behaviour.
|
|
105
77
|
|
|
106
|
-
|
|
78
|
+
## Concurrency
|
|
107
79
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
4. **Collection Layer**: Provides a document-oriented API
|
|
112
|
-
5. **Transaction Manager**: Handles ACID-compliant transactions
|
|
80
|
+
A writer holds a session-scoped `Web Locks` lease. A second tab that opens the same database fails with
|
|
81
|
+
`yydb.lease.unavailable` and `retryable: true` instead of silently writing alongside the first one. When a lock manager
|
|
82
|
+
is missing the call fails the same way; it never degrades to multiple writers.
|
|
113
83
|
|
|
114
|
-
|
|
84
|
+
`BroadcastChannel` carries `commit`, `schema` and `close` events so other same-origin contexts can discard stale views
|
|
85
|
+
and retry after the lease is released. `listenDatabaseEvents(name, handler)` subscribes without opening the database.
|
|
115
86
|
|
|
116
|
-
|
|
87
|
+
## Layout
|
|
117
88
|
|
|
118
|
-
|
|
89
|
+
| Path | Role |
|
|
90
|
+
|------|------|
|
|
91
|
+
| `src/api/` | Public database, transaction, schema and shared types |
|
|
92
|
+
| `src/core/` | Records, WAL, checkpoint, recovery, writer lease and broadcast |
|
|
93
|
+
| `src/storage/` | `StorageAdapter` plus OPFS, IndexedDB and memory backends |
|
|
94
|
+
| `src/codec/` | Page, snapshot and WAL record encoding over `Uint8Array` |
|
|
95
|
+
| `src/errors/` | Stable `yydb.*` error codes |
|
|
119
96
|
|
|
120
|
-
|
|
97
|
+
## Errors
|
|
121
98
|
|
|
122
|
-
|
|
99
|
+
| Code | Meaning |
|
|
100
|
+
|------|---------|
|
|
101
|
+
| `yydb.io` | Storage operation failed |
|
|
102
|
+
| `yydb.corrupt` | Persisted bytes failed validation |
|
|
103
|
+
| `yydb.schema.conflict` | Schema document differs from the stored one |
|
|
104
|
+
| `yydb.schema.invalid` | Schema document is not usable |
|
|
105
|
+
| `yydb.unsupported` | Host or operation is not supported |
|
|
106
|
+
| `yydb.session.closed` | Database or handle is closed |
|
|
107
|
+
| `yydb.lease.unavailable` | Writer lease is held elsewhere or Web Locks is missing (retryable) |
|
|
108
|
+
| `yydb.quota.exceeded` | Browser storage quota is exhausted |
|
|
123
109
|
|
|
124
|
-
|
|
110
|
+
[YYDB overview](https://github.com/yy-database/yydb.rs)
|
package/dist/api/LightDB.d.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LightDB 主类
|
|
3
|
-
* 提供用户直接使用的接口层
|
|
4
|
-
*/
|
|
5
|
-
import { StorageEngine } from "../storage";
|
|
6
|
-
import { Collection } from "../collection";
|
|
7
|
-
import type {
|
|
8
|
-
LightDBOptions,
|
|
9
|
-
CollectionCreateOptions,
|
|
10
|
-
TransactionCallback,
|
|
11
|
-
TransactionOptions,
|
|
12
|
-
TransactionResult,
|
|
13
|
-
DatabaseStats,
|
|
14
|
-
DatabaseConfig,
|
|
15
|
-
ILightDB,
|
|
16
|
-
CollectionSchema,
|
|
17
|
-
} from "./types";
|
|
18
|
-
import type { CheckpointResult } from "../types";
|
|
19
|
-
/**
|
|
20
|
-
* LightDB 数据库实例
|
|
21
|
-
* 提供完整的数据库操作 API
|
|
22
|
-
*/
|
|
23
|
-
export declare class LightDB implements ILightDB {
|
|
24
|
-
private readonly storageEngine;
|
|
25
|
-
private readonly collections;
|
|
26
|
-
private readonly transactionManager;
|
|
27
|
-
private readonly options;
|
|
28
|
-
private closed;
|
|
29
|
-
/**
|
|
30
|
-
* 创建 LightDB 实例
|
|
31
|
-
* @param storageEngine 已初始化的存储引擎
|
|
32
|
-
* @param options 配置选项
|
|
33
|
-
*/
|
|
34
|
-
private constructor();
|
|
35
|
-
/**
|
|
36
|
-
* 打开数据库
|
|
37
|
-
* 创建或打开指定路径的数据库
|
|
38
|
-
*
|
|
39
|
-
* @param path 数据库文件存储路径
|
|
40
|
-
* @param options 配置选项
|
|
41
|
-
* @returns 初始化完成的 LightDB 实例
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* const db = await LightDB.open('./data/mydb', {
|
|
46
|
-
* dbName: 'mydb',
|
|
47
|
-
* autoCheckpoint: true,
|
|
48
|
-
* pageSize: 4096
|
|
49
|
-
* });
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
static open(path: string, options?: LightDBOptions): Promise<LightDB>;
|
|
53
|
-
/**
|
|
54
|
-
* 获取数据库名称
|
|
55
|
-
*/
|
|
56
|
-
get dbName(): string;
|
|
57
|
-
/**
|
|
58
|
-
* 获取数据库路径
|
|
59
|
-
*/
|
|
60
|
-
get path(): string;
|
|
61
|
-
/**
|
|
62
|
-
* 检查数据库是否已打开
|
|
63
|
-
*/
|
|
64
|
-
get isOpen(): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* 获取或创建集合
|
|
67
|
-
* 返回类型安全的集合实例
|
|
68
|
-
*
|
|
69
|
-
* @param name 集合名称
|
|
70
|
-
* @param options 集合配置选项
|
|
71
|
-
* @returns 集合实例
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* interface User {
|
|
76
|
-
* id: number;
|
|
77
|
-
* name: string;
|
|
78
|
-
* age: number;
|
|
79
|
-
* }
|
|
80
|
-
*
|
|
81
|
-
* const users = db.collection<User>('users', {
|
|
82
|
-
* name: 'users',
|
|
83
|
-
* primaryKey: 'id',
|
|
84
|
-
* indexes: [
|
|
85
|
-
* { name: 'name_idx', fieldName: 'name' }
|
|
86
|
-
* ]
|
|
87
|
-
* });
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
collection<T extends Record<string, unknown>>(name: string, options: CollectionCreateOptions<T>): Collection<T>;
|
|
91
|
-
/**
|
|
92
|
-
* 检查集合是否存在
|
|
93
|
-
*
|
|
94
|
-
* @param name 集合名称
|
|
95
|
-
* @returns 集合是否存在
|
|
96
|
-
*/
|
|
97
|
-
hasCollection(name: string): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* 删除集合
|
|
100
|
-
*
|
|
101
|
-
* @param name 集合名称
|
|
102
|
-
* @returns 是否删除成功
|
|
103
|
-
*/
|
|
104
|
-
dropCollection(name: string): boolean;
|
|
105
|
-
/**
|
|
106
|
-
* 获取所有集合名称
|
|
107
|
-
*
|
|
108
|
-
* @returns 集合名称数组
|
|
109
|
-
*/
|
|
110
|
-
getCollectionNames(): string[];
|
|
111
|
-
/**
|
|
112
|
-
* 执行事务
|
|
113
|
-
* 支持 ACID 事务特性
|
|
114
|
-
*
|
|
115
|
-
* @param callback 事务回调函数
|
|
116
|
-
* @param options 事务选项
|
|
117
|
-
* @returns 事务执行结果
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* await db.transaction(async (tx) => {
|
|
122
|
-
* const users = tx.collection<User>('users');
|
|
123
|
-
* const user = await users.findOne({ id: 1 });
|
|
124
|
-
* await users.update({ id: 1 }, { balance: user.balance - 100 });
|
|
125
|
-
* });
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
transaction(callback: TransactionCallback, options?: TransactionOptions): Promise<TransactionResult>;
|
|
129
|
-
/**
|
|
130
|
-
* 执行检查点
|
|
131
|
-
* 将内存中的数据持久化到磁盘
|
|
132
|
-
*
|
|
133
|
-
* @returns 检查点执行结果
|
|
134
|
-
*/
|
|
135
|
-
checkpoint(): Promise<CheckpointResult>;
|
|
136
|
-
/**
|
|
137
|
-
* 获取数据库统计信息
|
|
138
|
-
*
|
|
139
|
-
* @returns 数据库统计信息
|
|
140
|
-
*/
|
|
141
|
-
getStats(): Promise<DatabaseStats>;
|
|
142
|
-
/**
|
|
143
|
-
* 获取数据库配置
|
|
144
|
-
*
|
|
145
|
-
* @returns 数据库配置信息
|
|
146
|
-
*/
|
|
147
|
-
getConfig(): DatabaseConfig;
|
|
148
|
-
/**
|
|
149
|
-
* 同步数据到磁盘
|
|
150
|
-
* 确保所有数据都已持久化
|
|
151
|
-
*/
|
|
152
|
-
sync(): Promise<void>;
|
|
153
|
-
/**
|
|
154
|
-
* 关闭数据库
|
|
155
|
-
* 释放所有资源并确保数据持久化
|
|
156
|
-
*/
|
|
157
|
-
close(): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* 确保数据库处于打开状态
|
|
160
|
-
*/
|
|
161
|
-
private ensureOpen;
|
|
162
|
-
/**
|
|
163
|
-
* 获取存储引擎(内部使用)
|
|
164
|
-
*/
|
|
165
|
-
getStorageEngine(): StorageEngine;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* 定义集合 Schema 的辅助函数
|
|
169
|
-
* 提供类型推断和 IDE 支持
|
|
170
|
-
*
|
|
171
|
-
* @param schema Schema 定义
|
|
172
|
-
* @returns Schema 对象
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* const UserSchema = defineCollectionSchema({
|
|
177
|
-
* schema: {} as User,
|
|
178
|
-
* primaryKey: 'id',
|
|
179
|
-
* indexes: [
|
|
180
|
-
* { name: 'name_idx', fieldName: 'name' }
|
|
181
|
-
* ]
|
|
182
|
-
* });
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
export declare function defineCollectionSchema<T extends Record<string, unknown>>(schema: CollectionSchema<T>): CollectionSchema<T>;
|
|
186
|
-
/**
|
|
187
|
-
* 打开数据库的便捷函数
|
|
188
|
-
*
|
|
189
|
-
* @param path 数据库文件存储路径
|
|
190
|
-
* @param options 配置选项
|
|
191
|
-
* @returns 初始化完成的 LightDB 实例
|
|
192
|
-
*/
|
|
193
|
-
export declare function openDatabase(path: string, options?: LightDBOptions): Promise<LightDB>;
|
|
194
|
-
//# sourceMappingURL=LightDB.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LightDB.d.ts","sourceRoot":"","sources":["../../src/api/LightDB.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAuB,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EACR,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,QAAQ,EACR,gBAAgB,EACnB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,gBAAgB,EAAsC,MAAM,UAAU,CAAC;AAGrF;;;GAGG;AACH,qBAAa,OAAQ,YAAW,QAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmD;IAC/E,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAEtB;IACF,OAAO,CAAC,MAAM,CAAU;IAExB;;;;OAIG;IACH,OAAO;IAaP;;;;;;;;;;;;;;;;OAgBG;WACiB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAyBtF;;OAEG;IACH,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAW,MAAM,IAAI,OAAO,CAE3B;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACI,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAoBtH;;;;;OAKG;IACI,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAK3C;;;;;OAKG;IACI,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAa5C;;;;OAIG;IACI,kBAAkB,IAAI,MAAM,EAAE;IAKrC;;;;;;;;;;;;;;;;OAgBG;IACU,WAAW,CAAC,QAAQ,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAKjH;;;;;OAKG;IACU,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKpD;;;;OAIG;IACU,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC;IAmB/C;;;;OAIG;IACI,SAAS,IAAI,cAAc;IAUlC;;;OAGG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAKlC;;;OAGG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAcnC;;OAEG;IACH,OAAO,CAAC,UAAU;IASlB;;OAEG;IACI,gBAAgB,IAAI,aAAa;CAG3C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAE1H;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3F"}
|