Use orm to create a table
Connect to the database
Create Base Base Class
Create classes, add attributes, and add data type constraints
Create session
Add create instance add data
Add data to the database
submit data


def add_data():
user = User (add attribute data)
session.add(user)
sesssion.commit()
def search_data():
data = session.query(Usre).filter(conditional judgment).all()
print(data)
def update_data():
data = session.query(Usre).filter(conditional judgment).all()
data.attribute name = xxx
session.commit()
def delete_data():
data = session.query(Usre).filter(conditional judgment).all()
session.rollback()
session.delete(data)

Integer: Plastic surgery.
Float: Floating point type.
Boolean: Pass True/False in.
DECIMAL: Fixed-point type.
enum: enumerated type.
Date: Pass datetime.date() in. 2020 10 28
def add_data():
user = User (add attribute data)
session.add(user)
sesssion.commit()
def search_data():
data = session.query(Usre).filter(conditional judgment).all()
print(data)
def update_data():
data = session.query(Usre).filter(conditional judgment).all()
data.attribute name = xxx
session.commit()
def delete_data():
data = session.query(Usre).filter(conditional judgment).all()
session.rollback()
session.delete(data)
DateTime: Pass datetime.datetime() in. 2020 10 28 21 36 21
Time: Pass datetime.time() in. 21 36 21
String: Character type. You need to specify the length when using it, which is different from the Text type.
Text: Text type.
LONGTEXT: Long text type.

Common parameters
default: The default value. When you set default=xxx, if you do not pass this data, then the database will display your settings
Of this value
nullable: Whether it is nullable. nullable=False means it cannot be empty
primary_key: Whether it is the primary key.
unique: Is it unique? When you set this parameter, then the data in the unified column cannot be the same, and the same will report an error
autoincrement: Whether to increase automatically.
onupdate: The function to be executed when updating.
name: the field mapping of the attribute in the database
Aggregate function
func.count
func.max
func.min
func.avg
func.sum

Filter condition Filtering is a very important function of data extraction. Here is an explanation of some commonly used filter conditions, and these filter conditions can only be achieved through the...
Experience: I receive a lot of information and knowledge every day. I'm afraid I can't remember what I should remember. I have to summarize it systematically to deepen my memory. I hope I will become ...
Directory Structure Need to install the library: Step 1: Configure database related information settings.py Step 2: Build a database model models.py Step 3: __init__.py file in the blog directory, not...
1. Basically increased, deleted and modified 2. Group query according to conditions...
When it comes to aggregate functions, they must be very unfamiliar. Today I will introduce commonly used aggregate functions. Aggregation functions can be described as old roles that are often used in...
1. Introduction to the database The database is used to store data, the data is not directly stored in the database, the database is stored in the table, and the data is stored in the table. So our le...
ORM addition, deletion, modification, data type and parameters 1. Flask-ORM add data 2. Adding, deleting, modifying and checking Flask-ORM data Three, SQLAlchemy commonly used data types Four, Column ...
[SQLAlchemy] Section 3: Commonly used fields and their constraints 1 Guide package 2 Commonly used field types 3 Common constraints 4 Examples 1 Guide package 2 Commonly used field types Keyword Corre...
default: default value nullable: is empty primary_key: primary key unique: is unique autoincrement: Are increment onupdate: execution of updating name: the property mapping database ...