Skip to content

Instantly share code, notes, and snippets.

@abdul
Forked from szinck/database.py
Created May 13, 2013 13:41
Show Gist options
  • Save abdul/5568370 to your computer and use it in GitHub Desktop.
Save abdul/5568370 to your computer and use it in GitHub Desktop.
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine("postgresql://user:@host/schema")
Base = declarative_base()
Base.metadata.reflect(engine)
from sqlalchemy.orm import relationship, backref
from database import Base
class Bar(Base):
__table__ = Base.metadata.tables['bars']
class Foo(Base):
__table__ = Base.metadata.tables['foos']
bar = relationship(Bar, primaryjoin='Foo.bar_id == Bar.bar_id')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment