ORM model class presentation,

 All of the software development process, will involve objects and relational databases, and business logic plane at the user level, programmers write code that is object-oriented, when the information we object changes, need corresponding information , spread to a relational database. before that, we need to write SQL statements to create corresponding data tables,

 (Example: Create a auth_user table, you need to define each field, to set the corresponding field types, attributes, and the data table to set the primary key or unique key and good definition table storage engine, character encoding.)

 Then business logic, there are many SQL statement, the table CRUD operations

  Then business logic, there are many SQL statement, the table CRUD operations,

 For example child; submit information via POST request Reviews

  python is a major design objects are all matters _

 You can will operate the database, but also to achieve it through an object-oriented approach ???

   - so there was ORM

 

 What is ORM?

    Our target, automatic XX of the relational database, the bridge acts as the equivalent of the business logic and database layers

 

 So, in Django, how do we develop a model class it?

 This is the role Models.py file!

 -Django, each time to build an application, the application will be in the folder,

 Models.py automatically generate a file, this is the place to write the model class

 

 Model class strengths and weaknesses:

  Advantage--

  Developers can focus on business logic processing, improve development efficiency,

  You are not required to write native SQL statements in the business logic code by way of the operation object, you can manipulate the database!

 Disadvantage -

  To a certain extent the expense of efficiency program,

  ORM written in a long time, you may forget to SQL statements

 

  How to choose a project? -

    Complex SQL statements or database-level features - using native SQL easier

    Enhance the development efficiency - Use ORM

  E.g-

  Use Sqlalchemy with Flask like to use ORM in Django as easy, efficient execution only 5% slower than the native SQL, to enhance the development efficiency relative to this performance loss is acceptable!

  

 

Guess you like

Origin www.cnblogs.com/goddog1024/p/11221282.html