What is ORM in Python

What is ORM in Python

Top web applications constantly receive and send a lot of new data, automatically entering them into its database, while the preparation of the requests themselves lies on the shoulders of the programmer. A real web application will require writing many queries in the language SQL… For a more concise presentation of them, they are used – Object-relational mappers or ORM… The advantages and disadvantages that we will talk about in this article.

Object-Relational Mapper (ORM) Is a code library that automates the transfer of data stored in relational database tables to objects that are used in application code.

Why are ORMs useful?
ORMs provide a high-level relational database abstraction that allows a developer to write code Python instead of SQL to create, read, update and delete data and schemas in your database. Developers can use the programming language they want to work with the database instead of writing SQL statements or stored procedures.

For example, without the ORM, a developer would write the following statement SQL to get each row in the USERS table where the zip_code column is 94107:

SELECT * FROM USERS WHERE zip_code=94107;

#Вместо этого эквивалентный запрос ORM Django будет выглядеть как следующий код Python:

users = Users.objects.filter(zip_code=94107)

Ability to write code Python instead of SQL can speed up the development of web applications, especially at the beginning of a project. Potential development speed improvement comes from not having to switch from code Python to write operators SQL with a declarative paradigm.

ORMs also theoretically allow you to switch your application between different relational databases. For example, a developer can use SQLite for local development and MySQL in production.

However, in practice, it is better to use the same database for local development as in production. Otherwise, the production environment may experience unexpected errors that were not present in the local development environment. In addition, a project rarely switches from one production database to another, unless there is a good reason.

Access to the database via Python ORM can be carried out both within the framework of the corresponding frameworks Django, Flask, Tornadoand at a low level using connector libraries… Connectors can come in handy when a script involves accessing a database, psycopg (for PostgreSQL) or MySQL-python (for MySQL).

Of course, similar abstractions SQL queries, affect performance when it comes to large amounts of data, which does a good job DBMS… Wherein ORM handles queries well on a small portion of the relational database. The possibility object representation of queries and relational database data solves the problem of minimizing errors in the program code.

Previous article Next article

Copying of materials is allowed only with the indication of the author (Mikhail Rusakov) and an indexed direct link to the site (http://myrusakov.ru)!

Add to my friends VK: http://vk.com/myrusakov.
If you want to rate me and my work, then write it in my group: http://vk.com/rusakovmy.

If you do not want to miss new materials on the site,
then you can subscribe to updates: Subscribe to updates

If you still have any questions, or you have a desire to comment on this article, then you can leave your comment at the bottom of the page.

Recommend this article to your friends:

If you liked the site, then post a link to it (on your site, on the forum, in contact):

  1. Button:

    It looks like this: How to create your website

  2. Text link:

    It looks like this: How to create your website

  3. BB-code of the link for forums (for example, you can put it in the signature):

Related Posts

Property Management in Dubai: Effective Rental Strategies and Choosing a Management Company

“Property Management in Dubai: Effective Rental Strategies and Choosing a Management Company” In Dubai, one of the most dynamically developing regions in the world, the real estate…

In Poland, an 18-year-old Ukrainian ran away from the police and died in an accident, – media

The guy crashed into a roadside pole at high speed. In Poland, an 18-year-old Ukrainian ran away from the police and died in an accident / illustrative…

NATO saw no signs that the Russian Federation was planning an attack on one of the Alliance countries

Bauer recalled that according to Article 3 of the NATO treaty, every country must be able to defend itself. Rob Bauer commented on concerns that Russia is…

The Russian Federation has modernized the Kh-101 missile, doubling its warhead, analysts

The installation of an additional warhead in addition to the conventional high-explosive fragmentation one occurred due to a reduction in the size of the fuel tank. The…

Four people killed by storm in European holiday destinations

The deaths come amid warnings of high winds and rain thanks to Storm Nelson. Rescuers discovered bodies in two separate incidents / photo ua.depositphotos.com Four people, including…

Egg baba: a centuries-old recipe of 24 yolks for Catholic Easter

They like to put it in the Easter basket in Poland. However, many countries have their own variations of “bab”. The woman’s original recipe is associated with…

Leave a Reply

Your email address will not be published. Required fields are marked *