Skip to content

Commit f07afeb

Browse files
Merge branch 'readme-update-examples' into 'main'
READMEs: update code examples to match website, more complex query See merge request objectbox/objectbox-dart!88
2 parents 2bb12c3 + 0791184 commit f07afeb

File tree

2 files changed

+34
-38
lines changed

2 files changed

+34
-38
lines changed

README.md

+17-19
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,35 @@ Persist local Dart objects with ease & speed, efficiently manage vectors.
3333
ObjectBox provides a store with boxes to put objects into:
3434

3535
```dart
36-
// Annotate a Dart class to create a box
36+
// Annotate a Dart class to create a Box
3737
@Entity()
3838
class Person {
39-
@Id()
39+
@Id()
4040
int id;
41-
String name;
41+
String firstName;
42+
String lastName;
4243
43-
Person({this.id = 0, required this.name});
44+
Person({this.id = 0, required this.firstName, required this.lastName});
4445
}
4546
47+
final Store store = await openStore(directory: 'person-db');
4648
final box = store.box<Person>();
4749
48-
// Put a new object into the box
49-
var person = Person(name: "Joe Green");
50-
final id = box.put(person);
50+
var person = Person(firstName: 'Joe', lastName: 'Green');
51+
final id = box.put(person); // Create
5152
52-
// Get the object back from the box
53-
person = box.get(id)!;
53+
person = box.get(id)!; // Read
5454
55-
// Update the object
56-
person.name = "Joe Black";
57-
box.put(person);
55+
person.lastName = 'Black';
56+
box.put(person); // Update
5857
59-
// Query for objects
60-
final query = box.query(Person_.name.equals("Joe Black"))
61-
.order(Person_.name).build();
62-
final people = query.find();
63-
query.close();
58+
box.remove(person.id); // Delete
6459
65-
// Remove the object from the box
66-
box.remove(person.id);
60+
final query = box // Query
61+
.query(Person_.firstName.equals('Joe') & Person_.lastName.startsWith('B'))
62+
.build();
63+
final List<Person> people = query.find();
64+
query.close();
6765
```
6866
Ready? Continue with the ➡️ **[Getting Started guide](https://docs.objectbox.io/getting-started)**.
6967

objectbox/README.md

+17-19
Original file line numberDiff line numberDiff line change
@@ -64,37 +64,35 @@ Oh, and there is one more thing...
6464
ObjectBox provides a store with boxes to put objects into:
6565

6666
```dart
67-
// Annotate a Dart class to create a box
67+
// Annotate a Dart class to create a Box
6868
@Entity()
6969
class Person {
70-
@Id()
70+
@Id()
7171
int id;
72-
String name;
72+
String firstName;
73+
String lastName;
7374
74-
Person({this.id = 0, required this.name});
75+
Person({this.id = 0, required this.firstName, required this.lastName});
7576
}
7677
78+
final Store store = await openStore(directory: 'person-db');
7779
final box = store.box<Person>();
7880
79-
// Put a new object into the box
80-
var person = Person(name: "Joe Green");
81-
final id = box.put(person);
81+
var person = Person(firstName: 'Joe', lastName: 'Green');
82+
final id = box.put(person); // Create
8283
83-
// Get the object back from the box
84-
person = box.get(id)!;
84+
person = box.get(id)!; // Read
8585
86-
// Update the object
87-
person.name = "Joe Black";
88-
box.put(person);
86+
person.lastName = 'Black';
87+
box.put(person); // Update
8988
90-
// Query for objects
91-
final query = box.query(Person_.name.equals("Joe Black"))
92-
.order(Person_.name).build();
93-
final people = query.find();
94-
query.close();
89+
box.remove(person.id); // Delete
9590
96-
// Remove the object from the box
97-
box.remove(person.id);
91+
final query = box // Query
92+
.query(Person_.firstName.equals('Joe') & Person_.lastName.startsWith('B'))
93+
.build();
94+
final List<Person> people = query.find();
95+
query.close();
9896
```
9997

10098
## Getting Started

0 commit comments

Comments
 (0)