File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ from objectbox import *
2+ from objectbox .model import *
3+
4+ def test_userclass ():
5+
6+ @Entity (id = 1 , uid = 1 )
7+ class Person :
8+ id = Id (id = 1 , uid = 1001 )
9+ firstName = Property (str , id = 2 , uid = 1002 )
10+ lastName = Property (str , id = 3 , uid = 1003 )
11+ def __init__ (self ):
12+ self .counter = 0
13+ def fullname (self ):
14+ return f"{ self .firstName } { self .lastName } "
15+ def tick (self ):
16+ self .counter += 1
17+
18+ model = Model ()
19+ model .entity (Person , last_property_id = IdUid (3 , 1003 ))
20+ model .last_entity_id = IdUid (1 ,1 )
21+ dbpath = "testdb"
22+ Store .remove_db_files (dbpath )
23+ store = Store (model = model , directory = dbpath )
24+ box = store .box (Person )
25+ id_alice = box .put ( Person (firstName = "Alice" , lastName = "Adkinson" ))
26+ id2 = box .put ( Person (firstName = "Bob" , lastName = "Bowman" ))
27+ id3 = box .put ( Person (firstName = "Cydia" , lastName = "Cervesa" ))
28+ assert box .count () == 3
29+ alice = box .get (id_alice )
30+ assert alice .fullname () == "Alice Adkinson"
31+ assert alice .counter == 0
32+ alice .tick ()
33+ alice .tick ()
34+ assert alice .counter == 2
You can’t perform that action at this time.
0 commit comments