Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is ORM?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report