Created
April 5, 2018 19:01
-
-
Save reflechant/d3f8be097ec3b12703fedeb6f9d0ce0e to your computer and use it in GitHub Desktop.
This file contains 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 import orm | |
db = orm.Database() | |
orm.set_sql_debug(True) | |
class Author(db.Entity): | |
name = orm.PrimaryKey(str) | |
books = orm.Set('Book') | |
class Book(db.Entity): | |
name = orm.PrimaryKey(str) | |
authors = orm.Set(Author) | |
db.bind( | |
provider='sqlite', | |
filename=':memory:') | |
db.generate_mapping(create_tables=True) | |
@orm.db_session | |
def init(): | |
a1 = Author(name='Umberto Eco') | |
b1 = Book(name='Il nome della rosa', authors=[a1]) | |
b1 = Book(name='Il pendolo di Foucault', authors=[a1]) | |
init() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment