@harperfast/rocksdb-js 0.1.2 → 0.1.3
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 +60 -7
- package/dist/index.cjs +16 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.mts +19 -1
- package/dist/index.mjs +15 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -19
package/README.md
CHANGED
|
@@ -91,6 +91,26 @@ RocksDatabase.config({
|
|
|
91
91
|
});
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
### `db.isOpen(): boolean`
|
|
95
|
+
|
|
96
|
+
Returns `true` if the database is open, otherwise false.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
console.log(db.isOpen()); // true or false
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `db.name: string`
|
|
103
|
+
|
|
104
|
+
Returns the database column family's name.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const db = new RocksDatabase('path/to/db');
|
|
108
|
+
console.log(db.name); // 'default'
|
|
109
|
+
|
|
110
|
+
const db2 = new RocksDatabase('path/to/db', { name: 'users' });
|
|
111
|
+
console.log(db.name); // 'users'
|
|
112
|
+
```
|
|
113
|
+
|
|
94
114
|
### `db.open(): RocksDatabase`
|
|
95
115
|
|
|
96
116
|
Opens the database at the given path. This must be called before performing any data operations.
|
|
@@ -108,16 +128,12 @@ There's also a static `open()` method for convenience that performs the same thi
|
|
|
108
128
|
const db = RocksDatabase.open('path/to/db');
|
|
109
129
|
```
|
|
110
130
|
|
|
111
|
-
### `db.
|
|
131
|
+
### `db.status: 'opened' | 'closed'`
|
|
112
132
|
|
|
113
|
-
Returns the database
|
|
133
|
+
Returns a string `'opened'` or `'closed'` indicating if the database is opened or closed.
|
|
114
134
|
|
|
115
135
|
```typescript
|
|
116
|
-
|
|
117
|
-
console.log(db.name); // 'default'
|
|
118
|
-
|
|
119
|
-
const db2 = new RocksDatabase('path/to/db', { name: 'users' });
|
|
120
|
-
console.log(db.name); // 'users'
|
|
136
|
+
console.log(db.status);
|
|
121
137
|
```
|
|
122
138
|
|
|
123
139
|
## Data Operations
|
|
@@ -156,6 +172,16 @@ const entriesRemoved = db.clearSync();
|
|
|
156
172
|
console.log(entriesRemoved); // 10
|
|
157
173
|
```
|
|
158
174
|
|
|
175
|
+
### `db.destroy(): void`
|
|
176
|
+
|
|
177
|
+
Completely removes a database based on the `db` instance's path including all data, column families,
|
|
178
|
+
and files on disk.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
db.destroy();
|
|
182
|
+
console.log(fs.existsSync(db.path)); // false
|
|
183
|
+
```
|
|
184
|
+
|
|
159
185
|
### `db.drop(): Promise<void>`
|
|
160
186
|
|
|
161
187
|
Removes all entries in the database. If the database was opened with a `name`, the database will be
|
|
@@ -847,6 +873,24 @@ Returns an object containing all of the information in the log file.
|
|
|
847
873
|
- `length: number` The size of the entry data.
|
|
848
874
|
- `timestamp: number` The entry timestamp.
|
|
849
875
|
|
|
876
|
+
### `registryStatus(): RegistryStatus`
|
|
877
|
+
|
|
878
|
+
Returns an array containing that status of all active RocksDB instances.
|
|
879
|
+
|
|
880
|
+
- `path: string` The database path.
|
|
881
|
+
- `refCount: number` The number of JavaScript database instances plus the registry's reference.
|
|
882
|
+
- `columnFamiles: string[]` A list of the database's column families.
|
|
883
|
+
- `transactions: number` The count of active transactions.
|
|
884
|
+
- `closables: number` The count of active database, transactions, and iterators.
|
|
885
|
+
- `locks: number` The count of active locks.
|
|
886
|
+
- `userSharedBuffers: number` The count of active user shared buffers.
|
|
887
|
+
- `listenerCallbacks: number` The count of in-flight callbacks.
|
|
888
|
+
|
|
889
|
+
```typescript
|
|
890
|
+
import { registryStatus } from '@harperfast/rocksdb-js';
|
|
891
|
+
console.log(registryStatus());
|
|
892
|
+
```
|
|
893
|
+
|
|
850
894
|
### `shutdown(): void`
|
|
851
895
|
|
|
852
896
|
The `shutdown()` will flush all in-memory data to disk and wait for any outstanding compactions to
|
|
@@ -858,6 +902,15 @@ import { shutdown } from '@harperfast/rocksdb-js';
|
|
|
858
902
|
process.on('exit', shutdown);
|
|
859
903
|
```
|
|
860
904
|
|
|
905
|
+
### `versions: { 'rocksdb': string; 'rocksdb-js': string }`
|
|
906
|
+
|
|
907
|
+
Returns the `rocksdb-js` and RocksDB version.
|
|
908
|
+
|
|
909
|
+
```typescript
|
|
910
|
+
import { versions } from '@harperfast/rocksdb-js';
|
|
911
|
+
console.log(versions); // { "rocksdb": "10.10.1", "rocksdb-js": "0.1.2" }
|
|
912
|
+
```
|
|
913
|
+
|
|
861
914
|
## Custom Store
|
|
862
915
|
|
|
863
916
|
The store is a class that sits between the `RocksDatabase` or `Transaction` instance and the native
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -79,8 +80,9 @@ const NativeDatabase = binding.Database;
|
|
|
79
80
|
const NativeIterator = binding.Iterator;
|
|
80
81
|
const NativeTransaction = binding.Transaction;
|
|
81
82
|
const TransactionLog = binding.TransactionLog;
|
|
82
|
-
const
|
|
83
|
+
const registryStatus = binding.registryStatus;
|
|
83
84
|
const shutdown = binding.shutdown;
|
|
85
|
+
const version = binding.version;
|
|
84
86
|
|
|
85
87
|
//#endregion
|
|
86
88
|
//#region src/util.ts
|
|
@@ -1099,7 +1101,6 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1099
1101
|
* ```
|
|
1100
1102
|
*/
|
|
1101
1103
|
clear() {
|
|
1102
|
-
if (!this.store.db.opened) return Promise.reject(/* @__PURE__ */ new Error("Database not open"));
|
|
1103
1104
|
if (this.store.encoder?.structures !== void 0) this.store.encoder.structures = [];
|
|
1104
1105
|
return new Promise((resolve, reject) => {
|
|
1105
1106
|
this.store.db.clear(resolve, reject);
|
|
@@ -1115,9 +1116,8 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1115
1116
|
* ```
|
|
1116
1117
|
*/
|
|
1117
1118
|
clearSync() {
|
|
1118
|
-
if (!this.store.db.opened) throw new Error("Database not open");
|
|
1119
1119
|
if (this.store.encoder?.structures !== void 0) this.store.encoder.structures = [];
|
|
1120
|
-
|
|
1120
|
+
this.store.db.clearSync();
|
|
1121
1121
|
}
|
|
1122
1122
|
/**
|
|
1123
1123
|
* Closes the database.
|
|
@@ -1144,14 +1144,15 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1144
1144
|
static config(options) {
|
|
1145
1145
|
config(options);
|
|
1146
1146
|
}
|
|
1147
|
+
destroy() {
|
|
1148
|
+
this.store.db.destroy();
|
|
1149
|
+
}
|
|
1147
1150
|
async drop() {
|
|
1148
|
-
if (!this.store.db.opened) return Promise.reject(/* @__PURE__ */ new Error("Database not open"));
|
|
1149
1151
|
return new Promise((resolve, reject) => {
|
|
1150
1152
|
this.store.db.drop(resolve, reject);
|
|
1151
1153
|
});
|
|
1152
1154
|
}
|
|
1153
1155
|
dropSync() {
|
|
1154
|
-
if (!this.store.db.opened) throw new Error("Database not open");
|
|
1155
1156
|
return this.store.db.dropSync();
|
|
1156
1157
|
}
|
|
1157
1158
|
get encoder() {
|
|
@@ -1410,6 +1411,12 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1410
1411
|
return this.store.db.purgeLogs(options);
|
|
1411
1412
|
}
|
|
1412
1413
|
/**
|
|
1414
|
+
* The status of the database.
|
|
1415
|
+
*/
|
|
1416
|
+
get status() {
|
|
1417
|
+
return this.store.isOpen() ? "open" : "closed";
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1413
1420
|
* Executes all operations in the callback as a single transaction.
|
|
1414
1421
|
*
|
|
1415
1422
|
* @param callback - A async function that receives the transaction as an argument.
|
|
@@ -1798,7 +1805,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
|
|
|
1798
1805
|
//#region src/index.ts
|
|
1799
1806
|
const versions = {
|
|
1800
1807
|
rocksdb: version,
|
|
1801
|
-
"rocksdb-js": "0.1.
|
|
1808
|
+
"rocksdb-js": "0.1.3"
|
|
1802
1809
|
};
|
|
1803
1810
|
|
|
1804
1811
|
//#endregion
|
|
@@ -1809,6 +1816,7 @@ exports.Transaction = Transaction;
|
|
|
1809
1816
|
exports.TransactionLog = TransactionLog;
|
|
1810
1817
|
exports.constants = constants;
|
|
1811
1818
|
exports.parseTransactionLog = parseTransactionLog;
|
|
1819
|
+
exports.registryStatus = registryStatus;
|
|
1812
1820
|
exports.shutdown = shutdown;
|
|
1813
1821
|
exports.versions = versions;
|
|
1814
1822
|
//# sourceMappingURL=index.cjs.map
|