Skip to content

Commit 0b9d801

Browse files
Add Store.isOpen.
1 parent a05b707 commit 0b9d801

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

objectbox/lib/src/native/store.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ class Store {
267267
}
268268
}
269269

270+
/// Returns if an open store was found for the given directory
271+
/// (i.e. opened before and not yet closed).
272+
static bool isOpen(String directory) {
273+
final cStr = directory.toNativeUtf8();
274+
try {
275+
return C.store_is_open(cStr.cast());
276+
} finally {
277+
malloc.free(cStr);
278+
}
279+
}
280+
270281
/// Returns a store reference you can use to create a new store instance with
271282
/// a single underlying native store. See [Store.fromReference] for more details.
272283
ByteData get reference => _reference;

objectbox/test/basics_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ void main() {
7777
env.closeAndDelete();
7878
});
7979

80+
test('store is open', () {
81+
expect(false, Store.isOpen(''));
82+
expect(false, Store.isOpen('testdata-basics'));
83+
final env = TestEnv('basics');
84+
expect(true, Store.isOpen('testdata-basics'));
85+
env.closeAndDelete();
86+
expect(false, Store.isOpen('testdata-basics'));
87+
});
88+
8089
test('transactions', () {
8190
final env = TestEnv('basics');
8291
expect(TxMode.values.length, 2);

0 commit comments

Comments
 (0)