@@ -33,37 +33,35 @@ Persist local Dart objects with ease & speed, efficiently manage vectors.
3333ObjectBox 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()
3838class 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');
4648final 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```
6866Ready? Continue with the ➡️ ** [ Getting Started guide] ( https://docs.objectbox.io/getting-started ) ** .
6967
0 commit comments