当前位置:网站首页>Flask framework operation database_ Add, delete, modify and query statements
Flask framework operation database_ Add, delete, modify and query statements
2022-07-29 03:42:00 【Chen Fuguo】
1、 increase :
Create entity class objects ( Rows of the database ):
For example, to User In the table user_name and password add to ‘ Zhang San ’ and ‘123456’ The line of :
#1. Create objects
user1 = User(user_name=" Zhang San ",password="123456")
#2. Add session :
db.session.add(user1)
#3. Submit
db.session.commit()
2、 check
There is one for each model class query object ,
# For example, retrieve user modular ( surface ) All the lines in :
User.query.all()
# Search by condition , Use filters filter() To configure query object :
user1 = User.query.filter(User.user_name==' Zhang San ').first()
3、 Change :
#1、 Query and find the data that needs to be modified
user1 = User.query.filter(User.user_name==' Zhang San ').first()
#2、 Modify the line :
user1.user_name=' Zhang Xiaobao '
#3、 Commit transaction :
db.session.commit()
4、 Delete
#1、 Take out the data to be deleted :
user1 = User.query.filter(User.user_name==' Zhang San ').first()
#2、 Delete data :
db.session.delete(user1)
#3、 Commit transaction :
db.session.commit()
边栏推荐
- Sleuth+zipkin to track distributed service links
- Tristate gate
- 向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
- @Configuration (proxybeanmethods = false) what's the use of setting this to false
- RHCE的at,crontab的基本操作,chrony服务和对称加密和非对称加密
- 2 neural network toolbox NN
- HDU multi School Game 2 1011 DOS card
- 3.1 common neural network layer (I) image correlation layer
- With more than 5 years of work experience and a salary of 15K, would you accept it if you were me?
- 从2019 年开始,你一定停止使用了这个营销策略…
猜你喜欢

Configure vscade to realize ROS writing

How to understand "page storage management scheme"

Matlab learning -- structured programs and user-defined functions

Shutter start white screen

数字孪生实际应用案例-智慧能源篇

Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business

Pp-yoloe details

Sunflower senior product director technology sharing: "how to apply national remote control" in AD domain environment

AI platform, AI midrange architecture

Various minor problems of jupyter notebook, configuration environment, code completion, remote connection, etc
随机推荐
How to realize shortcut keys for interface scaling by vscade
深入C语言(2)——结构的定义与使用
Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business
Li Kou daily question - day 44 -205. Isomorphic string
(nowcoder22529C)dinner(容斥原理+排列组合)
Vs code must know and know 20 shortcut keys!
Arm architecture and neural network
2. Variables and scope
1.6 example: cifar-10 classification
Excel splicing database statement
Flutter 启动白屏
Tencent cloud logs in with PEM
Simple understanding of Poe and UPS Technology
Shutter start white screen
Simple understanding of CDN, SDN and QoS
Introduction and comparison of unicast, multicast (target broadcast, multicast), broadcast, flooding, flooding
Numpy acceleration -- > cupy installation
Malloc C language
Kotlin companion object vs global function
(2022杭电多校三)1011-Link is as bear(思维+线性基)