Skip to content

Commit bfb9feb

Browse files
Add Store.isOpen.
1 parent a042da7 commit bfb9feb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

objectbox/lib/src/native/store.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ class Store {
274274
}
275275
}
276276

277+
/// Returns if an open store was found for the given directory
278+
/// (i.e. opened before and not yet closed).
279+
static bool isOpen(String directory) {
280+
final cStr = directory.toNativeUtf8();
281+
try {
282+
return C.store_is_open(cStr.cast());
283+
} finally {
284+
malloc.free(cStr);
285+
}
286+
}
287+
277288
/// Returns a store reference you can use to create a new store instance with
278289
/// a single underlying native store. See [Store.fromReference] for more details.
279290
ByteData get reference => _reference;

objectbox/test/basics_test.dart

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

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

0 commit comments

Comments
 (0)