Sobes.tech
Junior — Middle

Is it possible to implement a data model without tying it to a specific table in a database?

sobes.tech AI

Answer from AI

Yes, in Python it is possible to implement a data model without a strict binding to a specific database table. This is often done using ORM (Object-Relational Mapping) or with the use of dynamic data structures.

For example, dictionaries or classes without direct connection to tables can be used, and then data can be stored in various sources, including NoSQL databases or files.

There are also libraries that allow working with data models independently of a specific DBMS, such as SQLAlchemy with the ability to define tables dynamically.

A simple example of a model without a strict binding:

class DataModel:
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, value)

obj = DataModel(name='Alice', age=30)
print(obj.name)  # Alice

Thus, a data model can be flexible and not directly dependent on the database structure.