table of Contents
ORM framework
ORM object-relational mapping, refers to the relationship between objects and databases
Why do mapping? Avoid duplication write sql statement
ORM can help us generate sql statements, execution, and get the results, and then converted to an object
object --> databases --> object
Hand line and ORM framework
The reason to write, in order to better understand the framework of the principle of realization
We automatically generate those sql statement
You can do
Create table statement
CRUD
When you want to create a table
A project corresponds to a database
A class corresponding to a table
An object corresponding to a record
A field corresponding to an attribute
We want to achieve the purpose of:
- When creating a class in a project automatically generates the table according to the type of information
- Metaclasses to control the process of creating classes
- By init method, the class learned about to create, generate a build table statement
- Metaclasses to control the process of creating classes
create table user1(
id int primary key auto_increment,
name char(20),
pwd char(20),
vip tinyint default 0,
extra float,
utype tinyint default 0,
islock tinyint default 0
);
- When we create an object and save it automatically generates a record based on the information object
- Object storage method to increase
- When we want to modify the properties of a particular object, automatically generate a modified statement
- Object provides a method to update
- When we want to delete, delete the automatically generated statement
- Object provides a method to delete
- When I did not need to get a certain type of data, automatically generating queries, and converts it into an object query
- It provides a method for obtaining a class object
The difference between the timestamp and datetime
note:
- Mysql the various constraints can be controlled in python
- When the amount of data to foreign key table is too large, foreign key association is not recommended, because every time you insert data from a table when the query again will be the main table, impact on performance