@@ -41,8 +41,19 @@ from objectbox.model import *
41
41
@Entity (id = 1 , uid = 1 )
42
42
class Person :
43
43
id = Id(id = 1 , uid = 1001 )
44
- first_name = Property(str , id = 2 , uid = 1002 )
45
- last_name = Property(str , id = 3 , uid = 1003 )
44
+ name = Property(str , id = 2 , uid = 1002 )
45
+ is_enabled = Property(bool , id = 3 , uid = 1003 )
46
+ # int can be stored with 64 (default), 32, 16 or 8 bit precision.
47
+ int64 = Property(int , id = 4 , uid = 1004 )
48
+ int32 = Property(int , type = PropertyType.int, id = 5 , uid = 1005 )
49
+ int16 = Property(int , type = PropertyType.short, id = 6 , uid = 1006 )
50
+ int8 = Property(int , type = PropertyType.byte, id = 7 , uid = 1007 )
51
+ # float can be stored with 64 or 32 (default) bit precision.
52
+ float64 = Property(float , id = 8 , uid = 1008 )
53
+ float32 = Property(float , type = PropertyType.float, id = 9 , uid = 1009 )
54
+ byte_array = Property(bytes , id = 10 , uid = 1010 )
55
+ # Regular properties are not stored.
56
+ transient = " "
46
57
```
47
58
48
59
### Using ObjectBox
@@ -58,16 +69,16 @@ import objectbox
58
69
59
70
# Configure ObjectBox: should be done only once in the whole program and the "ob" variable should be kept around
60
71
model = objectbox.Model()
61
- model.entity(Person, last_property_id = objectbox.model.IdUid(3 , 1003 ))
72
+ model.entity(Person, last_property_id = objectbox.model.IdUid(10 , 1010 ))
62
73
model.last_entity_id = objectbox.model.IdUid(1 , 1 )
63
74
ob = objectbox.Builder().model(model).directory(" db" ).build()
64
75
65
76
# Open the box of "Person" entity. This can be called many times but you can also pass the variable around
66
77
box = objectbox.Box(ob, Person)
67
78
68
- id = box.put(Person(first_name = " Joe" , last_name = " Green" )) # Create
79
+ id = box.put(Person(name = " Joe Green" )) # Create
69
80
person = box.get(id ) # Read
70
- person.last_name = " Black"
81
+ person.name = " Joe Black"
71
82
box.put(person) # Update
72
83
box.remove(person) # Delete
73
84
```
0 commit comments