@@ -33,37 +33,35 @@ Persist local Dart objects with ease & speed, efficiently manage vectors.
33
33
ObjectBox provides a store with boxes to put objects into:
34
34
35
35
``` dart
36
- // Annotate a Dart class to create a box
36
+ // Annotate a Dart class to create a Box
37
37
@Entity()
38
38
class Person {
39
- @Id()
39
+ @Id()
40
40
int id;
41
- String name;
41
+ String firstName;
42
+ String lastName;
42
43
43
- Person({this.id = 0, required this.name });
44
+ Person({this.id = 0, required this.firstName, required this.lastName });
44
45
}
45
46
47
+ final Store store = await openStore(directory: 'person-db');
46
48
final box = store.box<Person>();
47
49
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
51
52
52
- // Get the object back from the box
53
- person = box.get(id)!;
53
+ person = box.get(id)!; // Read
54
54
55
- // Update the object
56
- person.name = "Joe Black";
57
- box.put(person);
55
+ person.lastName = 'Black';
56
+ box.put(person); // Update
58
57
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
64
59
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();
67
65
```
68
66
Ready? Continue with the ➡️ ** [ Getting Started guide] ( https://docs.objectbox.io/getting-started ) ** .
69
67
0 commit comments