Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sqlalchemy import create_engine, MetaData
- from sqlalchemy.orm import sessionmaker
- from sqlalchemy.ext.declarative import declarative_base
- username = "username"
- password = "password"
- host = "localhost"
- database = "dbname"
- engine = create_engine("mysql://{}:{}@{}/{}".format(username, password, host, database))
- Base = declarative_base(engine)
- def loadSession():
- metadata = Base.metadata
- Session = sessionmaker(bind=engine)
- session = Session()
- return session
- class Company(Base):
- __tablename__ = 'company'
- __table_args__ = {'autoload': True}
- session = loadSession()
- print session.query(Company).first()
Add Comment
Please, Sign In to add comment