The SQL data model – rows and tables

Conceptually, the SQL data model is based on named tables with named columns. A table definition is a flat list of columns with no other structure to the data. Each row is essentially a mutable @dataclass. The idea is to imagine the contents within a table as a list of individual @dataclass objects. The relational model can be described by Python type hints as if it had definitions similar to the following:

from dataclasses import dataclassfrom typing import Union, Textimport datetimeSQLType = Union[Text, int, float, datetime.datetime, datetime.date, bytes]@dataclassclass Row:    column_x: SQLType    ...Table = Union[List[Row], Dict[SQLType, Row]]

From the type hints, we can see that a database Table can be ...

Get Mastering Object-Oriented Python - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.