-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
29 lines (23 loc) · 890 Bytes
/
database.py
File metadata and controls
29 lines (23 loc) · 890 Bytes
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
import datetime as dt
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime
from sqlalchemy.ext.declarative import declarative_base
# Start the DB engine with the desired DBMS
engine = create_engine('sqlite:///thoughts.db', echo=True)
Base = declarative_base()
# Main table
class Thought(Base):
__tablename__ = 'thoughts'
id = Column(Integer, primary_key=True, autoincrement=True)
text = Column(Text(2000)) # around 400 (English) words
author_id = Column(Integer)
date = Column(DateTime)
def __init__(self, *args, **kw):
super(Thought, self).__init__(*args, **kw)
def get_id(self):
return self.id
def get_author_id(self):
return self.author_id
def create_tables():
""" Instantiate DB tables """
Base.metadata.create_all(engine)