Skip to content

Commit

Permalink
Merge pull request #86 from objectbox/dev
Browse files Browse the repository at this point in the history
v0.6.0 Release
  • Loading branch information
vaind committed Dec 19, 2019
2 parents 770cdb8 + c4f12e9 commit b733f30
Show file tree
Hide file tree
Showing 91 changed files with 1,747 additions and 1,030 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ jobs:
image: google/dart:latest
steps:
- uses: actions/checkout@v1
- name: Install dependencies
working-directory: generator
run: pub get
- name: Install ObjectBox C-API
run: ./install.sh
- name: Run tests
working-directory: generator
run: pub run test
run: ./generator/test.sh

lib:
needs: generator
Expand Down
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
**/.dart_tool/
**/.packages
**/build/
**/.pub/
**/pubspec.lock
misc/
**/build/

.DS_Store
.idea/
.vscode/

download/
lib/*.dll
lib/*.dylib
lib/*.so
lib/*.a
.vscode/

**/*.g.dart
doc/api
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
0.6.0 (2019-12-19)
------------------
* Flutter iOS support
* Generator fixes and rework to support multiple entity files in addition to many entities in a single file.
Please move `objectbox-model.json` to `lib/` before running the generator.
* Simplified Android support (automatic dependency).
* Docs improvements
* Updated to objectbox-c 0.8.1

0.5.0 (2019-11-18)
------------------
* Dart 2.6 support - breaking change due to Dart 2.6 FFI changes.
Please keep using 0.4 if you're on Dart 2.5 or Flutter. Currently no Flutter version comes with Dart 2.6 final.
Please keep using 0.4 if you're on Dart 2.5/Flutter 1.9.
(thanks [Jasm Sison](https://github.com/Buggaboo) for [#57](https://github.com/objectbox/objectbox-dart/pull/57))
* Docs fixes & improvements

Expand Down
65 changes: 16 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,34 @@ ObjectBox for Dart is a standalone database storing Dart objects locally, with s
Flutter/Dart compatibility
--------------------------
This library depends on a new Dart feature, FFI, introduced in Dart 2.5 (Flutter 1.9) as a feature preview.
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.
Versions starting with ObjectBox 0.5 support Dart 2.6 as well as Flutter 1.10 (when it's finally released).
However, it has changed significantly in Dart 2.6/Flutter 1.12, i.e. introduced breaking changes we had to reflect.
Versions starting with ObjectBox 0.5 support Dart 2.6+ as well as Flutter 1.12+.

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.
For Flutter users, this is the only option, as long as a new version of Flutter (1.10), including Dart 2.6 is released.

If you're developing standalone/non-flutter dart programs, you can already use Dart 2.6 with the latest ObjectBox version.
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
latest 0.4.x version instead.

Installation
------------
Add the following dependencies to your `pubspec.yaml`:
```yaml
dependencies:
objectbox: ^0.5.0
objectbox: ^0.6.0

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

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

### Object IDs

Each entity is required to have an _Id_ property of type _Long_.
Each entity is required to have an ID property of type `int`.
Already persisted entities have an ID greater or equal to 1.
New (not yet persisted) objects typically have _Id_ value of `0` or `null`: calling `Box.put` automatically assigns a new ID to the object.
New (not yet persisted) objects typically have ID value of `0` or `null`: calling `Box.put` automatically assigns a new ID to the object.

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

### Box
Box is your main interface for storing and retrieving data.
```dart
import "package:objectbox/objectbox.dart";
part "note.g.dart";
@Entity()
class Note {
@Id() // automatically always 'int' in Dart code and 'Long' in ObjectBox
int id;
String text;
Note(); // empty default constructor needed
Note.construct(this.text);
toString() => "Note{id: $id, text: $text}";
}
```

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.
Finally, you need a _box_, representing the interface for objects of one specific entity type.

```dart
var store = Store([Note_OBXDefs]);
var box = Box<Note>(store);
var note = Note.construct("Hello");
var note = Note(text: "Hello");
note.id = box.put(note);
print("new note got id ${note.id}");
print("refetched note: ${box.get(note.id)}");
store.close();
```

### Query and QueryBuilder

Basic querying can be done with e.g.:

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

### Ordering

The results from a query can be ordered using the `order` method, e.g.

```dart
Expand Down
4 changes: 4 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Contents of this folder is based on `flutter create --template=plugin`.
It was reduced to the minimum that works for library inclusion by client apps.

Notably, the package depends on `io.objectbox:objectbox-android`, a native ObjectBox library distribution.
8 changes: 8 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
}

dependencies {
implementation "io.objectbox:objectbox-android:2.5.0"
}
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'objectbox'
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.objectbox.flutter">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.objectbox.flutter

class ObjectboxPlugin {
}
37 changes: 0 additions & 37 deletions doc/code-generation.md

This file was deleted.

17 changes: 0 additions & 17 deletions doc/modelinfo.md

This file was deleted.

52 changes: 51 additions & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
ObjectBox Examples
==========================

* [Flutter android app](flutter/objectbox_demo) - requires Flutter 1.9
In the following file, e.g. `models.dart`, we import objectbox.dart to get definitions for `@Entity`,
`@Id` and other annotations and define a single entity that should be persisted by ObjectBox. You could have multiple
entities in the same file or you can have them spread across multiple files in the `lib` directory tree.

```dart
import "package:objectbox/objectbox.dart";
@Entity()
class Note {
@Id() // required; stored as a 64-bit unsigned integer in ObjectBox
int id;
String text;
Note({this.text}); // empty default constructor needed but it can have optional args
toString() => "Note{id: $id, text: $text}";
}
```

ObjectBox generator will look for all `@Entity` annotations in your `lib` folder and create a single database definition
`lib/objectbox-model.json` and supporting code in `lib/objectbox.g.dart`.
You should commit `objectbox-model.json` into your source control (e.g. git) and add `objectbox.g.dart` to the ignore
list (e.g. .gitignore), otherwise the build_runner will complain about it being changed each time you pull a change.

Note: the generator will process `lib` and `test` folders separately and create a separate database in each one, if it
finds annotations there. This is useful if you need a separate test DB, but if you're just writing tests for your own
code you won't have any annotations in the `test` folder so no DB will be created there.

-------------------

To use ObjectBox and store the just defined entity, you should import `objectbox.g.dart` and create the `Store`.
Finally, you will create a `Box<Note>` which gives you a typed interface for storing and retrieving `Note` objects.

```dart
import 'objectbox.g.dart'; // this file will be generated by ObjectBox after running `pub run build_runner build`
void main() {
var store = Store(getObjectBoxModel()); // Note: getObjectBoxModel() is generated for you in objectbox.g.dart
var box = Box<Note>(store);
var note = Note(text: "Hello");
note.id = box.put(note);
print("new note got id ${note.id}");
print("refetched note: ${box.get(note.id)}");
store.close();
}
```

See also
--------
* sample [Flutter android app](flutter/objectbox_demo) - requires Flutter 1.12
3 changes: 1 addition & 2 deletions example/flutter/objectbox_demo/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
}

defaultConfig {
applicationId "io.objectbox.flutterexample"
applicationId "com.example.objectbox_demo"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
Expand All @@ -59,7 +59,6 @@ flutter {
}

dependencies {
implementation "io.objectbox:objectbox-android:2.4.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.objectbox.flutterexample">
package="com.example.objectbox_demo">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.objectbox.flutterexample">
package="com.example.objectbox_demo">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
Expand All @@ -13,7 +13,7 @@
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
Expand Down
Loading

0 comments on commit b733f30

Please sign in to comment.