Skip to content

Commit 8e7f7dc

Browse files
committed
Expose db.status prop
1 parent 9960ba0 commit 8e7f7dc

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ RocksDatabase.config({
9191
});
9292
```
9393

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+
94114
### `db.open(): RocksDatabase`
95115

96116
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
108128
const db = RocksDatabase.open('path/to/db');
109129
```
110130

111-
### `db.name: string`
131+
### `db.status: 'opened' | 'closed'`
112132

113-
Returns the database column family's name.
133+
Returns a string `'opened'` or `'closed'` indicating if the database is opened or closed.
114134

115135
```typescript
116-
const db = new RocksDatabase('path/to/db');
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);
121137
```
122138

123139
## Data Operations

src/database.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,13 @@ export class RocksDatabase extends DBI<DBITransactional> {
443443
return this.store.db.purgeLogs(options);
444444
}
445445

446+
/**
447+
* The status of the database.
448+
*/
449+
get status(): 'open' | 'closed' {
450+
return this.store.isOpen() ? 'open' : 'closed';
451+
}
452+
446453
/**
447454
* Executes all operations in the callback as a single transaction.
448455
*

0 commit comments

Comments
 (0)