python database operations using ORM - CRUD

A blog by the explanation, we need to operate the database using orm installed pymysql and sqlalchemy module, then we deletions simple change to the database search:
1, import module:
Here Insert Picture Description
2, creates a connection to the base class:
Here Insert Picture Description
here mysql: // scott: tiger @ hostname / dbname can hold down CTRL + left mouse button to find the source code:
Here Insert Picture Description
format:
MySQL: // database Username: database password @ip address / name of the database

3, add the primary table associated with Table classes:
Here Insert Picture Description
a class representing a table

4, main functions will create a table of the class object instance:

Here Insert Picture Description
Here it will be the class object is similar to the cursor pymysql

5, insert data:
Here Insert Picture Description
After inserting data into the same data repeatedly bound error, then we add the try statement:
Here Insert Picture Description

6, query data:
(1) all data query name and age:
Here Insert Picture Description
operating results;
Here Insert Picture Description
(2) a single query data:
Here Insert Picture Description
(3) the query conditions:
Here Insert Picture Description

7, modify the data:
Here Insert Picture Description

8, delete the data:
Here Insert Picture Description

Additions and deletions to the database must commit to database

These are the additions and deletions to change search orm operation of the database, we want to be able to help
automate the test group: 762,141,168
welcome you to test your friends to join and progress together, work together!

Published 10 original articles · won praise 13 · views 399

Guess you like

Origin blog.csdn.net/weixin_46457203/article/details/104941784