import sqlalchemy from sqlalchemy import * from sqlalchemy.orm import sessionmaker def setupdb(): #engine = create_engine('sqlite:///Users/erdgeist/Coding/tinybill/foo.db', echo=True) engine = create_engine('sqlite:///foo.db', echo=True) metadata = MetaData() Table( 'customers', metadata, Column( 'id', Integer, primary_key=True ), Column( 'name', String, unique=True ), Column( 'email', String ) ) Table( 'products', metadata, Column( 'id', Integer, primary_key=True ), Column( 'type', String ), Column( 'name', String, unique=True ), Column( 'price', Integer ), ) Table( 'purchases', metadata, Column( 'id', Integer, primary_key=True ), Column( 'product', Integer, ForeignKey('products.id' ) ), Column( 'customer', Integer, ForeignKey('customers.id' ) ), Column( 'detail', String ), Column( 'date', Date ) ) Table( 'payment', metadata, Column( 'id', Integer, primary_key=True ), Column( 'purchase', Integer, ForeignKey('purchases.id') ), Column( 'amount', Integer ), Column( 'date', Date ) ) metadata.create_all(engine) global Session Session = sessionmaker(bind=engine)