Skip to content

Commit b1e016a

Browse files
authored
Merge pull request #32 from objectbox/dev
v0.3.0 release
2 parents d9d6d74 + 3eebaa4 commit b1e016a

File tree

92 files changed

+2656
-1143
lines changed

Some content is hidden

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

92 files changed

+2656
-1143
lines changed

.github/workflows/dart.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Dart CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
generator:
7+
runs-on: ubuntu-latest
8+
container:
9+
image: google/dart:latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Install dependencies
13+
working-directory: bin/objectbox_model_generator
14+
run: pub get
15+
- name: Run tests
16+
working-directory: bin/objectbox_model_generator
17+
run: pub run test
18+
19+
lib:
20+
needs: generator
21+
runs-on: ubuntu-latest
22+
container:
23+
image: google/dart:latest
24+
steps:
25+
- uses: actions/checkout@v1
26+
- name: Install ObjectBox C-API
27+
run: ./install.sh
28+
- name: Install dependencies
29+
run: pub get
30+
- name: Generate ObjectBox models
31+
run: pub run build_runner build
32+
- name: Run tests
33+
run: pub run test

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
**/pubspec.lock
55
misc/
66
.idea/
7+
download/
8+
lib/*.dll
9+
lib/*.dylib
10+
lib/*.so
11+
lib/*.a
12+
.vscode/
713
**/*.g.dart

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
0.3.0 (2019-10-14)
2+
------------------
3+
* ID/UID generation and model persistence (objectbox-model.json)
4+
* CI tests using GitHub Actions
5+
* Code cleanup, refactoring and formatting
6+
(thanks [Buggaboo](https://github.com/Buggaboo) for [#20](https://github.com/objectbox/objectbox-dart/pull/20) & [#21](https://github.com/objectbox/objectbox-dart/pull/21)]
7+
18
0.2.0 (2019-09-11)
29
------------------
3-
* UTF-8 support for Store and Box (thanks to [Buggaboo](https://github.com/Buggaboo) for [#14](https://github.com/objectbox/objectbox-dart/pull/14)!)
10+
* UTF-8 support for Store and Box
11+
(thanks to [Buggaboo](https://github.com/Buggaboo) for [#14](https://github.com/objectbox/objectbox-dart/pull/14)!)
412
* Bulk put and get functions (getMany, getAll, putMany)
513
* Updated to objectbox-c 0.7
614
* Basic Store options

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ However, the ObjectBox core supports many more features, e.g. queries, indexing,
99
To bring all these features to Dart, we're asking the community to help out. PRs are more than welcome!
1010
The ObjectBox team will try its best to guide you and answer questions.
1111

12-
### Open Development Process
13-
12+
Contributing
13+
------------------
1414
This project is completely managed here on GitHub using its [issue tracker](https://github.com/objectbox/objectbox-dart/issues) and [project boards](https://github.com/objectbox/objectbox-dart/projects).
1515

1616
To prepare an upcoming version, we create a (Kanban like) board for it.
@@ -24,30 +24,36 @@ Issues on the board are referred to as "cards" which move from left to right:
2424
* Once a task is considered complete (e.g. PR is made), put it in the "Review" column.
2525
* Once another person had a look and is happy, the task is finally moved to "Done"
2626

27-
Anyone can contribute in this process. Look for tasks having a **"help wanted"** tag.
28-
29-
### Feedback
27+
Anyone can contribute, be it by coding, improving docs or just proposing a new feature.
28+
Look for tasks having a **"help wanted"** tag.
3029

30+
#### Feedback
3131
Also, please let us know your feedback by opening an issue:
3232
for example, if you experience errors or if you have ideas for how to improve the API.
3333
Thanks!
3434

35+
#### Code style
36+
Please make sure that all code submitted via Pull Request is formatted using `dartfmt -l 120`.
37+
You can configure your IDE to do this automatically, e.g. VS Code needs the project-specific settings
38+
`"editor.defaultFormatter": "Dart-Code.dart-code"` and `"dart.lineLength": 120`.
39+
3540
Getting started
3641
---------------
3742
To try out the demo code in this repository, follow these steps:
3843

39-
1. Install [objectbox-c](https://github.com/objectbox/objectbox-c) system-wide: `bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh) 0.7` (answer Y when it asks about installing to /usr/lib).
44+
1. Install [objectbox-c](https://github.com/objectbox/objectbox-c) system-wide:
45+
`bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh) 0.7` (answer Y when it asks about installing to /usr/lib).
4046
2. Back in this repository, run `pub get`.
41-
3. Execute `pub run build_runner build`. This regenerates the ObjectBox model to make it usable in Dart (i.e. the file `test/test.g.dart`) and is necessary each time you add or change a class annotated with `@Entity(...)`.
42-
4. Finally run `pub run test test/test.dart` to run the unit tests.
47+
3. Execute `pub run build_runner build`. This regenerates the ObjectBox model to make it usable in Dart
48+
(i.e. the file `test/test.g.dart`) and is necessary each time you add or change a class annotated with `@Entity(...)`.
49+
4. Finally run `pub run test` to run the unit tests.
4350

4451
Dart integration
4552
----------------
4653
In general, Dart class annotations are used to mark classes as ObjectBox entities and provide meta information.
4754
Note that right now, only a limited set of types is supported; this will be expanded upon in the near future.
48-
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.
49-
50-
All non-annotated class instance variables are ignored by ObjectBox.
55+
Entity IDs and UIDs that are defined in their respective annotations need to be unique across all entities, while
56+
property IDs only need to be unique in their respective entity; property UIDs also need to be globally unique.
5157

5258
### Object IDs
5359

@@ -57,20 +63,15 @@ New (not yet persisted) objects typically have _Id_ value of `0` or `null`: call
5763

5864
### Example
5965

60-
*Note:* specifying the (meta model) IDs in annotations manually is a temporary quick solution.
61-
In a later version, you won't have to do this the and e.g. `@Property(id: 2, uid: 1002)` can be dropped completely.
62-
As specified in step 3 of the _Getting started_ section, Dart's _build\_runner_ and _source\_gen_ are currently used and the generator will be extended to automatically manage the meta model IDs in the future.
63-
6466
```dart
65-
import "../lib/objectbox.dart";
66-
part "test.g.dart";
67+
import "package:objectbox/objectbox.dart";
68+
part "note.g.dart";
6769
68-
@Entity(id: 1, uid: 1)
70+
@Entity()
6971
class Note {
70-
@Id(id: 1, uid: 1001) // automatically always 'int' in Dart code and 'Long' in ObjectBox
72+
@Id() // automatically always 'int' in Dart code and 'Long' in ObjectBox
7173
int id;
7274
73-
@Property(id: 2, uid: 1002)
7475
String text;
7576
7677
Note(); // empty default constructor needed
@@ -83,7 +84,7 @@ In your main function, you can then create a _store_ which needs an array of you
8384
Finally, you need a _box_, representing the interface for objects of one specific entity type.
8485

8586
```dart
86-
var store = Store([[Note, Note_OBXDefs]]);
87+
var store = Store([Note_OBXDefs]);
8788
var box = Box<Note>(store);
8889
8990
var note = Note.construct("Hello");

bin/objectbox_model_generator/lib/builder.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ import "package:build/build.dart";
22
import "package:source_gen/source_gen.dart";
33
import "package:objectbox_model_generator/src/generator.dart";
44

5-
Builder objectboxModelFactory(BuilderOptions options) =>
6-
SharedPartBuilder([EntityGenerator()], "objectbox_model");
5+
Builder objectboxModelFactory(BuilderOptions options) => SharedPartBuilder([EntityGenerator()], "objectbox_model");
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import "package:objectbox/src/modelinfo/index.dart";
2+
3+
class CodeChunks {
4+
static String modelInfoLoader() => """
5+
Map<int, ModelEntity> _allOBXModelEntities = null;
6+
7+
void _loadOBXModelEntities() {
8+
if (FileSystemEntity.typeSync("objectbox-model.json") == FileSystemEntityType.notFound)
9+
throw Exception("objectbox-model.json not found");
10+
11+
_allOBXModelEntities = {};
12+
ModelInfo modelInfo = ModelInfo.fromMap(json.decode(new File("objectbox-model.json").readAsStringSync()));
13+
modelInfo.entities.forEach((e) => _allOBXModelEntities[e.id.uid] = e);
14+
}
15+
16+
ModelEntity _getOBXModelEntity(int entityUid) {
17+
if (_allOBXModelEntities == null) _loadOBXModelEntities();
18+
if (!_allOBXModelEntities.containsKey(entityUid))
19+
throw Exception("entity uid missing in objectbox-model.json: \$entityUid");
20+
return _allOBXModelEntities[entityUid];
21+
}
22+
""";
23+
24+
static String instanceBuildersReaders(ModelEntity readEntity) {
25+
String name = readEntity.name;
26+
return """
27+
ModelEntity _${name}_OBXModelGetter() {
28+
return _getOBXModelEntity(${readEntity.id.uid});
29+
}
30+
31+
$name _${name}_OBXBuilder(Map<String, dynamic> members) {
32+
$name r = new $name();
33+
${readEntity.properties.map((p) => "r.${p.name} = members[\"${p.name}\"];").join()}
34+
return r;
35+
}
36+
37+
Map<String, dynamic> _${name}_OBXReader($name inst) {
38+
Map<String, dynamic> r = {};
39+
${readEntity.properties.map((p) => "r[\"${p.name}\"] = inst.${p.name};").join()}
40+
return r;
41+
}
42+
43+
const ${name}_OBXDefs = EntityDefinition<${name}>(_${name}_OBXModelGetter, _${name}_OBXReader, _${name}_OBXBuilder);
44+
""";
45+
}
46+
}

0 commit comments

Comments
 (0)