130 likes | 230 Views
Group P06: Chen Xi Han Lin Hu Qiang Xie Chenhong. YAOP. Yet Another ORM in Python. Introduction. YAOP is: A set of Python API Serialization of objects into SQLite3 Object Oriented Easy to use. Architecture. Data Definition Language Data Manipulation Language. Architecture Diagrams.
E N D
Group P06: Chen Xi Han Lin Hu Qiang Xie Chenhong YAOP Yet Another ORM in Python
Introduction • YAOP is: • A set of Python API • Serialization of objects into SQLite3 • Object Oriented • Easy to use
Architecture • Data Definition Language • Data Manipulation Language
Data Definition Language • Table Creation • … in an OOP manner
Table Creation >>> ah_beh = Student(name="Ah Beh", age=15) >>> dog_lover1 = Person(name="John") Student and Person table will be created. >>> dog_lover2 = Person(name="Alex") Person table has already been created, no repeated creation.
Kicking in OOP >>> class Kid(Person): age = Attribute(str) Kid inherit from Person so it has both name and the additional attribute - age.
Data Manipulation Language • Creation • Read/Search • Update • Delete
Creation >>> ah_beh = Student(name="Ah Beh", age=15) >>> ah_beh.update(grade=5) >>> print ah_beh.save() >>> Executed: insert into Student(grade,age,name) values(5,15,"Ah Beh")
Read/Search >>> pets_named_bobby = Pet.search(name="Bobby") >>> one_of_bobbies = pets_named_bobby[0] >>> # Check if this is John's Bobby >>> if one_of_bobbies.owner.value == johns_id: print "John finds his Bobby" else: print "This is not John's Bobby" >>> John finds his Bobby
Update >>> ah_beh.update(grade=6) # Level up >>> ah_beh.save() >>> print ah_beh.grade.value >>> Executed: update Student set grade=6,age=15,name="Ah Beh" where id=1
Delete >>> ah_beh.remove() >>> one_of_bobbies.remove() >>> dog_lover.remove()
Q & A Thank you