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,, 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.