Class to read and save different objects in SQL database!!!
-
I am trying to create a class that is capable of saving and reading objects of different type in a SQL database. The goal is to avoid redundancy of methods in each object class ( I could, for simplicity write my sql database methods in each object class that I want to save and read and it would work). The strategy I tried is to inherit my object classes with a class containing static methods. Additionnaly different object type have to be saved in different database.
As the database class contains static methods, I am obliged to use static member variables in order to save the database name and path. This is the point that is bothering me. Static variables can be initialized just once. Hence, the database name and path cannot be different for different objects.
https://trackeasy.fun/usps/ https://showbox.tools/ https://speedtest.vet/
My question is the following: what strategy should I use, if I want to have a single class that is capable of saving and reading different object types in different databases according to the object type.Below I provide a minimal example of what I did and that is not the good strategy:
-
This might be helpful
https://doc.qt.io/qt-5/model-view-programming.html -
@VincentWesley said in Class to read and save different objects in SQL database!!!:
class containing static methods
Why static methods?
What you're describing sounds like ORM. Take a look at existing libs like https://www.qxorm.com/qxorm_en/home.html