Skip to content

Instantly share code, notes, and snippets.

@szinck
Created May 23, 2012 04:56
Show Gist options
  • Save szinck/2773350 to your computer and use it in GitHub Desktop.
Save szinck/2773350 to your computer and use it in GitHub Desktop.
sqlalchemy reflection
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