Skip to content

Instantly share code, notes, and snippets.

@reflechant
Created April 5, 2018 19:01
Show Gist options
  • Save reflechant/d3f8be097ec3b12703fedeb6f9d0ce0e to your computer and use it in GitHub Desktop.
Save reflechant/d3f8be097ec3b12703fedeb6f9d0ce0e to your computer and use it in GitHub Desktop.
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