Skip to content

Commit 61223c4

Browse files
authored
Merge pull request #71 from objectbox/dev
v0.5.0 release
2 parents 80cca76 + 15becba commit 61223c4

16 files changed

+195
-193
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ lib/*.so
1111
lib/*.a
1212
.vscode/
1313
**/*.g.dart
14+
doc/api

CHANGELOG.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
0.5.0 (2019-11-18)
2+
------------------
3+
* Dart 2.6 support - breaking change due to Dart 2.6 FFI changes.
4+
Please keep using 0.4 if you're on Dart 2.5 or Flutter. Currently no Flutter version comes with Dart 2.6 final.
5+
(thanks [Jasm Sison](https://github.com/Buggaboo) for [#54](https://github.com/objectbox/objectbox-dart/pull/57))
6+
* Docs fixes & improvements
7+
18
0.4.0 (2019-10-31)
29
------------------
310
* Flutter Android support
411
* Queries for all currently supported types
5-
(thanks [Jasm Sison](https://github.com/Buggaboo) for [#27](https://github.com/objectbox/objectbox-dart/pull/27) and [#46](https://github.com/objectbox/objectbox-dart/pull/46)]
12+
(thanks [Jasm Sison](https://github.com/Buggaboo) for [#27](https://github.com/objectbox/objectbox-dart/pull/27) and [#46](https://github.com/objectbox/objectbox-dart/pull/46))
613
* More Box functions (count, isEmpty, contains, remove and their bulk variants)
7-
(thanks [liquidiert](https://github.com/liquidiert) for [#42](https://github.com/objectbox/objectbox-dart/pull/42) and [#45](https://github.com/objectbox/objectbox-dart/pull/45)]
14+
(thanks [liquidiert](https://github.com/liquidiert) for [#42](https://github.com/objectbox/objectbox-dart/pull/42) and [#45](https://github.com/objectbox/objectbox-dart/pull/45))
815
* Explicit write transactions
9-
(thanks [liquidiert](https://github.com/liquidiert) for [#50](https://github.com/objectbox/objectbox-dart/pull/50)]
16+
(thanks [liquidiert](https://github.com/liquidiert) for [#50](https://github.com/objectbox/objectbox-dart/pull/50))
1017
* Resolved linter issues
11-
(thanks [Gregory Sech](https://github.com/GregorySech) for [#31](https://github.com/objectbox/objectbox-dart/pull/31)]
18+
(thanks [Gregory Sech](https://github.com/GregorySech) for [#31](https://github.com/objectbox/objectbox-dart/pull/31))
1219
* Updated to objectbox-c 0.7.2
1320
* First release on pub.dev
1421

@@ -17,12 +24,12 @@
1724
* ID/UID generation and model persistence (objectbox-model.json)
1825
* CI tests using GitHub Actions
1926
* Code cleanup, refactoring and formatting
20-
(thanks [Jasm Sison](https://github.com/Buggaboo) for [#20](https://github.com/objectbox/objectbox-dart/pull/20) & [#21](https://github.com/objectbox/objectbox-dart/pull/21)]
27+
(thanks [Jasm Sison](https://github.com/Buggaboo) for [#20](https://github.com/objectbox/objectbox-dart/pull/20) & [#21](https://github.com/objectbox/objectbox-dart/pull/21))
2128

2229
0.2.0 (2019-09-11)
23-
------------------Buggaboo
30+
------------------
2431
* UTF-8 support for Store and Box
25-
(thanks to [Jasm Sison](https://github.com/Buggaboo) for [#14](https://github.com/objectbox/objectbox-dart/pull/14)!)
32+
(thanks [Jasm Sison](https://github.com/Buggaboo) for [#14](https://github.com/objectbox/objectbox-dart/pull/14)!)
2633
* Bulk put and get functions (getMany, getAll, putMany)
2734
* Updated to objectbox-c 0.7
2835
* Basic Store options

README.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@ ObjectBox for Dart/Flutter
22
==========================
33
ObjectBox for Dart is a standalone database storing Dart objects locally, with strong ACID semantics.
44

5+
Flutter/Dart compatibility
6+
--------------------------
7+
This library depends on a new Dart feature, FFI, introduced in Dart 2.5 (Flutter 1.9) as a feature preview.
8+
However, it has been change significantly significantly in Dart 2.6 (future Flutter 1.10.x), i.e. introduced breaking changes we had to reflect.
9+
Versions starting with ObjectBox 0.5 support Dart 2.6 as well as Flutter 1.10 (when it's finally released).
10+
11+
The last supported version for Flutter 1.9/Dart 2.5 is ObjectBox 0.4.*, so if you can't upgrade yet, please use latest 0.4.x version instead.
12+
For Flutter users, this is the only option, as long as a new version of Flutter (1.10), including Dart 2.6 is released.
13+
14+
If you're developing standalone/non-flutter dart programs, you can already use Dart 2.6 with the latest ObjectBox version.
15+
516
Installation
617
------------
718
Add the following dependencies to your `pubspec.yaml`:
819
```yaml
920
dependencies:
10-
objectbox: ^0.4.0
21+
objectbox: ^0.5.0
1122

1223
dev_dependencies:
1324
build_runner: ^1.0.0
14-
objectbox_generator: ^0.4.0
25+
objectbox_generator: ^0.5.0
1526
```
1627
1728
Proceed based on whether you're developing a Flutter app or a standalone dart program:
@@ -34,7 +45,7 @@ Proceed based on whether you're developing a Flutter app or a standalone dart pr
3445
* macOS: if dart later complains that it cannot find the `libobjectbox.dylib` you probably have to unsign the
3546
`dart` binary (source: [dart issue](https://github.com/dart-lang/sdk/issues/38314#issuecomment-534102841)):
3647
```shell script
37-
sudo xcode --remove-signature $(which dart)
48+
sudo codesign --remove-signature $(which dart)
3849
```
3950
* Windows: use "Git Bash" or similar to execute the following command
4051
```shell script
@@ -111,17 +122,17 @@ queryNullText.close(); // We have to manually close queries and query builders.
111122
```
112123

113124
More complex queries can be constructed using `and/or` operators.
114-
Also there is basic operator overloading support for `equal`, `greater`, `less`, `and` and `or`,
115-
respectively `==`, `>`, `<`, `&`, `|`.
125+
Also there is basic operator overloading support for `greater`, `less`, `and` and `or`,
126+
respectively `>`, `<`, `&`, `|`.
116127

117128
```dart
118129
// final box ...
119130
120-
box.query(value.greaterThan(10).or(date.IsNull())).build();
131+
box.query(value.greaterThan(10).or(date.isNull())).build();
121132
122133
// equivalent to
123134
124-
final overloaded = (value > 10) | date.IsNull();
135+
final overloaded = (value > 10) | date.isNull();
125136
box.query(overloaded as Condition).build(); // the cast is necessary due to the type analyzer
126137
```
127138

@@ -137,7 +148,7 @@ final q = box.query(Entity_.number > 0)
137148
// ...
138149
139150
final qt = box.query(Entity_.text.notNull())
140-
.order(Entity_.text, flags: OBXOrderFlag.DESCENDING | OBXOrderFlag.CASE_SENSITIVE)
151+
.order(Entity_.text, flags: Order.descending | Order.caseSensitive)
141152
.build();
142153
```
143154

generator/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: objectbox_generator
2-
version: 0.4.0
2+
version: 0.5.0
33
repository: https://github.com/objectbox/objectbox-dart
44
homepage: https://objectbox.io
55
author: objectbox.io
@@ -9,7 +9,7 @@ environment:
99
sdk: ">=2.5.0 <3.0.0"
1010

1111
dependencies:
12-
objectbox: 0.4.0
12+
objectbox: 0.5.0
1313
build: ^1.0.0
1414
source_gen: ^0.9.0
1515
analyzer: ">=0.35.0 <0.100.0"

lib/objectbox.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
library objectbox;
22

3-
export "dart:io"; // needed for generated files
4-
export "dart:convert";
5-
63
export "src/annotations.dart";
74
export "src/common.dart";
85
export "src/model.dart";

lib/src/bindings/bindings.dart

+19-18
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ class _ObjectBoxBindings {
1313
// common functions
1414
void Function(Pointer<Int32> major, Pointer<Int32> minor, Pointer<Int32> patch) obx_version;
1515
Pointer<Uint8> Function() obx_version_string;
16-
void Function(Pointer<Uint64> structPtr) obx_string_array_free,
17-
obx_int64_array_free,
18-
obx_int32_array_free,
19-
obx_int16_array_free,
20-
obx_int8_array_free,
21-
obx_double_array_free,
22-
obx_float_array_free;
23-
obx_free_t<OBX_bytes_array> obx_bytes_array_free;
24-
obx_free_t<OBX_id_array> obx_id_array_free;
16+
17+
obx_free_dart_t<OBX_bytes_array> obx_bytes_array_free;
18+
obx_free_dart_t<OBX_id_array> obx_id_array_free;
19+
// obx_free_dart_t<OBX__array> obx_string_array_free;
20+
// obx_free_dart_t<OBX__array> obx_int64_array_free;
21+
// obx_free_dart_t<OBX__array> obx_int32_array_free;
22+
// obx_free_dart_t<OBX__array> obx_int16_array_free;
23+
// obx_free_dart_t<OBX__array> obx_int8_array_free;
24+
// obx_free_dart_t<OBX__array> obx_double_array_free;
25+
// obx_free_dart_t<OBX__array> obx_float_array_free;
2526

2627
// error info
2728
int Function() obx_last_error_code;
@@ -154,15 +155,15 @@ class _ObjectBoxBindings {
154155
// common functions
155156
obx_version = _fn<obx_version_native_t>("obx_version").asFunction();
156157
obx_version_string = _fn<obx_version_string_native_t>("obx_version_string").asFunction();
157-
obx_bytes_array_free = _fn<obx_free_t<OBX_bytes_array>>("obx_bytes_array_free").asFunction();
158-
obx_id_array_free = _fn<obx_free_t<OBX_id_array>>("obx_id_array_free").asFunction();
159-
obx_string_array_free = _fn<obx_free_struct_native_t>("obx_string_array_free").asFunction();
160-
obx_int64_array_free = _fn<obx_free_struct_native_t>("obx_int64_array_free").asFunction();
161-
obx_int32_array_free = _fn<obx_free_struct_native_t>("obx_int32_array_free").asFunction();
162-
obx_int16_array_free = _fn<obx_free_struct_native_t>("obx_int16_array_free").asFunction();
163-
obx_int8_array_free = _fn<obx_free_struct_native_t>("obx_int8_array_free").asFunction();
164-
obx_double_array_free = _fn<obx_free_struct_native_t>("obx_double_array_free").asFunction();
165-
obx_float_array_free = _fn<obx_free_struct_native_t>("obx_float_array_free").asFunction();
158+
obx_bytes_array_free = _fn<obx_free_native_t<Pointer<OBX_bytes_array>>>("obx_bytes_array_free").asFunction();
159+
obx_id_array_free = _fn<obx_free_native_t<Pointer<OBX_id_array>>>("obx_id_array_free").asFunction();
160+
// obx_string_array_free = _fn<obx_free_native_t<Pointer<>>>("obx_string_array_free").asFunction();
161+
// obx_int64_array_free = _fn<obx_free_native_t<Pointer<>>>("obx_int64_array_free").asFunction();
162+
// obx_int32_array_free = _fn<obx_free_native_t<Pointer<>>>("obx_int32_array_free").asFunction();
163+
// obx_int16_array_free = _fn<obx_free_native_t<Pointer<>>>("obx_int16_array_free").asFunction();
164+
// obx_int8_array_free = _fn<obx_free_native_t<Pointer<>>>("obx_int8_array_free").asFunction();
165+
// obx_double_array_free = _fn<obx_free_native_t<Pointer<>>>("obx_double_array_free").asFunction();
166+
// obx_float_array_free = _fn<obx_free_native_t<Pointer<>>>("obx_float_array_free").asFunction();
166167

167168
// error info
168169
obx_last_error_code = _fn<obx_last_error_code_native_t>("obx_last_error_code").asFunction();

lib/src/bindings/flatbuffers.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class OBXFlatbuffersManager<T> {
136136

137137
// expects pointer to OBX_bytes_array and manually resolves its contents (see objectbox.h)
138138
List<T> unmarshalArray(final Pointer<OBX_bytes_array> bytesArray, {bool allowMissing = false}) {
139-
final OBX_bytes_array array = bytesArray.load();
139+
final OBX_bytes_array array = bytesArray.ref;
140140
var fn = (OBX_bytes b) => unmarshal(b.data);
141141
if (allowMissing) {
142142
fn = (OBX_bytes b) => b.isEmpty ? null : unmarshal(b.data);

lib/src/bindings/signatures.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import 'structs.dart';
66
// common functions
77
typedef obx_version_native_t = Void Function(Pointer<Int32> major, Pointer<Int32> minor, Pointer<Int32> patch);
88
typedef obx_version_string_native_t = Pointer<Uint8> Function();
9-
typedef obx_free_t<T extends NativeType> = Void Function(Pointer<T> ptr);
10-
typedef obx_free_struct_native_t = Void Function(Pointer<Uint64> structPtr);
9+
10+
typedef obx_free_dart_t<T extends NativeType> = void Function(Pointer<T> ptr);
11+
typedef obx_free_native_t<T extends NativeType> = Void Function(T ptr); // no Pointer<T>, code analysis fails on usage
1112

1213
// error info
1314
typedef obx_last_error_code_native_t = Int32 Function();

lib/src/bindings/structs.dart

+22-65
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:ffi';
2-
import "dart:typed_data" show Uint8List, Uint64List;
2+
import "dart:typed_data" show Uint8List;
3+
import "package:ffi/ffi.dart" show allocate, free;
34

45
import '../common.dart';
56

@@ -10,34 +11,34 @@ import '../common.dart';
1011
/// obx_id* ids;
1112
/// size_t count;
1213
/// };
13-
class OBX_id_array extends Struct<OBX_id_array> {
14+
class OBX_id_array extends Struct {
1415
Pointer<Uint64> _itemsPtr;
1516

1617
@IntPtr() // size_t
1718
int length;
1819

1920
/// Get a copy of the list
20-
List<int> items() => Uint64List.view(_itemsPtr.asExternalTypedData(count: length).buffer).toList();
21+
List<int> items() => _itemsPtr.asTypedList(length);
2122

2223
/// Execute the given function, managing the resources consistently
2324
static R executeWith<R>(List<int> items, R Function(Pointer<OBX_id_array>) fn) {
2425
// allocate a temporary structure
25-
final ptr = Pointer<OBX_id_array>.allocate();
26+
final ptr = allocate<OBX_id_array>();
2627

2728
// fill it with data
28-
OBX_id_array array = ptr.load();
29+
OBX_id_array array = ptr.ref;
2930
array.length = items.length;
30-
array._itemsPtr = Pointer<Uint64>.allocate(count: array.length);
31+
array._itemsPtr = allocate<Uint64>(count: array.length);
3132
for (int i = 0; i < items.length; ++i) {
32-
array._itemsPtr.elementAt(i).store(items[i]);
33+
array._itemsPtr.elementAt(i).value = items[i];
3334
}
3435

3536
// call the function with the structure and free afterwards
3637
try {
3738
return fn(ptr);
3839
} finally {
39-
array._itemsPtr.free();
40-
ptr.free();
40+
free(array._itemsPtr);
41+
free(ptr);
4142
}
4243
}
4344
}
@@ -47,16 +48,15 @@ class OBX_id_array extends Struct<OBX_id_array> {
4748
/// const void* data;
4849
/// size_t size;
4950
/// };
50-
class OBX_bytes extends Struct<OBX_bytes> {
51+
class OBX_bytes extends Struct {
5152
Pointer<Uint8> _dataPtr;
5253

5354
@IntPtr() // size_t
5455
int length;
5556

5657
/// Get access to the data (no-copy)
57-
Uint8List get data => isEmpty
58-
? throw ObjectBoxException("can't access data of empty OBX_bytes")
59-
: Uint8List.view(_dataPtr.asExternalTypedData(count: length).buffer);
58+
Uint8List get data =>
59+
isEmpty ? throw ObjectBoxException("can't access data of empty OBX_bytes") : _dataPtr.asTypedList(length);
6060

6161
bool get isEmpty => length == 0 || _dataPtr.address == 0;
6262

@@ -65,8 +65,8 @@ class OBX_bytes extends Struct<OBX_bytes> {
6565
/// Returns a pointer to OBX_bytes with copy of the passed data.
6666
/// Warning: this creates an two unmanaged pointers which must be freed manually: OBX_bytes.freeManaged(result).
6767
static Pointer<OBX_bytes> managedCopyOf(Uint8List data) {
68-
final ptr = Pointer<OBX_bytes>.allocate();
69-
final OBX_bytes bytes = ptr.load();
68+
final ptr = allocate<OBX_bytes>();
69+
final OBX_bytes bytes = ptr.ref;
7070

7171
const align = true; // ObjectBox requires data to be aligned to the length of 4
7272
bytes.length = align ? ((data.length + 3.0) ~/ 4.0) * 4 : data.length;
@@ -79,19 +79,19 @@ class OBX_bytes extends Struct<OBX_bytes> {
7979
// }
8080

8181
// create a copy of the data
82-
bytes._dataPtr = Pointer<Uint8>.allocate(count: bytes.length);
82+
bytes._dataPtr = allocate<Uint8>(count: bytes.length);
8383
for (int i = 0; i < data.length; ++i) {
84-
bytes._dataPtr.elementAt(i).store(data[i]);
84+
bytes._dataPtr.elementAt(i).value = data[i];
8585
}
8686

8787
return ptr;
8888
}
8989

9090
/// Free a dart-created OBX_bytes pointer.
9191
static void freeManaged(Pointer<OBX_bytes> ptr) {
92-
final OBX_bytes bytes = ptr.load();
93-
bytes._dataPtr.free();
94-
ptr.free();
92+
final OBX_bytes bytes = ptr.ref;
93+
free(bytes._dataPtr);
94+
free(ptr);
9595
}
9696
}
9797

@@ -100,7 +100,7 @@ class OBX_bytes extends Struct<OBX_bytes> {
100100
/// OBX_bytes* bytes;
101101
/// size_t count;
102102
/// };
103-
class OBX_bytes_array extends Struct<OBX_bytes_array> {
103+
class OBX_bytes_array extends Struct {
104104
Pointer<OBX_bytes> _items;
105105

106106
@IntPtr() // size_t
@@ -110,51 +110,8 @@ class OBX_bytes_array extends Struct<OBX_bytes_array> {
110110
List<OBX_bytes> items() {
111111
final result = List<OBX_bytes>();
112112
for (int i = 0; i < length; i++) {
113-
result.add(_items.elementAt(i).load());
113+
result.add(_items.elementAt(i).ref);
114114
}
115115
return result;
116116
}
117-
118-
/// TODO: try this with new Dart 2.6 FFI... with the previous versions it was causing memory corruption issues.
119-
/// It's supposed to be used by PutMany()
120-
// /// Create a dart-managed OBX_bytes_array.
121-
// static Pointer<OBX_bytes_array> createManaged(int count) {
122-
// final ptr = Pointer<OBX_bytes_array>.allocate();
123-
// final OBX_bytes_array array = ptr.load();
124-
// array.length = count;
125-
// array._items = Pointer<OBX_bytes>.allocate(count: count);
126-
// return ptr;
127-
// }
128-
//
129-
// /// Replace the data at the given index with the passed pointer.
130-
// void setAndFree(int i, Pointer<OBX_bytes> src) {
131-
// assert(i >= 0 && i < length);
132-
//
133-
// final OBX_bytes srcBytes = src.load();
134-
// final OBX_bytes tarBytes = _items.elementAt(i).load();
135-
//
136-
// assert(!srcBytes.isEmpty);
137-
// assert(tarBytes.isEmpty);
138-
//
139-
// tarBytes._dataPtr = srcBytes._dataPtr;
140-
// tarBytes.length = srcBytes.length;
141-
//
142-
// srcBytes._dataPtr.store(nullptr.address);
143-
// srcBytes.length = 0;
144-
// src.free();
145-
// }
146-
//
147-
// /// Free a dart-created OBX_bytes pointer.
148-
// static void freeManaged(Pointer<OBX_bytes_array> ptr, bool freeIncludedBytes) {
149-
// final OBX_bytes_array array = ptr.load();
150-
// if (freeIncludedBytes) {
151-
// for (int i = 0; i < array.length; i++) {
152-
// // Calling OBX_bytes.freeManaged() would cause double free
153-
// final OBX_bytes bytes = array._items.elementAt(i).load();
154-
// bytes._dataPtr.free();
155-
// }
156-
// }
157-
// array._items.free();
158-
// ptr.free();
159-
// }
160117
}

0 commit comments

Comments
 (0)