A
A
Alexander Rublev2017-10-24 21:50:52
Python
Alexander Rublev, 2017-10-24 21:50:52

When to do ORM mapping?

Hello.
I'm starting to write a new program for myself, and decided to get acquainted with ORM (Pony orm)
Tell me, did I understand correctly that you need to do mapping every time you start the program in order to work with ORM objects?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-11-02
@Meller008

In your application, you describe storage objects as OOP classes. Further, when working with these objects in Python, the ORM system translates object interactions into SQL in accordance with the specified provider.
For example, print(Person[person_id].name) will generate the following SQL for SQLite:

SELECT "id", "name", "age"
FROM "Person"
WHERE "id" = ?

Where the specified person_id will be substituted for the question. It will be executed in SQLite, return the data to the ORM, and it will already give us the requested data in the form of a Person object , from which in this case we derive the name.
And it will work that way whether you are running the app for the first time or the hundredth time.
On the official Pony ORM page, everything is quite clearly described in the first steps section:
Getting Started with Pony
To understand the interaction between ORM and the database, I advise you to enable debug mode: set_sql_debug(True) . In this case, all interaction with the database will be displayed in the console.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question