Skip to content

Commit 44d201b

Browse files
Add directoryPath property to Store.
1 parent 573bbf4 commit 44d201b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

objectbox/lib/src/native/store.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class Store {
4444
final _reader = ReaderWithCBuffer();
4545
Transaction? _tx;
4646

47+
/// Path to the database directory.
48+
final String directoryPath;
49+
4750
/// Absolute path to the database directory, used for open check.
4851
final String _absoluteDirectoryPath;
4952

@@ -88,6 +91,7 @@ class Store {
8891
String? macosApplicationGroup})
8992
: _weak = false,
9093
_queriesCaseSensitiveDefault = queriesCaseSensitiveDefault,
94+
directoryPath = _safeDirectoryPath(directory),
9195
_absoluteDirectoryPath =
9296
path.context.canonicalize(_safeDirectoryPath(directory)) {
9397
try {
@@ -114,13 +118,11 @@ class Store {
114118

115119
try {
116120
checkObx(C.opt_model(opt, model.ptr));
117-
if (directory != null && directory.isNotEmpty) {
118-
final cStr = directory.toNativeUtf8();
119-
try {
120-
checkObx(C.opt_directory(opt, cStr.cast()));
121-
} finally {
122-
malloc.free(cStr);
123-
}
121+
final cStr = directoryPath.toNativeUtf8();
122+
try {
123+
checkObx(C.opt_directory(opt, cStr.cast()));
124+
} finally {
125+
malloc.free(cStr);
124126
}
125127
if (maxDBSizeInKB != null && maxDBSizeInKB > 0) {
126128
C.opt_max_db_size_in_kb(opt, maxDBSizeInKB);
@@ -199,6 +201,7 @@ class Store {
199201
{bool queriesCaseSensitiveDefault = true})
200202
// must not close the same native store twice so [_weak]=true
201203
: _weak = true,
204+
directoryPath = '',
202205
_absoluteDirectoryPath = '',
203206
_queriesCaseSensitiveDefault = queriesCaseSensitiveDefault {
204207
// see [reference] for serialization order
@@ -231,6 +234,7 @@ class Store {
231234
// _weak = false so store can be closed.
232235
: _weak = false,
233236
_queriesCaseSensitiveDefault = queriesCaseSensitiveDefault,
237+
directoryPath = _safeDirectoryPath(directoryPath),
234238
_absoluteDirectoryPath =
235239
path.context.canonicalize(_safeDirectoryPath(directoryPath)) {
236240
try {
@@ -240,12 +244,12 @@ class Store {
240244
// overlap.
241245
_checkStoreDirectoryNotOpen();
242246

243-
final path = _safeDirectoryPath(directoryPath);
244-
final pathCStr = path.toNativeUtf8();
247+
final pathCStr = this.directoryPath.toNativeUtf8();
245248
try {
246249
if (debugLogs) {
247250
final isOpen = C.store_is_open(pathCStr.cast());
248-
print('Attaching to store... path=$path isOpen=$isOpen');
251+
print(
252+
'Attaching to store... path=${this.directoryPath} isOpen=$isOpen');
249253
}
250254
_cStore = C.store_attach(pathCStr.cast());
251255
} finally {

0 commit comments

Comments
 (0)