-
-
Save vioan/c9dee609cc9f406c4928 to your computer and use it in GitHub Desktop.
sqlalchemy reflection
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 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) | |
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 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