Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. class User(DB.Model):
  2. __tablename__ = 'users'
  3. id = DB.Column(DB.Integer, primary_key=True)
  4. username = DB.Column(DB.String(64), index=True)
  5. password = DB.Column(DB.String(128))
  6.  
  7. class Customer(DB.Model):
  8. __tablename__ = 'customer'
  9. customer_id = DB.Column(DB.Integer, primary_key=True)
  10. customer_name = DB.Column(DB.String, unique=True, index=True)
  11.  
  12. SQLALCHEMY_BINDS = {
  13. 'customer1' = 'sqlite:////path/customer1.db',
  14. 'customer2' = 'sqlite:////path/customer2.db',
  15. ...
  16. }
  17.  
  18. def get_session(customer_id):
  19. sqlite_url = 'sqlite:////path/customer%s.db' % customer_id
  20. engine = create_engine(sqlite_url)
  21.  
  22. # initialize the db if it hasn't yet been initialized
  23. Base.metadata.create_all(engine)
  24.  
  25. Session = sessionmaker(bind=engine)
  26. session = Session()
  27.  
  28. return session
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement