diff options
author | Cody Hiar <cody@hiar.ca> | 2021-02-03 14:29:24 -0700 |
---|---|---|
committer | Cody Hiar <cody@hiar.ca> | 2021-02-03 14:29:24 -0700 |
commit | 2b007a5a500b635ddcfe4b9a512777f3d21fa6b6 (patch) | |
tree | 7a9ccb2d41222fc571c6d08b169d4946e26c130c /mappings.py |
Initial commit of project
Diffstat (limited to 'mappings.py')
-rw-r--r-- | mappings.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/mappings.py b/mappings.py new file mode 100644 index 0000000..e80756f --- /dev/null +++ b/mappings.py @@ -0,0 +1,40 @@ +"""Database for project.""" +from sqlalchemy import Column, Integer, String, create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker + +DB_FILE = "sqlite:///db.sqlite" +engine = create_engine(DB_FILE, echo=True) +Base = declarative_base() + + +class Message(Base): + """Message from slack.""" + + __tablename__ = "message" + + id = Column(Integer, primary_key=True) + iid = Column(String) + type = Column(String) + username = Column(String) + text = Column(String) + + # ---------------------------------------------------------------------- + def __init__(self, iid, type, username, text): + """Create record.""" + self.iid = iid + self.type = type + self.username = username + self.text = text + + +def create_tables(): + """Create tables.""" + Base.metadata.create_all(engine) + + +def get_session(): + """Start a session.""" + engine = create_engine(DB_FILE, echo=True) + Session = sessionmaker(bind=engine) + return Session() |