{"id":15209400,"url":"https://github.com/denisbilli/qdbmanager","last_synced_at":"2025-10-29T15:30:30.303Z","repository":{"id":30711125,"uuid":"34267235","full_name":"denisbilli/qDBManager","owner":"denisbilli","description":"An easy-to-use ORM/Entity Manager for Qt Framework","archived":false,"fork":false,"pushed_at":"2017-12-07T16:51:37.000Z","size":34,"stargazers_count":16,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T01:51:18.546Z","etag":null,"topics":["c-plus-plus","database","dbmanager","entity","orm","qt-framework"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denisbilli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-20T15:00:45.000Z","updated_at":"2024-12-27T01:00:18.000Z","dependencies_parsed_at":"2022-07-28T03:39:00.278Z","dependency_job_id":null,"html_url":"https://github.com/denisbilli/qDBManager","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisbilli%2FqDBManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisbilli%2FqDBManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisbilli%2FqDBManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisbilli%2FqDBManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denisbilli","download_url":"https://codeload.github.com/denisbilli/qDBManager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238840721,"owners_count":19539602,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","database","dbmanager","entity","orm","qt-framework"],"created_at":"2024-09-28T07:23:25.994Z","updated_at":"2025-10-29T15:30:29.955Z","avatar_url":"https://github.com/denisbilli.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# qDBManager\nThis is a simple DBManager for SQLite on Qt Framework. It has been created since I needed an easy way to manage my SQLite database in my C++/Qt applications. I always worked with an Entity-like approach, and I wasn't able to find a similar approach that was a \"pure\" C++ solution (there is **QxOrm** but it uses boost, and I didn't want. Anyway you can find it here: http://www.qxorm.com/qxorm_en/home.html). Eventually I decided to do it myself.\n\n# How it works\nAs already said, it is based on a pure Qt approach. The only thing you need to do is to include *qdbmanager.pri* inside your *.pro* file, like this:\n```c++\ninclude(../qdbmanager/qdbmanager.pri)\n```\n\n**Let's create an entity**\n\nNow you have to create an Entity for our test. Let's call it *TestEntity*. I created a snippet in QtCreator in order to be very fast in this phase.\n```c++\n#ifndef TESTENTITY_H\n#define TESTENTITY_H\n\n#include \"entities/BaseEntity.h\"\n\nclass TestEntity : public BaseEntity\n{\n    Q_OBJECT\n    Q_TABLENAME(\"TestEntity\")\n    \n    /* TODO PROPERTIES */\n    \npublic:\n    explicit TestEntity(QObject* parent=0);\n    \n    /* TODO ACCESSORS */\n    \n    virtual QString toString() { \n        //TODO\n        return QString(\"\"); \n    }\n    \n    virtual bool equals(QObject *elem) { \n        //TODO\n        return false;\n    }\n    \nsignals:\n    /* TODO SIGNALS */\n    \nprivate:\n    /* TODO STATUS VARIABLES */\n};\nQ_DECLARE_METATYPE(TestEntity*)\n\ntypedef QList\u003cTestEntity*\u003e          QListTestEntity;\ntypedef QMap\u003cint,QListTestEntity\u003e   QMapTestEntity;\n\n#endif // TESTENTITY_H\n```\n\nNow, you have several possibilities to get it work. The first is to use my personal shortcuts:\n\n* Q_FIELD([FIELD_TYPE],[FIELD_NAME]) =\u003e Creates a mapped field of that Type inside the Entity\n* Q_TRANSIENT_FIELD([FIELD_TYPE],[FIELD_NAME]) =\u003e Creates an unmapped field of that Type inside the Entity (the same as Hibernate)\n* Q_INDEX([FIELD_NAME]) =\u003e Creates an index with that field\n* Q_INDEX_MUL([FIELD_NAME_1],[FIELD_NAME_2]) =\u003e Creates an index with those two fields\n\nLet's say that you need two fields called *Name* and *Surname* mapped and indexed in the Entity, and a transient *Connected* field, you would do something like:\n\n```c++\n#ifndef TESTENTITY_H\n#define TESTENTITY_H\n\n#include \"entities/BaseEntity.h\"\n\nclass TestEntity : public BaseEntity\n{\n    Q_OBJECT\n    Q_TABLENAME(\"TestEntity\")\n\n    Q_FIELD(QString,name)\n    Q_FIELD(QString,surname)\n\n    Q_TRANSIENT_FIELD(bool,connected)\n\n    Q_INDEX(name)\n    Q_INDEX(surname)\n\npublic:\n    explicit TestEntity(QObject* parent=0);\n\n    QString get_name();\n    void set_name(QString name);\n\n    QString get_surname();\n    void set_surname(QString surname);\n\n    bool get_connected();\n    void set_connected(bool connected);\n\n    virtual QString toString() { return get_name() + \" \" + get_surname(); }\n\n    virtual bool equals(QObject *elem) { return qobject_cast\u003cTestEntity*\u003e(elem)-\u003etoString() == toString(); }\n\nsignals:\n    void changed_name(QString name);\n    void changed_surname(QString surname);\n    void changed_connected(bool connected);\n\nprivate:\n    QString name;\n    QString surname;\n    bool connected;\n};\nQ_DECLARE_METATYPE(TestEntity*)\n\ntypedef QList\u003cTestEntity*\u003e          QListTestEntity;\ntypedef QMap\u003cint,QListTestEntity\u003e   QMapTestEntity;\n\n#endif // TESTENTITY_H\n```\n\n```c++\n#include \"testentity.h\"\n\nTestEntity::TestEntity(QObject* parent) : BaseEntity(parent)\n{\n    propertyMap.insert(\"Name\", \"\");\n    propertyMap.insert(\"Surname\", \"\");\n    connected = false;\n}\n\nQString TestEntity::get_name()\n{\n    return propertyMap.value(\"Name\").toString();\n}\n\nvoid TestEntity::set_name(QString name)\n{\n    propertyMap.insert(\"Name\", name);\n    emit changed_name(name);\n}\n\nQString TestEntity::get_surname()\n{\n    return propertyMap.value(\"Surname\").toString();\n}\n\nvoid TestEntity::set_surname(QString surname)\n{\n    propertyMap.insert(\"Surname\", surname);\n    emit changed_surname(surname);\n}\n\nbool TestEntity::get_connected()\n{\n    return this-\u003econnected;\n}\n\nvoid TestEntity::set_connected(bool connected)\n{\n    this-\u003econnected = connected;\n}\n```\n\nNow your *main.cpp* looks like this:\n\n```c++\n#include \u003cQCoreApplication\u003e\n\n#include \"qdbmanager.h\"\n#include \"testentity.h\"\n#include \u003cQDebug\u003e\n\n#include \"interfaces/qsqlite.h\"\n\nint main(int argc, char *argv[])\n{\n    QCoreApplication a(argc, argv);\n\n    QDBManager *dbm = QDBManager::create(\"test\", \"QSQLITE\");\n    dbm-\u003eregister_entity\u003cTestEntity\u003e();\n\n    dbm-\u003eopenDB(\"testdb.sqlite\");\n    dbm-\u003ecreateTable\u003cTestEntity\u003e();\n\n    qDebug()\u003c\u003c\"WRITE TEST\";\n    for (int i = 0; i \u003c 10; ++i) {\n        int id = i+1;\n        TestEntity* testEntity = new TestEntity();\n        testEntity-\u003eset_name(\"Leonard\");\n        testEntity-\u003eset_surname(\"Hofstadter\");\n        testEntity-\u003eset_connected(true);\n\n        qDebug()\u003c\u003c\"ID \"\u003c\u003cid\u003c\u003c\"\\trows affected \"\u003c\u003cdbm-\u003einsertOrUpdate\u003cTestEntity\u003e(testEntity);\n    }\n\n    QListTestEntity testEntities = dbm-\u003elistAll\u003cTestEntity\u003e();\n    qDebug()\u003c\u003ctestEntities.count();\n    foreach (TestEntity* testEntity, testEntities) {\n        qDebug()\u003c\u003ctestEntity-\u003etoString()\u003c\u003ctestEntity-\u003eget_connected();\n    }\n\n    dbm-\u003ecloseDB();\n\n    return a.exec();\n}\n```\n\nAs you can see, you must register your entity if you want to use it in your program. You must use the method \n\n```c++\ndbm-\u003eregister_entity\u003c[ENTITY_CLASS_NAME]\u003e();\n```\n\nbefore reading the Entity from the database, otherwise you will obtain a NULL object.\n\n# Other functionalities\nThis version is fully capable of the basic CRUD operations, and also of retrieving entities from the database performing basic searches (using the Criteria Builder object), but also full queries. I didn't have the time to write a full Help, you may be able to find it yourself. If you are curious you can still write me anyway.\n\n# TODO\n- Only SQLite is supported for the moment, but I'm willing to support other RDBMS soon\n\nYou can write your own adapter extending the class **QDBManager** (have a look to the file interfaces/qsqlite.h).\n\n# Conclusions\nHope to help someone with this lines. Every suggestion is appreciated.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenisbilli%2Fqdbmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenisbilli%2Fqdbmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenisbilli%2Fqdbmanager/lists"}