Skip to content

Commit b733f30

Browse files
authored
Merge pull request #86 from objectbox/dev
v0.6.0 Release
2 parents 770cdb8 + c4f12e9 commit b733f30

File tree

91 files changed

+1747
-1030
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1747
-1030
lines changed

.github/workflows/dart.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ jobs:
99
image: google/dart:latest
1010
steps:
1111
- uses: actions/checkout@v1
12-
- name: Install dependencies
13-
working-directory: generator
14-
run: pub get
12+
- name: Install ObjectBox C-API
13+
run: ./install.sh
1514
- name: Run tests
16-
working-directory: generator
17-
run: pub run test
15+
run: ./generator/test.sh
1816

1917
lib:
2018
needs: generator

.gitignore

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
**/.dart_tool/
22
**/.packages
3-
**/build/
3+
**/.pub/
44
**/pubspec.lock
5-
misc/
5+
**/build/
6+
7+
.DS_Store
68
.idea/
9+
.vscode/
10+
711
download/
812
lib/*.dll
913
lib/*.dylib
1014
lib/*.so
1115
lib/*.a
12-
.vscode/
16+
1317
**/*.g.dart
14-
doc/api

CHANGELOG.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
0.6.0 (2019-12-19)
2+
------------------
3+
* Flutter iOS support
4+
* Generator fixes and rework to support multiple entity files in addition to many entities in a single file.
5+
Please move `objectbox-model.json` to `lib/` before running the generator.
6+
* Simplified Android support (automatic dependency).
7+
* Docs improvements
8+
* Updated to objectbox-c 0.8.1
9+
110
0.5.0 (2019-11-18)
211
------------------
312
* 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.
13+
Please keep using 0.4 if you're on Dart 2.5/Flutter 1.9.
514
(thanks [Jasm Sison](https://github.com/Buggaboo) for [#57](https://github.com/objectbox/objectbox-dart/pull/57))
615
* Docs fixes & improvements
716

README.md

+16-49
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,34 @@ ObjectBox for Dart is a standalone database storing Dart objects locally, with s
55
Flutter/Dart compatibility
66
--------------------------
77
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).
8+
However, it has changed significantly in Dart 2.6/Flutter 1.12, 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.12+.
1010

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.
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 the
12+
latest 0.4.x version instead.
1513

1614
Installation
1715
------------
1816
Add the following dependencies to your `pubspec.yaml`:
1917
```yaml
2018
dependencies:
21-
objectbox: ^0.5.0
19+
objectbox: ^0.6.0
2220

2321
dev_dependencies:
2422
build_runner: ^1.0.0
25-
objectbox_generator: ^0.5.0
23+
objectbox_generator: ^0.6.0
2624
```
2725
2826
Proceed based on whether you're developing a Flutter app or a standalone dart program:
2927
1. **Flutter** only steps:
3028
* Install the packages `flutter pub get`
31-
* Add `objectbox-android` dependency to your `android/app/build.gradle`
32-
```
33-
dependencies {
34-
implementation "io.objectbox:objectbox-android:2.4.1"
35-
...
36-
```
37-
* iOS coming soon
29+
* Note: only debug versions (e.g. `flutter run`) work at the moment, `flutter build` currently fails for release builds
3830
1. **Dart standalone programs**:
3931
* Install the packages `pub get`
4032
* Install [objectbox-c](https://github.com/objectbox/objectbox-c) system-wide:
4133
* macOS/Linux: execute the following command (answer Y when it asks about installing to /usr/lib)
4234
```shell script
43-
bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh) 0.7.2
35+
bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/master/install.sh)
4436
```
4537
* macOS: if dart later complains that it cannot find the `libobjectbox.dylib` you probably have to unsign the
4638
`dart` binary (source: [dart issue](https://github.com/dart-lang/sdk/issues/38314#issuecomment-534102841)):
@@ -49,7 +41,7 @@ Proceed based on whether you're developing a Flutter app or a standalone dart pr
4941
```
5042
* Windows: use "Git Bash" or similar to execute the following command
5143
```shell script
52-
bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh) 0.7.2
44+
bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/master/install.sh)
5345
```
5446
Then copy the downloaded `lib/objectbox.dll` to `C:\Windows\System32\` (requires admin privileges).
5547

@@ -59,52 +51,28 @@ After you've defined your persisted entities (see below), run `pub run build_run
5951
Getting started
6052
----------------
6153
In general, Dart class annotations are used to mark classes as ObjectBox entities and provide meta information.
62-
Note that right now, only a limited set of types is supported; this will be expanded upon in the near future.
6354
Entity IDs and UIDs that are defined in their respective annotations need to be unique across all entities, while
6455
property IDs only need to be unique in their respective entity; property UIDs also need to be globally unique.
6556

66-
### Object IDs
67-
68-
Each entity is required to have an _Id_ property of type _Long_.
57+
Each entity is required to have an ID property of type `int`.
6958
Already persisted entities have an ID greater or equal to 1.
70-
New (not yet persisted) objects typically have _Id_ value of `0` or `null`: calling `Box.put` automatically assigns a new ID to the object.
59+
New (not yet persisted) objects typically have ID value of `0` or `null`: calling `Box.put` automatically assigns a new ID to the object.
7160

7261
### Example
62+
For a code example, see [example/README.md](example/README.md)
7363

64+
### Box
65+
Box is your main interface for storing and retrieving data.
7466
```dart
75-
import "package:objectbox/objectbox.dart";
76-
part "note.g.dart";
77-
78-
@Entity()
79-
class Note {
80-
@Id() // automatically always 'int' in Dart code and 'Long' in ObjectBox
81-
int id;
82-
83-
String text;
84-
85-
Note(); // empty default constructor needed
86-
Note.construct(this.text);
87-
toString() => "Note{id: $id, text: $text}";
88-
}
89-
```
90-
91-
In your main function, you can then create a _store_ which needs an array of your entity classes and definitions to be constructed. If you have several entities, construct your store like `Store([[Entity1, Entity1_OBXDefs], [Entity2, Entity2_OBXDefs]])` etc.
92-
Finally, you need a _box_, representing the interface for objects of one specific entity type.
93-
94-
```dart
95-
var store = Store([Note_OBXDefs]);
9667
var box = Box<Note>(store);
97-
98-
var note = Note.construct("Hello");
68+
69+
var note = Note(text: "Hello");
9970
note.id = box.put(note);
10071
print("new note got id ${note.id}");
10172
print("refetched note: ${box.get(note.id)}");
102-
103-
store.close();
10473
```
10574

10675
### Query and QueryBuilder
107-
10876
Basic querying can be done with e.g.:
10977

11078
```dart
@@ -137,7 +105,6 @@ box.query(overloaded as Condition).build(); // the cast is necessary due to the
137105
```
138106

139107
### Ordering
140-
141108
The results from a query can be ordered using the `order` method, e.g.
142109

143110
```dart

android/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Contents of this folder is based on `flutter create --template=plugin`.
2+
It was reduced to the minimum that works for library inclusion by client apps.
3+
4+
Notably, the package depends on `io.objectbox:objectbox-android`, a native ObjectBox library distribution.

android/build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apply plugin: 'com.android.library'
2+
android {
3+
compileSdkVersion 28
4+
}
5+
6+
dependencies {
7+
implementation "io.objectbox:objectbox-android:2.5.0"
8+
}

android/settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'objectbox'

android/src/main/AndroidManifest.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.objectbox.flutter">
3+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package io.objectbox.flutter
2+
3+
class ObjectboxPlugin {
4+
}

doc/code-generation.md

-37
This file was deleted.

doc/modelinfo.md

-17
This file was deleted.

example/README.md

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,54 @@
11
ObjectBox Examples
22
==========================
33

4-
* [Flutter android app](flutter/objectbox_demo) - requires Flutter 1.9
4+
In the following file, e.g. `models.dart`, we import objectbox.dart to get definitions for `@Entity`,
5+
`@Id` and other annotations and define a single entity that should be persisted by ObjectBox. You could have multiple
6+
entities in the same file or you can have them spread across multiple files in the `lib` directory tree.
7+
8+
```dart
9+
import "package:objectbox/objectbox.dart";
10+
11+
@Entity()
12+
class Note {
13+
@Id() // required; stored as a 64-bit unsigned integer in ObjectBox
14+
int id;
15+
String text;
16+
17+
Note({this.text}); // empty default constructor needed but it can have optional args
18+
toString() => "Note{id: $id, text: $text}";
19+
}
20+
```
21+
22+
ObjectBox generator will look for all `@Entity` annotations in your `lib` folder and create a single database definition
23+
`lib/objectbox-model.json` and supporting code in `lib/objectbox.g.dart`.
24+
You should commit `objectbox-model.json` into your source control (e.g. git) and add `objectbox.g.dart` to the ignore
25+
list (e.g. .gitignore), otherwise the build_runner will complain about it being changed each time you pull a change.
26+
27+
Note: the generator will process `lib` and `test` folders separately and create a separate database in each one, if it
28+
finds annotations there. This is useful if you need a separate test DB, but if you're just writing tests for your own
29+
code you won't have any annotations in the `test` folder so no DB will be created there.
30+
31+
-------------------
32+
33+
To use ObjectBox and store the just defined entity, you should import `objectbox.g.dart` and create the `Store`.
34+
Finally, you will create a `Box<Note>` which gives you a typed interface for storing and retrieving `Note` objects.
35+
36+
```dart
37+
import 'objectbox.g.dart'; // this file will be generated by ObjectBox after running `pub run build_runner build`
38+
39+
void main() {
40+
var store = Store(getObjectBoxModel()); // Note: getObjectBoxModel() is generated for you in objectbox.g.dart
41+
var box = Box<Note>(store);
42+
43+
var note = Note(text: "Hello");
44+
note.id = box.put(note);
45+
print("new note got id ${note.id}");
46+
print("refetched note: ${box.get(note.id)}");
47+
48+
store.close();
49+
}
50+
```
51+
52+
See also
53+
--------
54+
* sample [Flutter android app](flutter/objectbox_demo) - requires Flutter 1.12

example/flutter/objectbox_demo/android/app/build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ android {
3737
}
3838

3939
defaultConfig {
40-
applicationId "io.objectbox.flutterexample"
40+
applicationId "com.example.objectbox_demo"
4141
minSdkVersion 16
4242
targetSdkVersion 28
4343
versionCode flutterVersionCode.toInteger()
@@ -59,7 +59,6 @@ flutter {
5959
}
6060

6161
dependencies {
62-
implementation "io.objectbox:objectbox-android:2.4.1"
6362
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
6463
testImplementation 'junit:junit:4.12'
6564
androidTestImplementation 'androidx.test:runner:1.1.1'

example/flutter/objectbox_demo/android/app/src/debug/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="io.objectbox.flutterexample">
2+
package="com.example.objectbox_demo">
33
<!-- Flutter needs it to communicate with the running application
44
to allow setting breakpoints, to provide hot reload, etc.
55
-->

example/flutter/objectbox_demo/android/app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="io.objectbox.flutterexample">
2+
package="com.example.objectbox_demo">
33
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
44
calls FlutterMain.startInitialization(this); in its onCreate method.
55
In most cases you can leave this as-is, but you if you want to provide
@@ -13,7 +13,7 @@
1313
android:name=".MainActivity"
1414
android:launchMode="singleTop"
1515
android:theme="@style/LaunchTheme"
16-
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
16+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1717
android:hardwareAccelerated="true"
1818
android:windowSoftInputMode="adjustResize">
1919
<!-- This keeps the window background of the activity showing

0 commit comments

Comments
 (0)