上QQ阅读APP看书,第一时间看更新
Defining the database schema
The database schema is simple and inherited from the monolith. We care only about the thoughts, stored in the thought_model table, so the database structure is as follows:
The thought_model table
This table is represented in code in the thoughts_backend/models.py file, described in SQLAlchemy format with the following code:
class ThoughtModel(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(50))
text = db.Column(db.String(250))
timestamp = db.Column(db.DateTime, server_default=func.now())
SQLAlchemy is capable of creating the table for testing purposes or for development mode. For this chapter, we defined the database to be SQLite, which stores the data in the db.sqlite3 file.