Guest User

Untitled

a guest
Apr 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. from sqlalchemy import create_engine, MetaData
  2. from sqlalchemy.orm import sessionmaker
  3. from sqlalchemy.ext.declarative import declarative_base
  4.  
  5. username = "username"
  6. password = "password"
  7. host = "localhost"
  8. database = "dbname"
  9.  
  10. engine = create_engine("mysql://{}:{}@{}/{}".format(username, password, host, database))
  11. Base = declarative_base(engine)
  12.  
  13. def loadSession():
  14. metadata = Base.metadata
  15. Session = sessionmaker(bind=engine)
  16. session = Session()
  17. return session
  18.  
  19. class Company(Base):
  20. __tablename__ = 'company'
  21. __table_args__ = {'autoload': True}
  22.  
  23. session = loadSession()
  24. print session.query(Company).first()
Add Comment
Please, Sign In to add comment