@@ -41,8 +41,19 @@ from objectbox.model import *
4141@Entity (id = 1 , uid = 1 )
4242class Person :
4343 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 = " "
4657```
4758
4859### Using ObjectBox
@@ -58,16 +69,16 @@ import objectbox
5869
5970# Configure ObjectBox: should be done only once in the whole program and the "ob" variable should be kept around
6071model = 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 ))
6273model.last_entity_id = objectbox.model.IdUid(1 , 1 )
6374ob = objectbox.Builder().model(model).directory(" db" ).build()
6475
6576# Open the box of "Person" entity. This can be called many times but you can also pass the variable around
6677box = objectbox.Box(ob, Person)
6778
68- id = box.put(Person(first_name = " Joe" , last_name = " Green" )) # Create
79+ id = box.put(Person(name = " Joe Green" )) # Create
6980person = box.get(id ) # Read
70- person.last_name = " Black"
81+ person.name = " Joe Black"
7182box.put(person) # Update
7283box.remove(person) # Delete
7384```
0 commit comments