Skip to content

Commit 10a3b70

Browse files
Add possibility to use store options
1 parent 7a759c1 commit 10a3b70

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

objectbox/lib/src/bindings/bindings.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class _ObjectBoxBindings {
2929

3030
// object store management
3131
Pointer<Void> Function() obx_opt;
32+
int Function(Pointer<Void> opt, Pointer<Uint8> dir) obx_opt_directory;
33+
void Function(Pointer<Void> opt, int size_in_kb) obx_opt_max_db_size_in_kb;
34+
void Function(Pointer<Void> opt, int file_mode) obx_opt_file_mode;
35+
void Function(Pointer<Void> opt, int max_readers) obx_opt_max_readers;
3236
int Function(Pointer<Void> opt, Pointer<Void> model) obx_opt_model;
3337
Pointer<Void> Function(Pointer<Void> opt) obx_store_open;
3438
int Function(Pointer<Void> store) obx_store_close;
@@ -83,6 +87,10 @@ class _ObjectBoxBindings {
8387

8488
// object store management
8589
obx_opt = objectbox.lookup<NativeFunction<obx_opt_native_t>>("obx_opt").asFunction();
90+
obx_opt_directory = objectbox.lookup<NativeFunction<obx_opt_directory_native_t>>("obx_opt_directory").asFunction();
91+
obx_opt_max_db_size_in_kb = objectbox.lookup<NativeFunction<obx_opt_max_db_size_in_kb_native_t>>("obx_opt_max_db_size_in_kb").asFunction();
92+
obx_opt_file_mode = objectbox.lookup<NativeFunction<obx_opt_file_mode_native_t>>("obx_opt_file_mode").asFunction();
93+
obx_opt_max_readers = objectbox.lookup<NativeFunction<obx_opt_max_readers_native_t>>("obx_opt_max_readers").asFunction();
8694
obx_opt_model = objectbox.lookup<NativeFunction<obx_opt_model_native_t>>("obx_opt_model").asFunction();
8795
obx_store_open = objectbox.lookup<NativeFunction<obx_store_open_native_t>>("obx_store_open").asFunction();
8896
obx_store_close = objectbox.lookup<NativeFunction<obx_store_close_native_t>>("obx_store_close").asFunction();

objectbox/lib/src/bindings/signatures.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ typedef obx_model_last_entity_id_native_t = Int32 Function(Pointer<Void> model,
2222

2323
// object store management
2424
typedef obx_opt_native_t = Pointer<Void> Function();
25+
typedef obx_opt_directory_native_t = Int32 Function(Pointer<Void> opt, Pointer<Uint8> dir);
26+
typedef obx_opt_max_db_size_in_kb_native_t = Void Function(Pointer<Void> opt, Int32 size_in_kb);
27+
typedef obx_opt_file_mode_native_t = Void Function(Pointer<Void> opt, Int32 file_mode);
28+
typedef obx_opt_max_readers_native_t = Void Function(Pointer<Void> opt, Int32 max_readers);
2529
typedef obx_opt_model_native_t = Int32 Function(Pointer<Void> opt, Pointer<Void> model);
2630
typedef obx_store_open_native_t = Pointer<Void> Function(Pointer<Void> opt);
2731
typedef obx_store_close_native_t = Int32 Function(Pointer<Void> store);

objectbox/lib/src/store.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@ import "dart:ffi";
22

33
import "bindings/bindings.dart";
44
import "bindings/helpers.dart";
5+
import "ffi/cstring.dart";
56

67
import "model.dart";
78

89
class Store {
910
Pointer<Void> _objectboxStore;
1011
Map<Type, Map<String, dynamic>> _modelDefinitions = {};
1112

12-
Store(List<List<dynamic>> defs) { // TODO: allow setting options, e.g. database path
13+
Store(List<List<dynamic>> defs, {String directory, int maxDBSizeInKB, int fileMode, int maxReaders}) { // TODO: allow setting options, e.g. database path
1314
defs.forEach((d) => _modelDefinitions[d[0]] = d[1]);
1415
var model = Model(defs.map((d) => d[1]["model"] as Map<String, dynamic>).toList());
1516

1617
var opt = bindings.obx_opt();
1718
checkObxPtr(opt, "failed to create store options");
1819
checkObx(bindings.obx_opt_model(opt, model.ptr));
20+
if(directory != null && directory.length != 0) {
21+
var cStr = new CString(directory);
22+
checkObx(bindings.obx_opt_directory(opt, cStr.ptr));
23+
cStr.free();
24+
}
25+
if(maxDBSizeInKB != null && maxDBSizeInKB > 0)
26+
bindings.obx_opt_max_db_size_in_kb(opt, maxDBSizeInKB);
27+
if(fileMode != null && fileMode >= 0)
28+
bindings.obx_opt_file_mode(opt, fileMode);
29+
if(maxReaders != null && maxReaders > 0)
30+
bindings.obx_opt_max_readers(opt, maxReaders);
1931
_objectboxStore = bindings.obx_store_open(opt);
2032
checkObxPtr(_objectboxStore, "failed to create store");
2133
}

0 commit comments

Comments
 (0)