Even though SQL expression language already provides a good level of abstraction, it still operates with a physical data model, not with business entities.
ORM makes it possible to map business entities, that a Python application deals with, to data structures in the database. To show this, let's create a Car class and define the mapping.
When using ORM, we describe the database structure and, at the same time, define the classes that represent business entities. This is done using a system named declarative. In SQLAlchemy, this system is initiated by creating a class that is then used as a base class for other classes:
from sqlalchemy.ext.declarative import declarative_base Base = declarative_base()
Now the high-level class that will ...