-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.py
29 lines (20 loc) · 1.05 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Column, Integer, String, PickleType
from sqlalchemy.orm import sessionmaker, scoped_session
engine = create_engine("sqlite:///passwords.db", echo=False)
session = scoped_session(sessionmaker(bind=engine, autocommit=False, autoflush=False)) # scoped_session is being used to guarantee thread-safety for multiple users accessing this same app
Base = declarative_base()
Base.query = session.query_property()
### Class declarations go here
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
email = Column(String(64), nullable=False)
password = Column(PickleType, nullable=False) # Holds Python objects, which are serialized using pickle
threshold = Column(Integer, nullable=False)
### End class declarations
def main():
"""In case we need this for something"""
pass
if __name__ == "__main__": # calls main function if we were to run this model.py file directly (vs. importing into another Python file)
main()