Guest User

Untitled

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. # skysim/skysimulation/database.py
  2. from sqlalchemy import create_engine
  3. from sqlalchemy.orm import scoped_session, sessionmaker
  4. from sqlalchemy.ext.declarative import declarative_base
  5.  
  6. engine = create_engine('blabla connect string here', convert_unicode=True)
  7. db_session = scoped_session(sessionmaker(autocommit=False,
  8. autoflush=False,
  9. bind=engine))
  10. Base = declarative_base()
  11. Base.query = db_session.query_property()
  12.  
  13. def init_db():
  14. # import all modules here that might define models so that
  15. # they will be registered properly on the metadata. Otherwise
  16. # you will have to import them first before calling init_db()
  17. import tables
  18. Base.metadata.create_all(bind=engine)
Add Comment
Please, Sign In to add comment