Feedback for ORM in development
-
Hi, I'm in process of developing active-record like ORM for a Qt. I've done proof of concept for myself, and would very much like a feedback. Currently it works for long/int and QString/text types and Postgres only with parent/child and
belongs to
relationships.I'm not trying to reinvent the wheel, but I haven't found open source alternative that could satisfy minimum requirements (easy to use, gets out of the way, can be used commercially).
Before continuing, my idea is to collect feedback and possible requirements for the future directions.
-
I'm not trying to reinvent the wheel, but I haven't found open source alternative that could satisfy minimum requirements (easy to use, gets out of the way, can be used commercially).
http://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5
What about this? I haven't checked it in details, but it seems to be based on the same idea?
Before continuing, my idea is to collect feedback and possible requirements for the future directions.
If I were implementing such a thing I wouldn't do it like this. For one I'd use the class name as table name and property names as table column names (the necessary reflection capabilities can be used by imposing
Q_GADGET
andQ_PROPERTY
macros). After having this in place I'd simply put down an "adapter" of sorts which will push/pull the objects from a standard instance ofQSqlDatabase
.Primary keys and relations can be pulled out of the db (most databases provide meta information readily for PKs and foreign keys).
Kind regards.
-
I haven't seen this library before, but it's not old. I guess I started working on mine before this one came out.
Yes, its possible to use class name as table name but there would still need to be
DB_TABLE
macro, just without arguments.As for column names, acctually I use properties, so columns are same as property name so
DB_COLUMN(QString, name)
createsset_name()
andget_name()
methods, andname
column in a db.set_
andget_
(example) aren'tcamelCase
as rest ofQt
but reasoning behind this is(a)
recognizable as db bound objects(b)
I did't want to clutterDB_COLUMN
macro but potentially there could be macro likeDB_COLUMN_EX
that specifies names for getters and setters likenut
library above.One thing I'm unable is to retrieve list of all QObjects in a system, or of a specific class so a user of a lib shouldn't manually register classes.
I did not know about Q_GADGET. Very helpful! Thanks.
-
but there would still need to be DB_TABLE macro, just without arguments.
Why, what exactly is that macro supposed to do?
As for column names, acctually I use properties, so columns are same as property name so DB_COLUMN(QString, name) creates set_name() and get_name() methods
Look up
Q_PROPERTY
.One thing I'm unable is to retrieve list of all QObjects in a system
And why should you? There's no central repository for objects ...
BesidesQObject
s are not for that, they can't be copied, you should just use regular objects. And my point was that you don't need to have any macros besidesQ_GADGET
(which will allow to query for the class name with some tweaking) andQ_PROPERTY
(which will give you dynamic properties). The relations can be retrieved from the db.