Get the App
SLTechnology News&Howtos  ›  Development  › 

What is ORM?

Shulou Source: shulou.com Published: 2022-06-03 05:31:25 10月18日 Update

Today, I would like to talk to you about what ORM is, many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.

Introduction to ORM

An important part of the MVC or MVC framework is ORM, which realizes the decoupling of the data model from the database, that is, the design of the data model does not need to depend on a specific database, and the database can be easily replaced through simple configuration, which greatly reduces the workload of developers and does not have to face the invalid labor caused by database changes.

ORM is the abbreviation of object-relation-mapping. (ObjectRelationalMapping, ORM for short) (I will learn a sqlalchemy in the future, which is very similar to him, but django's orm is not independent for others to use, although it is more powerful than sqlalchemy, but others can't use it.)

Class object-- > sql--- > pymysql--- > mysql server-- > disk, orm is actually an engine for translating the syntax of class object into sql statements, knowing what orm is, and the rest is how to use orm and how to write class object relation statements.

Create a table by single table operation

Create a model

Next, you need to create the corresponding data, connect to the corresponding database, then execute the command to create the table, translate it into the corresponding sql, and then execute it in the database to create the corresponding table. One more step in the process of translating orm into sql is inefficient, but there is not much damage, and you can bear it. When you can't stand it, you can write the native sql statement by yourself. The general scenario orm is enough, the development speed is faster, the writing method is closer to the application development, and there is another point, that is, the database upgrade or change, so the database operation you wrote with SQL statement before. Then you need to modify all the sql statements, but if you use orm, you don't need to worry about this problem, whether you change from mysql to oracle or from oracle to mysql, if you use orm to do it, you just need to modify the orm engine (change some configuration in the configuration file), and the orm statements you wrote before will be automatically translated into the corresponding database sql statements.

More fields and parameters

Each field has some unique parameters, for example, CharField requires the max_length parameter to specify the size of the VARCHAR database field. There are also some common parameters that apply to all fields. These parameters are defined in detail in the document.

After reading the above, do you have any further understanding of what ORM is? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Data database statements parameters fields objects that is content model development configuration engine more powerful important next people writing functions commands Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker Shulou Technology MariaDB Redmi