{"id":19000693,"url":"https://github.com/flaviomarcio/qorm","last_synced_at":"2026-04-12T15:08:40.725Z","repository":{"id":209546433,"uuid":"249058429","full_name":"flaviomarcio/qorm","owner":"flaviomarcio","description":"Qt-QOrm Object-relational mapping for SQL ANSI, SQLite, Postgres, MSSQL, Oracle, MySQL","archived":false,"fork":false,"pushed_at":"2023-11-15T15:43:04.000Z","size":945,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-01T18:18:45.529Z","etag":null,"topics":["amqp","cpp","http","iot","mqtt","mssql","mvc","odbc","or","oracle","postgres","psql","qt","rest","rpc","sqlite","websocket"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flaviomarcio.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,"governance":null}},"created_at":"2020-03-21T20:49:30.000Z","updated_at":"2023-11-27T22:17:48.000Z","dependencies_parsed_at":"2023-11-28T00:37:10.429Z","dependency_job_id":null,"html_url":"https://github.com/flaviomarcio/qorm","commit_stats":null,"previous_names":["flaviomarcio/qorm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviomarcio%2Fqorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviomarcio%2Fqorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviomarcio%2Fqorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviomarcio%2Fqorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flaviomarcio","download_url":"https://codeload.github.com/flaviomarcio/qorm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240018781,"owners_count":19734886,"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":["amqp","cpp","http","iot","mqtt","mssql","mvc","odbc","or","oracle","postgres","psql","qt","rest","rpc","sqlite","websocket"],"created_at":"2024-11-08T18:08:09.643Z","updated_at":"2026-04-12T15:08:40.677Z","avatar_url":"https://github.com/flaviomarcio.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QOrm\n\n**Builder to working querys.**\n\n\n## Working architecture\n\n\u003e## Support\n\u003e ANSI, MySQL, SQlite, Oracle, Postgres-PSQL, SQLServer-TSQL\n\n```mermaid\ngraph TD;\nA[QOrm::Query] \nA --\u003e B(SqlSuitableBuilder)\nB --\u003e BA(ANSI)--\u003e C\nB --\u003e BB(SQLite)--\u003e C\nB --\u003e BC(TSQL)--\u003e C\nB --\u003e BD(PSQL)--\u003e C\nB --\u003e BE(MySql)--\u003e C\nB --\u003e BF(Oracle)--\u003e C\nC[Strategy Selector]\nC --\u003e CA(Select)--\u003e D\nC --\u003e CB(Insert)--\u003e D\nC --\u003e CC(Update)--\u003e D\nC --\u003e CD(Upsert)--\u003e D\nC --\u003e CE(Remove)--\u003e D\nC --\u003e CF(Procedure)--\u003e D\nC --\u003e CG(Function)--\u003e D\nC --\u003e CH(Structure)--\u003e D\nC --\u003e CI(CombineSelect)--\u003e D\nD[Bind] --\u003e E\nE[QSqlQuery]\n```\n\n## Prerequisits\n\u003e```bash\n\u003e mkdir myproject;\n\u003e cd myproject;\n\u003e git clone git@github.com:flaviomarcio/qstm.git;\n\u003e git clone git@github.com:flaviomarcio/qorm.git;\n\u003e```\n\u003eCheck example in QOrm/example/crud\n\n\n## CMake Build information\n\n\u003e```\n\u003e## initial CMake parameters \n\u003e\n\u003e-GNinja\n\u003e-DCMAKE_BUILD_TYPE:STRING=Debug\n\u003e-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake\n\u003e-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}\n\u003e-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}\n\u003e-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}\n\u003e-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}\n\u003e-DCMAKE_INSTALL_PREFIX=~/build/qcrosscache/install/Debug\n\u003e```\n\n\u003e```bash\n\u003e cd qorm\n\u003e mkdir build;\n\u003e cd build;\n\u003e cmake ..\n\u003e make;\n\u003e make install;\n\u003e```\n\n## QMake Build information\n\n\u003e```bash\n\u003e cd qorm\n\u003e qmake qorm.pro\n\u003e make;\n\u003e make install;\n\u003e ls -l;\n\u003e```\n\n## Configure QMake project\n\n\u003e```c++\n\u003eCONFIG += c++17\n\u003eCONFIG += console\n\u003eCONFIG += silent\n\u003eCONFIG -= debug_and_release\n\u003eQT += gui core widgets\n\u003e\n\u003eTEMPLATE = app\n\u003eTARGET = demo\n\u003e\n\u003einclude($$PWD/../../../qstm/qstm.pri)\n\u003einclude($$PWD/../../../qorm/qorm.pri)\n\u003e\n\u003eHEADERS += \\\n\u003e    $$PWD/personModel.h \\\n\u003e    $$PWD/personController.h\n\u003e\n\u003eSOURCES += \\\n\u003e    $$PWD/personController.cpp \\\n\u003e    $$PWD/main.cpp\n\u003e\n\u003eRESOURCES += \\\n\u003e    $$PWD/settings.qrc\n\u003e```\n\n## Resource settings\n\n\u003eSettings for connection database server saved in setting.json and included in settings.qrc\n\u003e```json\n\u003e{\n\u003e   \"connection\":{\n\u003e       \"secret\": \"YzUxNDFhMDA5\",\n\u003e       \"enviroment\" : \"debug\",\n\u003e       \"paramaters\" : {\n\u003e           \"debug\":{\n\u003e               \"driver\":\"QPSQL\",\n\u003e               \"hostName\":\"localhost\",\n\u003e               \"userName\":\"localuser\",\n\u003e               \"password\":\"localuser\",\n\u003e               \"port\":5432,\n\u003e               \"dataBaseName\":\"postgres\",\n\u003e               \"schemaNames\":\"public\"\n\u003e           }\n\u003e       }\n\u003e   }\n\u003e}\n\u003e```\n\n## Implementation method for create connection using connection manager\n\n\u003eCheck example in QOrm/example/crud\n\u003e```c++\n\u003e \n\u003e//main implementation\n\u003e#include \u003cQCoreApplication\u003e\n\u003e\n\u003e//include of model and controller\n\u003e#include \"./personModel.h\"\n\u003e#include \"./personController.h\"\n\u003e\n\u003eQ_GLOBAL_STATIC(QOrm::ConnectionManager, connectionManager);\n\u003e\n\u003e//!\n\u003e//! \\brief createConnection\n\u003e//! \\param connection\n\u003e//! \\return\n\u003e//! method for create connection\n\u003ebool createConnection(QSqlDatabase\u0026connection)\n\u003e{\n\u003e    //set settings to run service\n\u003e    if(!connectionManager-\u003esetSettingsFileName(QStringLiteral(\":/settings.json\"))){\n\u003e        qWarning()\u003c\u003c\"invalid settings\";\n\u003e        return 0;\n\u003e    }\n\u003e\n\u003e    //request new connection\n\u003e    if(!connectionManager-\u003epool().get(connection))\n\u003e        return false;\n\u003e\n\u003e    return true;\n\u003e}\n\u003e\n\u003eint main(int argc, char *argv[])\n\u003e{\n\u003e     ...more\n\u003e}\n\u003e```\n\n## Implementation method for chain person controller methods\n\n\u003eCheck example in QOrm/example/crud\n\u003e```c++\n\u003e//main implementation\n\u003e\n\u003eint main(int argc, char *argv[])\n\u003e{\n\u003e    QCoreApplication a(argc, argv);\n\u003e\n\u003e    QSqlDatabase connection;\n\u003e\n\u003e    //create new connection\n\u003e    if(!createConnection(connection))\n\u003e        return 0;//normal exit\n\u003e\n\u003e    //controller person\n\u003e    PersonController controller(connection);\n\u003e\n\u003e    {//crud run\n\u003e        QVariantHash v{};//structure crud\n\u003e        qWarning()\u003c\u003ccontroller.crud(v);\n\u003e    }\n\u003e\n\u003e    //create uuid to person\n\u003e    auto personUuid=QUuid::createUuid();\n\u003e\n\u003e    {//insert/update for person\n\u003e        PersonModel model;\n\u003e        model.set_uuid(personUuid);\n\u003e        model.set_name(\"Nick\");\n\u003e        model.set_enabled(true);\n\u003e        qWarning()\u003c\u003ccontroller.upsert(model.toHash());\n\u003e    }\n\u003e\n\u003e    {//get for person\n\u003e        //by uuid\n\u003e        qWarning()\u003c\u003ccontroller.get(personUuid);\n\u003e\n\u003e        //by model body\n\u003e        PersonModel model(personUuid);\n\u003e        qWarning()\u003c\u003ccontroller.get(model.toHash());\n\u003e    }\n\u003e\n\u003e    {//list records for person\n\u003e        //by uuid\n\u003e        qWarning()\u003c\u003ccontroller.list(personUuid);\n\u003e\n\u003e        //by model body\n\u003e        PersonModel model(personUuid);\n\u003e        qWarning()\u003c\u003ccontroller.list(model.toHash());\n\u003e    }\n\u003e\n\u003e    {//remove for person\n\u003e        //by uuid\n\u003e        qWarning()\u003c\u003ccontroller.remove(personUuid);\n\u003e\n\u003e        //by model body\n\u003e        PersonModel model(personUuid);\n\u003e        qWarning()\u003c\u003ccontroller.remove(model.toHash());\n\u003e    }\n\u003e\n\u003e    {//list parent for person\n\u003e        //by uuid\n\u003e        qWarning()\u003c\u003ccontroller.listPersonParent(personUuid);\n\u003e\n\u003e        //by model body\n\u003e        PersonModel model(personUuid);\n\u003e        qWarning()\u003c\u003ccontroller.listPersonParent(model.toHash());\n\u003e    }\n\u003e\n\u003e    {//list and check for person\n\u003e        //by uuid\n\u003e        qWarning()\u003c\u003ccontroller.listPersonCheck(personUuid);\n\u003e\n\u003e        //by model body\n\u003e        PersonModel model(personUuid);\n\u003e        qWarning()\u003c\u003ccontroller.listPersonCheck(model.toHash());\n\u003e    }\n\u003e\n\u003e    {//update dt_record for person using multi tasks connection\n\u003e        qWarning()\u003c\u003ccontroller.runMultiTasks();\n\u003e    }\n\u003e\n\u003e    return a.exec();\n\u003e}\u003e\n\u003e```\n\n## Implementation PersonModel Mapper\n\n\u003eCheck example in QOrm/example/crud\n\u003e\n\u003e```c++\n\u003e#include \u003cQOrm\u003e\n\u003e//!\n\u003e//! \\brief The PersonModel class\n\u003e//! \n\u003e//! inherits of QOrm::Model\n\u003eclass PersonModel : public QOrm::Model\n\u003e{\n\u003e    Q_OBJECT\n\u003epublic:\n\u003e    QORM_MODEL(PersonModel)//make default methods for PersonModel\n\u003e    QORM_DECLARE_MODEL_DESCRIPTION(tr(\"Person\"))//description\n\u003e    QORM_DECLARE_TABLE_SCHEMA()//declare schema name in database\n\u003e    QORM_DECLARE_TABLE(tab000,_,person)//table in database\n\u003e    QORM_DECLARE_TABLE_PRIMARY_KEY(uuid)//inform PK name\n\u003e    QORM_DECLARE_TABLE_FOREIGN_KEY(parent_uuid)//declare FK\n\u003e    QORM_DESCRIPTOR_ORDERBY(name)//declare default order by\n\u003epublic:\n\u003e    QORM_DECLARE_PROPERTY(QUuid  , uuid         , uuidGenerator()   )//declare field and default value\n\u003e    QORM_DECLARE_PROPERTY(QDate  , dt_record    , QDate()           )//declare field and default value\n\u003e    QORM_DECLARE_PROPERTY(QUuid  , parent_uuid  , QUuid()           )//declare field and default value\n\u003e    QORM_DECLARE_PROPERTY(QString, name         , QString()         )//declare field and default value\n\u003e    QORM_DECLARE_PROPERTY(bool   , enabled      , false             )//declare field and default value\n\u003epublic:\n\u003e    QORM_MODEL_CONSTRUCTOR(PersonModel, QOrm::Model)//contructors for PersonModel\n\u003e};\n\u003e\n\u003e//REGISTER MODEL AND DECLARE CRUD AND DAO\n\u003eQORM_DECLARE_CRUD(PersonModel)\n\u003e```\n\n\n## Implementation PersonController\n\n\u003eCheck example in QOrm/example/crud\n\u003e\n\u003e```c++\n\u003e#include \u003cQOrm\u003e\n\u003e\n\u003e//!\n\u003e//! \\brief The PersonController class\n\u003e//!\n\u003e//! inherits of QOrm::Controller\n\u003eclass PersonController : public QOrm::Controller\n\u003e{\n\u003e    Q_OBJECT\n\u003epublic:\n\u003e    //!\n\u003e    //! \\brief personController\n\u003e    //! \\param parent\n\u003e    //!\n\u003e    //! constructor controller to pass current connection\n\u003e    QORM_CONTROLLER_CONSTRUCTOR(PersonController)\n\u003e\n\u003e    //!\n\u003e    //! \\brief crud\n\u003e    //! \\param vBody\n\u003e    //! \\return\n\u003e    //! example of CRUD\n\u003e    ResultValue \u0026crud(const QVariant \u0026vBody);\n\u003e\n\u003e    .....more\n\u003e\n\u003e};\n\n\u003e```\n\n\n## Using QOrm::ModelDao\n\u003eCheck example in QOrm/example/crud\n\u003e## Using CRUD methods\n\u003e\n\u003e```c++\n\u003eResultValue \u0026PersonController::crud(const QVariant \u0026vBody)\n\u003e{\n\u003e    //Person CRUD\n\u003e    PersonModelCRUD crud(vBody, this);\n\u003e    return this-\u003elr(crud.crudify());//return success/error and created object\n\u003e}\n\u003e```\n\n\u003e## Using  upsert/insert/update/remove methods\n\u003e\n\u003e```c++\n\u003eResultValue \u0026PersonController::upsert(const QVariant \u0026v)\n\u003e{\n\u003e    //Person generic dao\n\u003e    PersonModelGDao dao(this);\n\u003e    PersonModel model(v);\n\u003e\n\u003e    //insert or update record\n\u003e    if(!dao.upsert(model))\n\u003e        return this-\u003elr();//return error\n\u003e\n\u003e    return this-\u003elr(model.toHash());//return success and created object\n\u003e}\n\u003e\n\u003eResultValue \u0026PersonController::insert(const QVariant \u0026v)\n\u003e{\n\u003e    //Person generic dao\n\u003e    PersonModelGDao dao(this);\n\u003e\n\u003e    //remove record\n\u003e    return this-\u003elr(dao.insert(v));//return successful/error\n\u003e}\n\u003e\n\u003eResultValue \u0026PersonController::update(const QVariant \u0026v)\n\u003e{\n\u003e    //Person generic dao\n\u003e    PersonModelGDao dao(this);\n\u003e\n\u003e    //remove record\n\u003e    return this-\u003elr(dao.update(v));//return successful/error\n\u003e}\n\u003e\n\u003eResultValue \u0026PersonController::remove(const QVariant \u0026v)\n\u003e{\n\u003e    //Person generic dao\n\u003e    PersonModelGDao dao(this);\n\u003e\n\u003e    //remove record\n\u003e    return this-\u003elr(dao.remove(v));//return successful/error\n\u003e}\n\u003e```\n\u003e## Using record/recordList methods\n\u003e\n\u003e```c++\n\u003eResultValue \u0026PersonController::record(const QVariant \u0026v)\n\u003e{\n\u003e    //Person generic dao\n\u003e    PersonModelGDao dao(this);\n\u003e\n\u003e    //get record\n\u003e    return this-\u003elr(dao.record(v));//return success/error and record\n\u003e}\n\u003e\n\u003eResultValue \u0026PersonController::recordList(const QVariant \u0026v)\n\u003e{\n\u003e    //Person generic dao\n\u003e    PersonModelGDao dao(this);\n\u003e\n\u003e    //get record\n\u003e    return this-\u003elr(dao.recordList(v));//return success/error and record\n\u003e}\n\u003e```\n\u003e\n\u003e\u003e## Using  query buider strategy\n\u003e\n\u003e```c++\n\u003eResultValue \u0026PersonController::listPerson(const QVariant \u0026v)\n\u003e{\n\u003e    QOrm::Query query(this);\n\u003e\n\u003e    auto\u0026select=query.builder().select();\n\u003e\n\u003e    select\n\u003e        .fields(PersonModelR)\n\u003e        .from(PersonModelR);\n\u003e\n\u003e    select\n\u003e        .where()\n\u003e        .equal(PersonModelM.parent_uuid_field(), v);\n\u003e\n\u003e    //execute query\n\u003e    if(!query.exec())\n\u003e        return this-\u003elr();//return error\n\u003e\n\u003e    //make record list\n\u003e    return this-\u003elr(query.makeRecordList());//return successful and record list\n\u003e}\n\u003e\n\u003eResultValue \u0026PersonController::listPersonParent(const QVariant \u0026v)\n\u003e{\n\u003e    QOrm::Query query(this);\n\u003e\n\u003e    auto\u0026select=query.builder().select();\n\u003e\n\u003e    select\n\u003e        .fields()\n\u003e        .f(PersonModelM.uuid_field(\"a\"))\n\u003e        .f(PersonModelM.parent_uuid_field(\"a\"))\n\u003e        .f(PersonModelM.name_field(\"a\"))\n\u003e        .f(PersonModelM.enabled_field(\"a\"));\n\u003e    select\n\u003e        .from(PersonModelR, \"a\");\n\u003e\n\u003e    select\n\u003e        .joinInner(PersonModelR).alias(\"b\")\n\u003e        .equal(PersonModelM.parent_uuid_field(\"b\"), PersonModelM.parent_uuid_field(\"a\"));\n\u003e\n\u003e    select\n\u003e        .where()\n\u003e        .equal(PersonModelM.parent_uuid_field(\"a\"), v);\n\u003e\n\u003e    //execute query\n\u003e    if(!query.exec())\n\u003e        return this-\u003elr();//return error\n\u003e\n\u003e    //make record list\n\u003e    return this-\u003elr(query.makeRecordList());//return successful and record list\n\u003e}\n\u003e```\n\u003e\n\u003e\u003e## Using  multi tasks execute\n\u003e\n\u003e```c++\n\u003eResultValue \u0026PersonController::runMultiTasks()\n\u003e{\n\u003e    //lamba to async update record\n\u003e\n\u003e    auto errorUpdateDate=[](QSqlDatabase\u0026, const QVariant\u0026)\n\u003e    {\n\u003e        qWarning()\u003c\u003c\"It\\'s not OK\";\n\u003e        //..action to error\n\u003e        return QVariant();\n\u003e    };\n\u003e\n\u003e    auto successUpdateDate=[](QSqlDatabase\u0026, const QVariant\u0026)\n\u003e    {\n\u003e        qWarning()\u003c\u003c\"it\\'s OK\";\n\u003e        //..action to success\n\u003e        return QVariant();\n\u003e    };\n\u003e\n\u003e    auto executeUpdateDate=[](QSqlDatabase\u0026connection, const QVariant\u0026record){\n\u003e        //Person generic dao\n\u003e        PersonModelGDao dao;\n\u003e        dao.setConnection(connection);//individual connection to task\n\u003e        PersonModel model(record);//load body model\n\u003e        model.set_dt_record(QDate::currentDate());//update dt\n\u003e\n\u003e        if(!dao.upsert(model))//insert/update person\n\u003e            return dao.lr().toHash();//record body error\n\u003e\n\u003e        return model.toHash();//return new body object\n\u003e    };\n\u003e\n\u003e    PersonModelGDao dao(this);//dao to current connection\n\u003e    auto vList=dao.recordList().resultToList();//list all personModel record\n\u003e\n\u003e    QOrm::TaskRunner taskRunner(this);//task runner controller\n\u003e    taskRunner\n\u003e        .slotCount(QThread::idealThreadCount())//maximum thread in actual machine\n\u003e        .values(vList)//personModel records\n\u003e        .onExecute(executeUpdateDate)//lambda to async execute\n\u003e        .onFailed(errorUpdateDate)//lambda to error notify\n\u003e        .onSuccess(successUpdateDate)//lambda to success notify\n\u003e        .start();//wait to finish\n\u003e\n\u003e    return this-\u003elr(taskRunner.lr());//return successful/error\n\u003e\n\u003e}\n\u003e```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaviomarcio%2Fqorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflaviomarcio%2Fqorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaviomarcio%2Fqorm/lists"}