Last active
July 16, 2020 12:17
-
-
Save marmeladze/b0fecabbab33519d364597098f1d6d0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pony.orm import * | |
| db = Database() | |
| db.bind(provider='sqlite', filename='/home/ziya/Projects/TirexGroup/newdatabase.db', create_db=True) | |
| class Person(db.Entity): | |
| first_name = Required(str) | |
| last_name = Required(str) | |
| phone_number = Required(str) | |
| db.generate_mapping(create_tables=True) | |
| p1 = Person(first_name="John", last_name="Lennon", phone_number="5465465") | |
| p2 = Person(first_name="John", last_name="Locke", phone_number="5365465") | |
| p3 = Person(first_name="Jack", last_name="Shepherd", phone_number="53698465") | |
| commit() | |
| results = select(person for person in Person if person.first_name == "John") | |
| results.show() | |
| """ | |
| id|first_name|last_name|phone_number | |
| --+----------+---------+------------ | |
| 1 |John |Lennon |5465465 | |
| 2 |John |Locke |5365465 | |
| """ | |
| for result in results: | |
| print(result.first_name, result.last_name, result.phone_number) | |
| """ | |
| >>> record = Person.get(phone_number="5465465") | |
| >>> record.first_name = "Steve" | |
| >>> commit() | |
| >>> results = select(person for person in Person) | |
| >>> results.show() | |
| id|first_name|last_name|phone_number | |
| --+----------+---------+------------ | |
| 1 |Steve |Lennon |5465465 | |
| 2 |John |Locke |5365465 | |
| 3 |Jack |Shepherd |53698465 | |
| >>> results = Person.select_by_sql("SELECT * FROM PERSON WHERE id < 3") | |
| >>> results | |
| [Person[1], Person[2]] | |
| >>> for res in results: | |
| ... print(res.first_name, res.last_name) | |
| ... | |
| Steve Lennon | |
| John Locke | |
| >>> | |
| """ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment