@harperfast/rocksdb-js 1.1.1 → 1.2.0

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 CHANGED
@@ -105,10 +105,12 @@ Sets global database settings.
105
105
  - `blockCacheSize: number` The amount of memory in bytes to use to cache uncompressed blocks.
106
106
  Defaults to 32MB. Set to `0` (zero) disables block cache for future opened databases. Existing
107
107
  block cache for any opened databases is resized immediately. Negative values throw an error.
108
+ - `compactOnClose: boolean` When `true`, compacts the database on close. Defaults to `false`.
108
109
 
109
110
  ```typescript
110
111
  RocksDatabase.config({
111
112
  blockCacheSize: 100 * 1024 * 1024, // 100MB
113
+ compactOnClose: true,
112
114
  });
113
115
  ```
114
116
 
@@ -193,6 +195,33 @@ const entriesRemoved = db.clearSync();
193
195
  console.log(entriesRemoved); // 10
194
196
  ```
195
197
 
198
+ ### `db.compact(options?): Promise<void>`
199
+
200
+ Compacts a range of keys in the database. In RocksDB, deleted keys are not immediately removed from
201
+ the database. Instead, they are marked as deleted and a tombstone is written. This function
202
+ triggers a manual compaction which removes the tombstones and reclaims space. Only one compaction
203
+ per database path can be performed at a time.
204
+
205
+ - `options: object`
206
+ - `start?: Key` The start key of the range to compact.
207
+ - `end?: Key` The end key of the range to compact.
208
+
209
+ ```typescript
210
+ await db.compact();
211
+
212
+ await db.compact({ start: 'a', end: 'z' });
213
+ ```
214
+
215
+ ### `db.compactSync(options?): void`
216
+
217
+ Synchronous version of `compact()`.
218
+
219
+ ```typescript
220
+ db.compactSync();
221
+
222
+ db.compactSync({ start: 'a', end: 'z' });
223
+ ```
224
+
196
225
  ### `db.destroy(): void`
197
226
 
198
227
  Completely removes a database based on the `db` instance's path including all data, column families,
@@ -224,6 +253,23 @@ db.dropSync();
224
253
  db.close();
225
254
  ```
226
255
 
256
+ ### `db.flush(): Promise<void>`
257
+
258
+ Flushes all in-memory data to disk asynchronously.
259
+
260
+ ```typescript
261
+ await db.flush();
262
+ ```
263
+
264
+ ### `db.flushSync(): void`
265
+
266
+ Flushes all in-memory data to disk synchronously. Note that this can be an expensive operation, so
267
+ it is recommended to use `flush()` if you want to keep the event loop free.
268
+
269
+ ```typescript
270
+ db.flushSync();
271
+ ```
272
+
227
273
  ### `db.get(key: Key, options?: GetOptions): MaybePromise<any>`
228
274
 
229
275
  Retreives the value for a given key. If the key does not exist, it will resolve `undefined`.
@@ -248,6 +294,16 @@ Note that all errors are returned as rejected promises.
248
294
 
249
295
  Synchronous version of `get()`.
250
296
 
297
+ ### `db.getEstimatedKeyCount(): number`
298
+
299
+ Retrieves the estimated number of keys in the database. This is an alias for
300
+ `db.getDBIntProperty('rocksdb.estimate-num-keys')`.
301
+
302
+ ```typescript
303
+ const estimated = db.getEstimatedKeyCount();
304
+ console.log(estimated);
305
+ ```
306
+
251
307
  ### `db.getKeys(options?: IteratorOptions): ExtendedIterable`
252
308
 
253
309
  Retrieves all keys within a range.
@@ -260,11 +316,11 @@ for (const key of db.getKeys()) {
260
316
 
261
317
  ### `db.getKeysCount(options?: RangeOptions): number`
262
318
 
263
- Retrieves the number of keys within a range.
319
+ Retrieves the exact number of keys in a database or a range.
264
320
 
265
321
  ```typescript
266
- const total = db.getKeysCount();
267
- const range = db.getKeysCount({ start: 'a', end: 'z' });
322
+ const count = db.getKeysCount(); // estimated number of keys
323
+ const range = db.getKeysCount({ start: 'a', end: 'z' }); // exact number of keys in the range
268
324
  ```
269
325
 
270
326
  ### `db.getMonotonicTimestamp(): number`
@@ -876,23 +932,6 @@ Note: If the `callback` throws an error, Node.js suppress the error. Node.js 18.
876
932
  `--force-node-api-uncaught-exceptions-policy` flag which will cause errors to emit the
877
933
  `'uncaughtException'` event. Future Node.js releases will enable this flag by default.
878
934
 
879
- ### `db.flush(): Promise<void>`
880
-
881
- Flushes all in-memory data to disk asynchronously.
882
-
883
- ```typescript
884
- await db.flush();
885
- ```
886
-
887
- ### `db.flushSync(): void`
888
-
889
- Flushes all in-memory data to disk synchronously. Note that this can be an expensive operation, so
890
- it is recommended to use `flush()` if you want to keep the event loop free.
891
-
892
- ```typescript
893
- db.flushSync();
894
- ```
895
-
896
935
  ## Transaction Log
897
936
 
898
937
  A user controlled API for logging transactions. This API is designed to be generic so that you can
@@ -1129,6 +1168,8 @@ The default `Store` contains the following methods which can be overridden:
1129
1168
 
1130
1169
  - `constructor(path, options?)`
1131
1170
  - `close()`
1171
+ - `compact(options?)`
1172
+ - `compactSync(options?)`
1132
1173
  - `decodeKey(key)`
1133
1174
  - `decodeValue(value)`
1134
1175
  - `encodeKey(key)`
@@ -1235,6 +1276,40 @@ Extends `RangeOptions`.
1235
1276
  - `options: object`
1236
1277
  - `reverse: boolean` When `true`, the iterator will iterate in reverse order. Defaults to `false`.
1237
1278
 
1279
+ ## CLI
1280
+
1281
+ The `rocksdb-js` CLI is a command line interface for interacting with RocksDB databases.
1282
+
1283
+ ```bash
1284
+ rocksdb-js [dbpath]
1285
+ ```
1286
+
1287
+ Options:
1288
+
1289
+ - `-h, --help` Show this help message
1290
+ - `-r, --readonly` Open the database in read-only mode
1291
+ - `-v, --version` Show the version information
1292
+
1293
+ Available commands:
1294
+
1295
+ - `clear` Clear all data in the current column family
1296
+ - `columns` List column families
1297
+ - `compact` Compact the current column family
1298
+ - `count` Count the number of keys in the current column family
1299
+ - `drop <column>` Permanently drop a column family
1300
+ - `exit` Exit the REPL
1301
+ - `get <key>` Get the value of a key
1302
+ - `help` Show this help message
1303
+ - `log [name] [file] [entry]` List the transaction log store names and log store files
1304
+ - `prop <key>` Get a RocksDB property (try "rocksdb.stats")
1305
+ - `purge-logs <name>` Purge transaction log files older than 3 days
1306
+ - `put <key> <value>` Set the value of a key
1307
+ - `query [start] [end]` Query a range of keys
1308
+ - `remove <key>` Delete a key
1309
+ - `repl` Open a JS sub-REPL; "db" refers to the current column family
1310
+ - `stats` Show the statistics for the current column family
1311
+ - `use [column]` Create a new column family or switch to an existing one
1312
+
1238
1313
  ## Development
1239
1314
 
1240
1315
  This package requires Node.js 18 or higher, pnpm, and a C++ compiler.