aboutsummaryrefslogtreecommitdiff
path: root/mappings.py
diff options
context:
space:
mode:
Diffstat (limited to 'mappings.py')
-rw-r--r--mappings.py40
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()