├── examples ├── CMakeLists.txt ├── orm │ ├── CMakeLists.txt │ ├── orm.pro │ ├── navigationdb │ │ ├── marker.png │ │ ├── navigationdb.qrc │ │ ├── navigationdb-qt6.qrc │ │ ├── qtorm.json │ │ ├── navigationdb.qbs │ │ ├── navigationdb.pro │ │ ├── CMakeLists.txt │ │ └── domain │ │ │ ├── province.h │ │ │ ├── province.cpp │ │ │ ├── community.h │ │ │ └── community.cpp │ └── orm.qbs ├── examples.pro └── examples.qbs ├── src ├── src.pro ├── src.qbs ├── orm │ ├── qormqueryresult.cpp │ ├── qormabstractprovider.cpp │ ├── qormorder.cpp │ ├── doc │ │ └── qtorm.qdocconf │ ├── qormfilter.cpp │ ├── qormmetadata_p.h │ ├── qormerror.cpp │ ├── qormorder.h │ ├── orm.pro │ ├── qormclassproperty.h │ ├── qormentitylistmodel.cpp │ ├── qormerror.h │ ├── qormrelation.h │ ├── qormtransactiontoken.h │ ├── qormclassproperty.cpp │ ├── qormentityinstancecache.h │ ├── qormsqliteconfiguration.cpp │ ├── qormabstractprovider.h │ ├── qormmetadatacache.h │ ├── qormsqliteconfiguration.h │ ├── qormsessionconfiguration.h │ ├── qormfilter.h │ ├── qormmetadata.h │ ├── qormtransactiontoken.cpp │ ├── qormsqliteprovider.h │ ├── qormpropertymapping.h │ ├── qormquery.h │ ├── qormrelation.cpp │ ├── qormmetadata.cpp │ ├── qormentityinstancecache.cpp │ ├── qormsession.h │ ├── orm.qbs │ └── qormquerybuilder.h └── CMakeLists.txt ├── tests ├── auto │ ├── qormqueryresult │ │ ├── domain │ │ │ ├── person.cpp │ │ │ └── person.h │ │ ├── queryresult.qrc │ │ ├── CMakeLists.txt │ │ ├── qtorm.json │ │ └── tst_queryresult.cpp │ ├── qormentitylistmodel │ │ ├── resource.qrc │ │ ├── qtorm.json │ │ ├── CMakeLists.txt │ │ ├── qormentitylistmodel.pro │ │ ├── qormentitylistmodel.qbs │ │ ├── domain │ │ │ ├── province.cpp │ │ │ ├── town.cpp │ │ │ ├── town.h │ │ │ └── province.h │ │ └── tst_qormentitylistmodel.cpp │ ├── qormfilterexpression │ │ ├── CMakeLists.txt │ │ ├── qormfilterexpression.pro │ │ └── qormfilterexpression.qbs │ ├── cmake │ │ ├── cmake.pro │ │ ├── CMakeLists.txt │ │ └── qtorm_add_unit_test.cmake │ ├── domainclasses │ │ ├── CMakeLists.txt │ │ ├── domainclasses.qrc │ │ ├── qtorm.json │ │ ├── domainclasses.pro │ │ ├── qtorm_bypass_schema.json │ │ └── domainclasses.qbs │ ├── qormsession │ │ ├── qtorm.json │ │ ├── qtorm_append_schema.json │ │ ├── qtorm_bypass_schema.json │ │ ├── qtorm_update_schema.json │ │ ├── ormsession.qrc │ │ ├── CMakeLists.txt │ │ ├── qormsession.pro │ │ ├── qormsession.qbs │ │ └── domain │ │ │ ├── province.cpp │ │ │ ├── town.cpp │ │ │ ├── town.h │ │ │ ├── province.h │ │ │ ├── person.cpp │ │ │ └── person.h │ ├── auto.pro │ ├── qormentityinstancecache │ │ ├── CMakeLists.txt │ │ ├── qormentityinstancecache.pro │ │ ├── qormentityinstancecache.qbs │ │ ├── domain │ │ │ ├── province.cpp │ │ │ ├── town.cpp │ │ │ ├── town.h │ │ │ └── province.h │ │ └── tst_entityinstancecache.cpp │ ├── qormmetadatacache │ │ ├── CMakeLists.txt │ │ ├── qormmetadatacache.pro │ │ ├── qormmetadatacache.qbs │ │ └── domain │ │ │ ├── person.cpp │ │ │ ├── province.cpp │ │ │ ├── province.h │ │ │ ├── town.cpp │ │ │ ├── person.h │ │ │ ├── town.h │ │ │ ├── withenum.cpp │ │ │ └── withenum.h │ ├── CMakeLists.txt │ ├── auto.qbs │ └── qormsqlitestatementgenerator │ │ ├── CMakeLists.txt │ │ ├── qormsqlitestatementgenerator.pro │ │ ├── qormsqlitestatementgenerator.qbs │ │ └── domain │ │ ├── community.cpp │ │ ├── person.cpp │ │ ├── province.cpp │ │ ├── withqvariant.cpp │ │ ├── person.h │ │ ├── withqvariant.h │ │ ├── town.cpp │ │ ├── town.h │ │ ├── withenum.cpp │ │ ├── province.h │ │ ├── withenum.h │ │ └── community.h ├── tests.pro ├── CMakeLists.txt └── tests.qbs ├── qws19.pdf ├── sync.profile ├── .qmake.conf ├── qtorm.pro ├── configure.json ├── cmake ├── ExtractClassNames.cmake ├── GetGeneratedHeaders.cmake └── GenerateHeaders.cmake ├── .gitignore ├── .github └── workflows │ ├── qmake.yml │ ├── qbs-linux.yml │ ├── cmake-linux.yml │ └── cmake-windows.yml ├── qtorm.qbs ├── _clang-format └── CMakeLists.txt /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(orm) 2 | -------------------------------------------------------------------------------- /src/src.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += orm -------------------------------------------------------------------------------- /examples/orm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(navigationdb) 2 | -------------------------------------------------------------------------------- /tests/auto/qormqueryresult/domain/person.cpp: -------------------------------------------------------------------------------- 1 | #include "person.h" -------------------------------------------------------------------------------- /examples/orm/orm.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS += navigationdb -------------------------------------------------------------------------------- /qws19.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpurgin/qtorm/HEAD/qws19.pdf -------------------------------------------------------------------------------- /sync.profile: -------------------------------------------------------------------------------- 1 | %modules = ( 2 | "QtOrm" => "$basedir/src/orm", 3 | ); 4 | -------------------------------------------------------------------------------- /tests/tests.pro: -------------------------------------------------------------------------------- 1 | requires(qtHaveModule(orm)) 2 | 3 | TEMPLATE = subdirs 4 | SUBDIRS += auto 5 | -------------------------------------------------------------------------------- /examples/examples.pro: -------------------------------------------------------------------------------- 1 | requires(qtHaveModule(orm)) 2 | 3 | TEMPLATE = subdirs 4 | SUBDIRS += orm 5 | -------------------------------------------------------------------------------- /src/src.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | Project { 4 | references: [ 5 | "orm/orm.qbs", 6 | ] 7 | } 8 | 9 | -------------------------------------------------------------------------------- /examples/examples.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | Project { 4 | references: [ 5 | "orm/orm.qbs", 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpurgin/qtorm/HEAD/examples/orm/navigationdb/marker.png -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Qt${QTORM_QT_VERSION_MAJOR} COMPONENTS Test REQUIRED) 2 | 3 | add_subdirectory(auto) 4 | -------------------------------------------------------------------------------- /tests/tests.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | Project { 4 | references: [ 5 | "auto/auto.qbs", 6 | ] 7 | } 8 | 9 | -------------------------------------------------------------------------------- /examples/orm/orm.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | Project { 4 | references: [ 5 | "navigationdb/navigationdb.qbs", 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.qmake.conf: -------------------------------------------------------------------------------- 1 | load(qt_build_config) 2 | 3 | CONFIG += warning_clean 4 | DEFINES += QT_NO_FOREACH 5 | 6 | MODULE_VERSION = $${QT_VERSION} 7 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qtorm.json 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/auto/qormfilterexpression/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qtorm_add_unit_test(NAME tst_ormfilterexpression SOURCES 2 | tst_ormfilterexpression.cpp 3 | ) 4 | -------------------------------------------------------------------------------- /tests/auto/cmake/cmake.pro: -------------------------------------------------------------------------------- 1 | # Cause make to do nothing. 2 | TEMPLATE = subdirs 3 | 4 | CMAKE_QT_MODULES_UNDER_TEST = orm 5 | 6 | CONFIG += ctest_testcase 7 | -------------------------------------------------------------------------------- /tests/auto/domainclasses/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qtorm_add_unit_test(NAME tst_domainclasses SOURCES 2 | tst_domainclasses.cpp 3 | 4 | domainclasses.qrc 5 | ) 6 | -------------------------------------------------------------------------------- /tests/auto/qormqueryresult/queryresult.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qtorm.json 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/auto/domainclasses/domainclasses.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qtorm.json 4 | qtorm_bypass_schema.json 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/auto/qormqueryresult/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qtorm_add_unit_test(NAME tst_queryresult SOURCES 2 | tst_queryresult.cpp 3 | 4 | domain/person.cpp 5 | domain/person.h 6 | 7 | queryresult.qrc 8 | ) 9 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/navigationdb.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qtorm.json 4 | main.qml 5 | marker.png 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/auto/qormfilterexpression/qormfilterexpression.pro: -------------------------------------------------------------------------------- 1 | QT = core testlib orm 2 | 3 | CONFIG += testcase warn_on silent c++17 4 | 5 | TARGET = tst_ormfilterexpression 6 | 7 | SOURCES += tst_ormfilterexpression.cpp 8 | 9 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/navigationdb-qt6.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qtorm.json 4 | main-qt6.qml 5 | marker.png 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/auto/qormsession/qtorm.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": "testdb.db", 6 | "schemaMode": "recreate", 7 | "verbose": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/auto/auto.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | domainclasses \ 5 | qormentityinstancecache \ 6 | qormmetadatacache \ 7 | qormsession \ 8 | qormfilterexpression \ 9 | qormsqlitestatementgenerator 10 | -------------------------------------------------------------------------------- /tests/auto/domainclasses/qtorm.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": "testdb.db", 6 | "schemaMode": "recreate", 7 | "verbose": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/auto/qormqueryresult/qtorm.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": "testdb.db", 6 | "schemaMode": "recreate", 7 | "verbose": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/auto/qormentityinstancecache/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qtorm_add_unit_test(NAME tst_entityinstancecache SOURCES 2 | tst_entityinstancecache.cpp 3 | domain/province.cpp 4 | domain/town.cpp 5 | 6 | domain/province.h 7 | domain/town.h 8 | ) 9 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/qtorm.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": ":memory:", 6 | "schemaMode": "recreate", 7 | "verbose": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/qtorm.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": "navigationdb.db", 6 | "verbose": true, 7 | "schemaMode": "recreate" 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/auto/domainclasses/domainclasses.pro: -------------------------------------------------------------------------------- 1 | QT = core testlib orm orm-private 2 | 3 | CONFIG += testcase warn_on silent c++17 4 | 5 | TARGET = tst_domainclasses 6 | 7 | SOURCES += tst_domainclasses.cpp \ 8 | 9 | RESOURCES += domainclasses.qrc 10 | -------------------------------------------------------------------------------- /tests/auto/domainclasses/qtorm_bypass_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": "testdb.db", 6 | "schemaMode": "bypass", 7 | "verbose": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/auto/qormsession/qtorm_append_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": "testdb.db", 6 | "schemaMode": "append", 7 | "verbose": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/auto/qormsession/qtorm_bypass_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": "testdb.db", 6 | "schemaMode": "bypass", 7 | "verbose": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/auto/qormsession/qtorm_update_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "sqlite", 3 | "verbose": true, 4 | "sqlite": { 5 | "databaseName": "testdb.db", 6 | "schemaMode": "update", 7 | "verbose": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /qtorm.pro: -------------------------------------------------------------------------------- 1 | requires(qtHaveModule(sql)) 2 | 3 | lessThan(QT_MAJOR_VERSION, 5) { 4 | message("Cannot build current QtOrm sources with Qt version $${QT_VERSION}.") 5 | } 6 | 7 | QTORM_BUILD_PARTS = libs tests examples 8 | 9 | load(configure) 10 | load(qt_parts) 11 | -------------------------------------------------------------------------------- /tests/auto/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | cmake_minimum_required(VERSION 2.8) 3 | 4 | project(qmake_cmake_files) 5 | 6 | enable_testing() 7 | 8 | find_package(Qt5Core REQUIRED) 9 | 10 | include("${_Qt5CTestMacros}") 11 | 12 | test_module_includes( 13 | Orm 14 | ) 15 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qtorm_add_unit_test(NAME tst_ormentitylistmodel SOURCES 2 | tst_qormentitylistmodel.cpp 3 | 4 | domain/province.cpp 5 | domain/town.cpp 6 | 7 | domain/province.h 8 | domain/town.h 9 | 10 | resource.qrc 11 | ) 12 | -------------------------------------------------------------------------------- /tests/auto/qormsession/ormsession.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qtorm.json 4 | qtorm_bypass_schema.json 5 | qtorm_update_schema.json 6 | qtorm_append_schema.json 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qtorm_add_unit_test(NAME tst_metadatacachetest SOURCES 2 | tst_metadatacachetest.cpp 3 | 4 | domain/person.cpp 5 | domain/province.cpp 6 | domain/town.cpp 7 | domain/withenum.cpp 8 | 9 | domain/person.h 10 | domain/province.h 11 | domain/town.h 12 | domain/withenum.h 13 | ) -------------------------------------------------------------------------------- /tests/auto/domainclasses/domainclasses.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | QtApplication { 4 | name: "tst_domainclasses" 5 | type: ["application", "autotest"] 6 | cpp.cxxLanguageVersion: "c++17" 7 | Depends { name: "Qt"; submodules: ["core", "test"] } 8 | Depends { name: "QtOrm" } 9 | files: ["tst_domainclasses.cpp", "domainclasses.qrc"] 10 | } 11 | -------------------------------------------------------------------------------- /tests/auto/qormfilterexpression/qormfilterexpression.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | QtApplication { 4 | name: "tst_ormfilterexpression" 5 | type: ["application", "autotest"] 6 | cpp.cxxLanguageVersion: "c++17" 7 | Depends { name: "Qt"; submodules: ["core", "test"] } 8 | Depends { name: "QtOrm" } 9 | files: ["tst_ormfilterexpression.cpp"] 10 | } 11 | -------------------------------------------------------------------------------- /tests/auto/qormsession/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qtorm_add_unit_test(NAME tst_ormsession SOURCES 2 | tst_ormsession.cpp 3 | 4 | domain/person.cpp 5 | domain/province.cpp 6 | domain/town.cpp 7 | 8 | domain/person.h 9 | domain/province.h 10 | domain/town.h 11 | 12 | ormsession.qrc 13 | 14 | LINK_LIBRARIES Qt${QTORM_QT_VERSION_MAJOR}::Sql 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/qormentitylistmodel.pro: -------------------------------------------------------------------------------- 1 | QT = core testlib orm 2 | 3 | CONFIG += testcase warn_on silent c++17 4 | 5 | TARGET = tst_ormentitylistmodel 6 | 7 | SOURCES += tst_ormentitylistmodel.cpp \ 8 | domain/province.cpp \ 9 | domain/town.cpp \ 10 | 11 | HEADERS += \ 12 | domain/province.h \ 13 | domain/town.h \ 14 | 15 | RESOURCES += resource.qrc 16 | -------------------------------------------------------------------------------- /tests/auto/qormentityinstancecache/qormentityinstancecache.pro: -------------------------------------------------------------------------------- 1 | QT += testlib orm 2 | QT -= gui 3 | 4 | CONFIG += qt console warn_on depend_includepath testcase c++17 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += tst_entityinstancecache.cpp \ 10 | domain/province.cpp \ 11 | domain/town.cpp 12 | 13 | HEADERS += \ 14 | domain/province.h \ 15 | domain/town.h 16 | -------------------------------------------------------------------------------- /tests/auto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(cmake/qtorm_add_unit_test.cmake) 2 | 3 | add_subdirectory(domainclasses) 4 | add_subdirectory(qormentityinstancecache) 5 | add_subdirectory(qormentitylistmodel) 6 | add_subdirectory(qormfilterexpression) 7 | add_subdirectory(qormmetadatacache) 8 | add_subdirectory(qormqueryresult) 9 | add_subdirectory(qormsession) 10 | add_subdirectory(qormsqlitestatementgenerator) 11 | -------------------------------------------------------------------------------- /tests/auto/qormsession/qormsession.pro: -------------------------------------------------------------------------------- 1 | QT = core testlib orm orm-private 2 | 3 | CONFIG += testcase warn_on silent c++17 4 | 5 | TARGET = tst_ormsession 6 | 7 | SOURCES += tst_ormsession.cpp \ 8 | domain/province.cpp \ 9 | domain/town.cpp \ 10 | domain/person.cpp \ 11 | 12 | HEADERS += \ 13 | domain/province.h \ 14 | domain/town.h \ 15 | domain/person.h \ 16 | 17 | RESOURCES += ormsession.qrc 18 | -------------------------------------------------------------------------------- /tests/auto/auto.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | Project { 4 | references: [ 5 | "domainclasses/domainclasses.qbs", 6 | "qormentityinstancecache/qormentityinstancecache.qbs", 7 | "qormmetadatacache/qormmetadatacache.qbs", 8 | "qormsession/qormsession.qbs", 9 | "qormfilterexpression/qormfilterexpression.qbs", 10 | "qormsqlitestatementgenerator/qormsqlitestatementgenerator.qbs", 11 | ] 12 | } 13 | 14 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/navigationdb.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | QtApplication { 4 | name: "navigationdb" 5 | cpp.cxxLanguageVersion: "c++17" 6 | Depends { name: "Qt"; submodules: ["core", "quick"] } 7 | Depends { name: "QtOrm" } 8 | files: [ 9 | "domain/province.cpp", "domain/province.h", 10 | "domain/community.cpp", "domain/community.h", 11 | "main.cpp", 12 | "navigationdb.qrc", 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /tests/auto/qormentityinstancecache/qormentityinstancecache.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | QtApplication { 4 | name: "tst_entityinstancecache" 5 | type: ["application", "autotest"] 6 | cpp.cxxLanguageVersion: "c++17" 7 | Depends { name: "Qt"; submodules: ["core", "test"] } 8 | Depends { name: "QtOrm" } 9 | files: [ 10 | "tst_entityinstancecache.cpp", 11 | "domain/province.cpp", "domain/province.h", 12 | "domain/town.cpp", "domain/town.h", 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /configure.json: -------------------------------------------------------------------------------- 1 | { 2 | "module": "orm", 3 | "depends": [ 4 | "core", 5 | "sql" 6 | ], 7 | 8 | "features": { 9 | "sqlite": { 10 | "label": "SQLite Backend", 11 | "purpose": "Enables OR-mapping to SQLite databases.", 12 | "condition": true 13 | } 14 | }, 15 | 16 | "summary": [{ 17 | "section": "Qt ORM", 18 | "entries": [ 19 | "sqlite" 20 | ] 21 | }] 22 | 23 | } -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/qormentitylistmodel.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | QtApplication { 4 | name: "tst_ormentitylistmodel" 5 | type: ["application", "autotest"] 6 | cpp.cxxLanguageVersion: "c++17" 7 | Depends { name: "Qt"; submodules: ["core", "test"] } 8 | Depends { name: "QtOrm" } 9 | files: [ 10 | "domain/province.cpp", "domain/province.h", 11 | "domain/town.cpp", "domain/town.h", 12 | "tst_ormentitylistmodel.cpp", 13 | "resource.qrc"] 14 | } 15 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/qormmetadatacache.pro: -------------------------------------------------------------------------------- 1 | QT += testlib orm 2 | QT -= gui 3 | 4 | CONFIG += qt console warn_on depend_includepath testcase c++17 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += tst_metadatacachetest.cpp \ 10 | domain/person.cpp \ 11 | domain/province.cpp \ 12 | domain/town.cpp \ 13 | domain/withenum.cpp 14 | 15 | HEADERS += \ 16 | domain/person.h \ 17 | domain/province.h \ 18 | domain/town.h \ 19 | domain/withenum.h 20 | 21 | -------------------------------------------------------------------------------- /cmake/ExtractClassNames.cmake: -------------------------------------------------------------------------------- 1 | function(ExtractClassNames HEADER OUTPUT_VARIABLE) 2 | set(RESULT "") 3 | get_filename_component(OUTPUT_HEADER "${HEADER}" NAME) 4 | 5 | file(STRINGS ${HEADER} LINES) 6 | 7 | foreach (LINE ${LINES}) 8 | if ("${LINE}" MATCHES "class[\t ]+(Q_ORM_EXPORT[\t ]+)?(QOrm[A-Za-z0-9_]+)[^;]*$") 9 | list(APPEND RESULT ${CMAKE_MATCH_2}) 10 | endif() 11 | endforeach() 12 | 13 | set("${OUTPUT_VARIABLE}" ${RESULT} PARENT_SCOPE) 14 | endfunction() 15 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/navigationdb.pro: -------------------------------------------------------------------------------- 1 | QT += orm orm-private # enable the ORM module 2 | QT += quick 3 | 4 | CONFIG += c++17 # required by QtOrm 5 | 6 | TARGET = navigationdb 7 | TEMPLATE = app 8 | 9 | HEADERS += \ 10 | domain/province.h \ 11 | domain/community.h \ 12 | 13 | SOURCES += \ 14 | domain/province.cpp \ 15 | domain/community.cpp \ 16 | main.cpp 17 | 18 | target.path = $$[QT_INSTALL_EXAMPLES]/orm/navigationdb 19 | INSTALLS += target 20 | 21 | 22 | RESOURCES += navigationdb.qrc 23 | 24 | -------------------------------------------------------------------------------- /tests/auto/qormsession/qormsession.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | QtApplication { 4 | name: "tst_ormsession" 5 | type: ["application", "autotest"] 6 | cpp.cxxLanguageVersion: "c++17" 7 | Depends { name: "Qt"; submodules: ["core", "sql", "test"] } 8 | Depends { name: "QtOrm" } 9 | files: [ 10 | "domain/person.cpp", "domain/person.h", 11 | "domain/province.cpp", "domain/province.h", 12 | "domain/town.cpp", "domain/town.h", 13 | "tst_ormsession.cpp", 14 | "ormsession.qrc"] 15 | } 16 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qtorm_add_unit_test(NAME tst_sqlitestatementgenerator SOURCES 2 | tst_sqlitestatementgenerator.cpp 3 | 4 | domain/province.h 5 | domain/province.cpp 6 | 7 | domain/town.h 8 | domain/town.cpp 9 | 10 | domain/person.h 11 | domain/person.cpp 12 | 13 | domain/community.h 14 | domain/community.cpp 15 | 16 | domain/withqvariant.h 17 | domain/withqvariant.cpp 18 | 19 | domain/withenum.h 20 | domain/withenum.cpp 21 | ) 22 | 23 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/qormmetadatacache.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | QtApplication { 4 | name: "tst_metadatacachetest" 5 | type: ["application", "autotest"] 6 | cpp.cxxLanguageVersion: "c++17" 7 | Depends { name: "Qt"; submodules: ["core", "test"] } 8 | Depends { name: "QtOrm" } 9 | files: [ 10 | "tst_metadatacachetest.cpp", 11 | "domain/person.cpp", "domain/person.h", 12 | "domain/province.cpp", "domain/province.h", 13 | "domain/town.cpp", "domain/town.h", 14 | "domain/withenum.cpp", "domain/withenum.h" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Qt${QTORM_QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED) 2 | 3 | if (QTORM_QT_VERSION_MAJOR EQUAL 6) 4 | set(RESOURCES navigationdb-qt6.qrc) 5 | else() 6 | set(RESOURCES navigationdb.qrc) 7 | endif() 8 | 9 | add_executable(navigationdb 10 | domain/province.h 11 | domain/community.h 12 | 13 | domain/province.cpp 14 | domain/community.cpp 15 | main.cpp 16 | 17 | ${RESOURCES} 18 | ) 19 | 20 | target_link_libraries(navigationdb PUBLIC qtorm Qt${QTORM_QT_VERSION_MAJOR}::Core Qt${QTORM_QT_VERSION_MAJOR}::Quick) 21 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/qormsqlitestatementgenerator.pro: -------------------------------------------------------------------------------- 1 | QT += testlib orm orm-private 2 | QT -= gui 3 | 4 | CONFIG += qt console warn_on depend_includepath testcase c++17 5 | CONFIG -= app_bundle 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += tst_sqlitestatementgenerator.cpp \ 10 | domain/province.cpp \ 11 | domain/town.cpp \ 12 | domain/person.cpp \ 13 | domain/community.cpp \ 14 | domain/withenum.cpp \ 15 | domain/withqvariant.cpp 16 | 17 | HEADERS += \ 18 | domain/province.h \ 19 | domain/town.h \ 20 | domain/person.h \ 21 | domain/community.h \ 22 | domain/withenum.h \ 23 | domain/withqvariant.h 24 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/qormsqlitestatementgenerator.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | 3 | QtApplication { 4 | name: "tst_sqlitestatementgenerator" 5 | type: ["application", "autotest"] 6 | cpp.cxxLanguageVersion: "c++17" 7 | Depends { name: "Qt"; submodules: ["core", "test"] } 8 | Depends { name: "QtOrm" } 9 | files: [ 10 | "domain/person.cpp", "domain/person.h", 11 | "domain/province.cpp", "domain/province.h", 12 | "domain/town.cpp", "domain/town.h", 13 | "domain/community.cpp", "domain/community.h", 14 | "domain/withenum.cpp", "domain/withenum.h", 15 | "domain/withqvariant.cpp", "domain/withqvariant.h", 16 | "tst_sqlitestatementgenerator.cpp"] 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | *.slo 3 | *.lo 4 | *.o 5 | *.a 6 | *.la 7 | *.lai 8 | *.so 9 | *.dll 10 | *.dylib 11 | 12 | # Qt-es 13 | object_script.*.Release 14 | object_script.*.Debug 15 | *_plugin_import.cpp 16 | /.qmake.cache 17 | /.qmake.stash 18 | *.pro.user 19 | *.pro.user.* 20 | *.qbs.user 21 | *.qbs.user.* 22 | *.moc 23 | moc_*.cpp 24 | moc_*.h 25 | qrc_*.cpp 26 | ui_*.h 27 | *.qmlc 28 | *.jsc 29 | Makefile* 30 | *build-* 31 | 32 | # Qt unit tests 33 | target_wrapper.* 34 | 35 | # QtCreator 36 | *.autosave 37 | 38 | # QtCreator Qml 39 | *.qmlproject.user 40 | *.qmlproject.user.* 41 | 42 | # QtCreator CMake 43 | CMakeLists.txt.user* 44 | 45 | # QtCreator 4.8< compilation database 46 | compile_commands.json 47 | 48 | # QtCreator local machine specific files for imported projects 49 | *creator.user* 50 | 51 | # QtCreator 14+ build directory 52 | build/ 53 | 54 | # CLion directories 55 | .idea/ 56 | cmake-build*/ -------------------------------------------------------------------------------- /cmake/GetGeneratedHeaders.cmake: -------------------------------------------------------------------------------- 1 | function(GetGeneratedHeaders OUTPUT_DIRECTORY PUBLIC_HEADERS PRIVATE_HEADERS OUTPUT_VARIABLE) 2 | set(RESULT "${OUTPUT_DIRECTORY}/QtOrm") 3 | 4 | foreach(HEADER ${PUBLIC_HEADERS}) 5 | get_filename_component(OUTPUT_HEADER "${HEADER}" NAME) 6 | 7 | list(APPEND RESULT "${OUTPUT_DIRECTORY}/${OUTPUT_HEADER}") 8 | ExtractClassNames(${HEADER} CLASS_NAMES) 9 | 10 | foreach(CLASS_NAME ${CLASS_NAMES}) 11 | list(APPEND RESULT "${OUTPUT_DIRECTORY}/${CLASS_NAME}") 12 | endforeach() 13 | endforeach() 14 | 15 | foreach(HEADER ${PRIVATE_HEADERS}) 16 | get_filename_component(OUTPUT_HEADER "${HEADER}" NAME) 17 | 18 | list(APPEND RESULT "${OUTPUT_DIRECTORY}/private/${OUTPUT_HEADER}") 19 | endforeach() 20 | 21 | list(REMOVE_DUPLICATES RESULT) 22 | 23 | set("${OUTPUT_VARIABLE}" ${RESULT} PARENT_SCOPE) 24 | endfunction() 25 | -------------------------------------------------------------------------------- /tests/auto/cmake/qtorm_add_unit_test.cmake: -------------------------------------------------------------------------------- 1 | function(qtorm_add_unit_test) 2 | set(OPTIONS) 3 | set(ONE_VALUE_ARGS NAME) 4 | set(MULTI_VALUE_ARGS SOURCES LINK_LIBRARIES) 5 | 6 | cmake_parse_arguments(QTORM_ADD_UNIT_TEST "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN}) 7 | 8 | add_executable(${QTORM_ADD_UNIT_TEST_NAME} ${QTORM_ADD_UNIT_TEST_SOURCES}) 9 | target_link_libraries(${QTORM_ADD_UNIT_TEST_NAME} Qt${QTORM_QT_VERSION_MAJOR}::Test qtorm ${QTORM_ADD_UNIT_TEST_LINK_LIBRARIES}) 10 | 11 | add_test(NAME ${QTORM_ADD_UNIT_TEST_NAME} COMMAND ${QTORM_ADD_UNIT_TEST_NAME}) 12 | 13 | if (WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.22.0") 14 | set_tests_properties(${QTORM_ADD_UNIT_TEST_NAME} PROPERTIES 15 | ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${CMAKE_BINARY_DIR}/src;PATH=path_list_prepend:${_qt5Core_install_prefix}/bin") 16 | endif() 17 | endfunction() 18 | -------------------------------------------------------------------------------- /tests/auto/qormqueryresult/domain/person.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Person : public QObject 6 | { 7 | Q_OBJECT 8 | 9 | Q_PROPERTY(long id READ id WRITE setId NOTIFY idChanged) 10 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 11 | 12 | public: 13 | Q_INVOKABLE Person() = default; 14 | 15 | [[nodiscard]] long id() const { return m_id; } 16 | void setId(long id) 17 | { 18 | if (m_id != id) 19 | { 20 | m_id = id; 21 | emit idChanged(); 22 | } 23 | } 24 | 25 | [[nodiscard]] QString name() const { return m_name; } 26 | void setName(QString name) 27 | { 28 | if (m_name != name) 29 | { 30 | m_name = name; 31 | emit nameChanged(); 32 | } 33 | } 34 | 35 | signals: 36 | void idChanged(); 37 | void nameChanged(); 38 | 39 | private: 40 | long m_id{-1}; 41 | QString m_name; 42 | }; 43 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/community.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * 4 | * This file is part of QtOrm library. 5 | * 6 | * QtOrm is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * QtOrm is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with QtOrm. If not, see . 18 | */ 19 | 20 | #include "community.h" 21 | 22 | Community::Community(QObject* parent) 23 | : QObject{parent} 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /.github/workflows/qmake.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | jobs: 4 | build: 5 | strategy: 6 | fail-fast: false 7 | matrix: 8 | qtversion: [ '5.12.*', '5.15.*' ] 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: Install Qt 16 | uses: jurplel/install-qt-action@v3 17 | with: 18 | version: ${{ matrix.qtversion }} 19 | archives: 'qtbase qtdeclarative qtquickcontrols2 icu' 20 | 21 | - name: Create Build Environment 22 | shell: bash 23 | run: mkdir -p ${{runner.workspace}}/build 24 | 25 | - name: Configure QMake 26 | shell: bash 27 | working-directory: ${{runner.workspace}}/build 28 | run: qmake ${GITHUB_WORKSPACE}/qtorm.pro 29 | 30 | - name: Build 31 | working-directory: ${{runner.workspace}}/build 32 | shell: bash 33 | run: make 34 | 35 | - name: Test 36 | working-directory: ${{runner.workspace}}/build 37 | shell: bash 38 | run: make check 39 | -------------------------------------------------------------------------------- /src/orm/qormqueryresult.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormqueryresult.h" 22 | #include "qormerror.h" 23 | 24 | #include 25 | 26 | QT_BEGIN_NAMESPACE 27 | 28 | QT_END_NAMESPACE 29 | -------------------------------------------------------------------------------- /qtorm.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | import qbs.FileInfo 3 | 4 | Project { 5 | name: "qtorm" 6 | 7 | minimumQbsVersion: "1.6" 8 | property bool withDocumentation: true 9 | property bool withExamples: true 10 | property bool withTests: true 11 | 12 | references: [ 13 | "src/src.qbs", 14 | ] 15 | 16 | // SubProject { 17 | // filePath: "doc/doc.qbs" 18 | // Properties { 19 | // condition: parent.withDocumentation 20 | // } 21 | // } 22 | 23 | SubProject { 24 | filePath: "examples/examples.qbs" 25 | Properties { 26 | condition: parent.withExamples 27 | } 28 | } 29 | SubProject { 30 | filePath: "tests/tests.qbs" 31 | Properties { 32 | condition: parent.withTests 33 | } 34 | } 35 | AutotestRunner { 36 | Depends { name: "QtOrm" } 37 | environment: { 38 | var path = FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix, "lib"); 39 | return base.concat(["LD_LIBRARY_PATH=" + path]); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/orm/qormabstractprovider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormabstractprovider.h" 22 | 23 | QT_BEGIN_NAMESPACE 24 | 25 | QOrmAbstractProvider::~QOrmAbstractProvider() = default; 26 | 27 | QT_END_NAMESPACE 28 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/person.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Dmitriy Purgin 3 | * 4 | * This file is part of QtOrm library. 5 | * 6 | * QtOrm is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * QtOrm is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with QtOrm. If not, see . 18 | */ 19 | 20 | 21 | #include "person.h" 22 | 23 | void Person::setId(long id) 24 | { 25 | if (m_id != id) 26 | { 27 | m_id = id; 28 | emit idChanged(); 29 | } 30 | } 31 | 32 | void Person::setName(const QString &name) 33 | { 34 | if (m_name != name) 35 | { 36 | m_name = name; 37 | emit nameChanged(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /.github/workflows/qbs-linux.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | jobs: 4 | build: 5 | strategy: 6 | fail-fast: false 7 | matrix: 8 | qtversion: [ '5.15.*' ] 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: Install Qt 16 | uses: jurplel/install-qt-action@v3 17 | with: 18 | version: ${{ matrix.qtversion }} 19 | archives: 'qtbase qtdeclarative qtquickcontrols2 icu' 20 | 21 | - name: Install Qbs 22 | run: | 23 | wget --no-check-certificate --content-disposition https://download.qt.io/official_releases/qbs/1.24.1/qbs-linux-x86_64-1.24.1.tar.gz 24 | tar xzvf qbs-linux-x86_64-1.24.1.tar.gz 25 | QBS_BIN_DIR="${GITHUB_WORKSPACE}/qbs-linux-x86_64-1.24.1/bin" 26 | echo "$QBS_BIN_DIR" >> ${GITHUB_PATH} 27 | shell: bash 28 | 29 | - name: Configure Qbs 30 | run: | 31 | qbs-setup-toolchains $(command -v gcc) gcc 32 | qbs-setup-qt $(command -v qmake) qt5 33 | qbs-config profiles.qt5.baseProfile gcc 34 | shell: bash 35 | 36 | - name: Build 37 | run: qbs build profile:qt5 38 | shell: bash 39 | 40 | - name: Test 41 | run: qbs build profile:qt5 -p autotest-runner 42 | shell: bash 43 | -------------------------------------------------------------------------------- /src/orm/qormorder.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormorder.h" 22 | 23 | #include 24 | 25 | QT_BEGIN_NAMESPACE 26 | 27 | QDebug operator<<(QDebug dbg, const QOrmOrder& order) 28 | { 29 | QDebugStateSaver saver{dbg}; 30 | dbg.noquote().nospace() << "QOrmOrder(" << order.mapping().classPropertyName() << ", " 31 | << order.direction() << ")"; 32 | return dbg; 33 | } 34 | 35 | QT_END_NAMESPACE 36 | 37 | -------------------------------------------------------------------------------- /_clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | IndentWidth: 4 3 | Language: Cpp 4 | AccessModifierOffset: -4 5 | AlignAfterOpenBracket: Align 6 | AlignOperands: true 7 | # AllowAllConstructorInitializersOnNextLine: false 8 | AllowAllParametersOfDeclarationOnNextLine: false 9 | AllowShortFunctionsOnASingleLine: InlineOnly 10 | #AllowShortIfStatementsOnASingleLine: Never 11 | BreakBeforeBraces: Allman 12 | # BraceWrapping: 13 | # AfterEnum: true 14 | # AfterStruct: true 15 | # AfterClass: true 16 | # AfterControlStatement: true 17 | # AfterEnum: true 18 | # AfterNamespace: true 19 | # AfterStruct: true 20 | # AfterUnion: true 21 | # AfterExternBlock: true 22 | # BeforeCatch: true 23 | # BeforeElse: true 24 | # SplitEmptyFunction: true 25 | # SplitEmptyRecord: true 26 | # SplitEmptyNamespace: true 27 | BreakConstructorInitializers: BeforeComma 28 | ColumnLimit: 100 29 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 30 | IndentCaseLabels: true 31 | # IndentPPDirectives: BeforeHash 32 | NamespaceIndentation: All 33 | PointerAlignment: Left 34 | SortIncludes: true 35 | Standard: Cpp11 36 | BinPackArguments: false 37 | BinPackParameters: false 38 | AlwaysBreakTemplateDeclarations: Yes 39 | SpaceAfterTemplateKeyword: false 40 | ReflowComments: true 41 | PenaltyBreakBeforeFirstCallParameter: 100 42 | PenaltyReturnTypeOnItsOwnLine: 150 43 | -------------------------------------------------------------------------------- /src/orm/doc/qtorm.qdocconf: -------------------------------------------------------------------------------- 1 | include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) 2 | 3 | project = QtOrm 4 | description = Qt ORM Reference Documentation 5 | version = $QT_VERSION 6 | 7 | examplesinstallpath = orm 8 | 9 | qhp.projects = QtOrm 10 | 11 | qhp.QtOrm.file = qtorm.qhp 12 | qhp.QtOrm.namespace = at.sequality.qtorm.$QT_VERSION_TAG 13 | qhp.QtOrm.virtualFolder = qtorm 14 | qhp.QtOrm.indexTitle = Qt ORM 15 | qhp.QtOrm.indexRoot = 16 | 17 | qhp.QtOrm.filterAttributes = qtorm $QT_VERSION qtrefdoc 18 | qhp.QtOrm.customFilters.Qt.name = QtOrm $QT_VERSION 19 | qhp.QtOrm.customFilters.Qt.filterAttributes = qtorm $QT_VERSION 20 | 21 | qhp.QtOrm.subprojects = classes 22 | qhp.QtOrm.subprojects.classes.title = C++ Classes 23 | qhp.QtOrm.subprojects.classes.indexTitle = Qt ORM C++ Classes 24 | qhp.QtOrm.subprojects.classes.selectors = class fake:headerfile 25 | qhp.QtOrm.subprojects.classes.sortPages = true 26 | 27 | tagfile = ../../../doc/qtorm/qtorm.tags 28 | 29 | depends += \ 30 | qtcore \ 31 | qtdoc \ 32 | qtsql 33 | 34 | headerdirs += .. 35 | 36 | sourcedirs += .. 37 | 38 | exampledirs += ../../../examples/orm \ 39 | snippets/ 40 | 41 | imagedirs += images 42 | 43 | navigation.landingpage = "Qt ORM" 44 | navigation.cppclassespage = "Qt ORM C++ Classes" -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/domain/person.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "person.h" 22 | 23 | void Person::setId(int id) 24 | { 25 | if (m_id == id) 26 | return; 27 | 28 | m_id = id; 29 | emit idChanged(m_id); 30 | } 31 | 32 | void Person::setName(QString name) 33 | { 34 | if (m_name == name) 35 | return; 36 | 37 | m_name = name; 38 | emit nameChanged(m_name); 39 | } 40 | 41 | void Person::setTown(Town* town) 42 | { 43 | if (m_town == town) 44 | return; 45 | 46 | m_town = town; 47 | emit townChanged(m_town); 48 | } 49 | -------------------------------------------------------------------------------- /tests/auto/qormsession/domain/province.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "province.h" 22 | 23 | void Province::setId(int id) 24 | { 25 | if (m_id == id) 26 | return; 27 | 28 | m_id = id; 29 | emit idChanged(m_id); 30 | } 31 | 32 | void Province::setName(QString name) 33 | { 34 | if (m_name == name) 35 | return; 36 | 37 | m_name = name; 38 | emit nameChanged(m_name); 39 | } 40 | 41 | void Province::setTowns(QVector towns) 42 | { 43 | if (m_towns == towns) 44 | return; 45 | 46 | m_towns = towns; 47 | emit townsChanged(m_towns); 48 | } 49 | -------------------------------------------------------------------------------- /.github/workflows/cmake-linux.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | jobs: 4 | build: 5 | strategy: 6 | fail-fast: false 7 | matrix: 8 | include: 9 | - qtversion: '5.15.*' 10 | arch: 'gcc_64' 11 | - qtversion: '5.12.*' 12 | arch: 'gcc_64' 13 | - qtversion: '6.8.*' 14 | arch: 'linux_gcc_64' 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - name: Install Qt 21 | uses: jurplel/install-qt-action@v3 22 | with: 23 | version: ${{ matrix.qtversion }} 24 | arch: ${{ matrix.arch }} 25 | archives: 'qtbase qtdeclarative qtquickcontrols2 icu' 26 | 27 | - name: Create Build Environment 28 | run: cmake -E make_directory ${{runner.workspace}}/build 29 | 30 | - name: Configure CMake 31 | shell: bash 32 | working-directory: ${{runner.workspace}}/build 33 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=Debug -DQTORM_BUILD_EXAMPLES=ON -DQTORM_BUILD_TESTS=ON -DQTORM_BUILD_SHARED_LIBS=ON 34 | 35 | - name: Build 36 | working-directory: ${{runner.workspace}}/build 37 | shell: bash 38 | # Execute the build. You can specify a specific target with "--target " 39 | run: cmake --build . --config Debug 40 | 41 | - name: Test 42 | working-directory: ${{runner.workspace}}/build 43 | shell: bash 44 | run: ctest -C Debug --output-on-failure 45 | -------------------------------------------------------------------------------- /tests/auto/qormentityinstancecache/domain/province.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "province.h" 22 | 23 | void Province::setId(int id) 24 | { 25 | if (m_id == id) 26 | return; 27 | 28 | m_id = id; 29 | emit idChanged(m_id); 30 | } 31 | 32 | void Province::setName(QString name) 33 | { 34 | if (m_name == name) 35 | return; 36 | 37 | m_name = name; 38 | emit nameChanged(m_name); 39 | } 40 | 41 | void Province::setTowns(QVector towns) 42 | { 43 | if (m_towns == towns) 44 | return; 45 | 46 | m_towns = towns; 47 | emit townsChanged(m_towns); 48 | } 49 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/province.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "province.h" 22 | 23 | void Province::setId(int id) 24 | { 25 | if (m_id == id) 26 | return; 27 | 28 | m_id = id; 29 | emit idChanged(m_id); 30 | } 31 | 32 | void Province::setName(QString name) 33 | { 34 | if (m_name == name) 35 | return; 36 | 37 | m_name = name; 38 | emit nameChanged(m_name); 39 | } 40 | 41 | void Province::setTowns(QVector towns) 42 | { 43 | if (m_towns == towns) 44 | return; 45 | 46 | m_towns = towns; 47 | emit townsChanged(m_towns); 48 | } 49 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/withqvariant.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019-2021 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "withqvariant.h" 22 | 23 | int WithQVariant::id() const 24 | { 25 | return m_id; 26 | } 27 | 28 | void WithQVariant::setId(int id) 29 | { 30 | if (m_id != id) 31 | { 32 | m_id = id; 33 | emit idChanged(); 34 | } 35 | } 36 | 37 | QVariant WithQVariant::data() const 38 | { 39 | return m_data; 40 | } 41 | 42 | void WithQVariant::setData(const QVariant& data) 43 | { 44 | if (m_data != data) 45 | { 46 | m_data = data; 47 | emit dataChanged(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/person.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Dmitriy Purgin 3 | * 4 | * This file is part of QtOrm library. 5 | * 6 | * QtOrm is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * QtOrm is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with QtOrm. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | class Person : public QObject 25 | { 26 | Q_OBJECT 27 | 28 | Q_PROPERTY(long id READ id WRITE setId NOTIFY idChanged) 29 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 30 | 31 | long m_id; 32 | QString m_name; 33 | 34 | public: 35 | Q_INVOKABLE Person(QObject* parent = nullptr): QObject{parent} 36 | {} 37 | 38 | long id() const { return m_id; } 39 | void setId(long id); 40 | 41 | QString name() const { return m_name; } 42 | void setName(const QString& name); 43 | 44 | signals: 45 | void idChanged(); 46 | void nameChanged(); 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/domain/province.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "province.h" 22 | 23 | Province::Province(QObject* parent) 24 | : QObject(parent) 25 | { 26 | } 27 | 28 | int Province::id() const 29 | { 30 | return m_id; 31 | } 32 | 33 | QString Province::name() const 34 | { 35 | return m_name; 36 | } 37 | 38 | void Province::setId(int id) 39 | { 40 | if (m_id == id) 41 | return; 42 | 43 | m_id = id; 44 | emit idChanged(m_id); 45 | } 46 | 47 | void Province::setName(QString name) 48 | { 49 | if (m_name == name) 50 | return; 51 | 52 | m_name = name; 53 | emit nameChanged(m_name); 54 | } 55 | -------------------------------------------------------------------------------- /.github/workflows/cmake-windows.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | jobs: 4 | build: 5 | strategy: 6 | fail-fast: false 7 | matrix: 8 | include: 9 | - qtversion: '5.15.*' 10 | arch: 'win64_msvc2019_64' 11 | - qtversion: '5.12.*' 12 | arch: 'win64_msvc2017_64' 13 | - qtversion: '6.8.*' 14 | arch: 'win64_msvc2022_64' 15 | 16 | runs-on: windows-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | 21 | - name: Install Qt 22 | uses: jurplel/install-qt-action@v3 23 | with: 24 | version: ${{ matrix.qtversion }} 25 | arch: ${{ matrix.arch }} 26 | archives: 'qtbase qtdeclarative qtquickcontrols2' 27 | 28 | - name: Create Build Environment 29 | run: cmake -E make_directory ${{runner.workspace}}/build 30 | 31 | - name: Configure CMake 32 | working-directory: ${{runner.workspace}}/build 33 | run: cmake ${env:GITHUB_WORKSPACE} -A x64 -DQTORM_BUILD_EXAMPLES=ON -DQTORM_BUILD_TESTS=ON -DQTORM_BUILD_SHARED_LIBS=ON 34 | 35 | - name: Build 36 | working-directory: ${{runner.workspace}}/build 37 | # Execute the build. You can specify a specific target with "--target " 38 | run: cmake --build . --config Debug 39 | 40 | - name: Test 41 | working-directory: ${{runner.workspace}}/build 42 | run: | 43 | ${env:Path} = "${{runner.workspace}}/build/src/Debug;${env:Path}" 44 | ctest -C Debug --output-on-failure 45 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/domain/province.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019 Dmitriy Purgin 4 | * Copyright (C) 2019 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #include "province.h" 23 | 24 | void Province::setId(int id) 25 | { 26 | if (m_id == id) 27 | return; 28 | 29 | m_id = id; 30 | emit idChanged(m_id); 31 | } 32 | 33 | void Province::setName(QString name) 34 | { 35 | if (m_name == name) 36 | return; 37 | 38 | m_name = name; 39 | emit nameChanged(m_name); 40 | } 41 | 42 | void Province::setTowns(QVector towns) 43 | { 44 | if (m_towns == towns) 45 | return; 46 | 47 | m_towns = towns; 48 | emit townsChanged(m_towns); 49 | } 50 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/domain/province.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | class Province : public QObject 26 | { 27 | Q_OBJECT 28 | 29 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 30 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 31 | 32 | int m_id; 33 | QString m_name; 34 | 35 | public: 36 | Q_INVOKABLE explicit Province(QObject* parent = nullptr); 37 | 38 | int id() const; 39 | void setId(int id); 40 | 41 | QString name() const; 42 | void setName(QString name); 43 | 44 | signals: 45 | void idChanged(int id); 46 | void nameChanged(QString name); 47 | }; 48 | -------------------------------------------------------------------------------- /src/orm/qormfilter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormfilter.h" 22 | 23 | #include 24 | 25 | QT_BEGIN_NAMESPACE 26 | 27 | QDebug operator<<(QDebug dbg, const QOrmFilter& filter) 28 | { 29 | QDebugStateSaver saver{dbg}; 30 | 31 | dbg.nospace().noquote() << "QOrmFilter(" << filter.type(); 32 | 33 | switch (filter.type()) 34 | { 35 | case QOrm::FilterType::Invokable: 36 | dbg << "Invokable"; 37 | break; 38 | 39 | case QOrm::FilterType::Expression: 40 | dbg << "Expression, " << *filter.expression(); 41 | break; 42 | } 43 | 44 | dbg << ")"; 45 | 46 | return dbg; 47 | } 48 | 49 | QT_END_NAMESPACE 50 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/domain/town.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "town.h" 22 | 23 | Town::Town(QObject* parent) 24 | : QObject(parent) 25 | { 26 | } 27 | 28 | void Town::setId(int id) 29 | { 30 | if (m_id == id) 31 | return; 32 | 33 | m_id = id; 34 | emit idChanged(m_id); 35 | } 36 | 37 | void Town::setName(QString name) 38 | { 39 | if (m_name == name) 40 | return; 41 | 42 | m_name = name; 43 | emit nameChanged(m_name); 44 | } 45 | 46 | void Town::setPopulation(QVector population) 47 | { 48 | if (m_population == population) 49 | return; 50 | 51 | m_population = population; 52 | emit populationChanged(m_population); 53 | } 54 | -------------------------------------------------------------------------------- /cmake/GenerateHeaders.cmake: -------------------------------------------------------------------------------- 1 | include(${CMAKE_CURRENT_LIST_DIR}/ExtractClassNames.cmake) 2 | 3 | function(CheckVariable VARIABLE_NAME) 4 | if (NOT DEFINED ${VARIABLE_NAME}) 5 | message(FATAL_ERROR "${VARIABLE_NAME} is not defined") 6 | else() 7 | message(STATUS "${VARIABLE_NAME} is ${${VARIABLE_NAME}}") 8 | endif() 9 | endfunction() 10 | 11 | CheckVariable(SOURCE_DIRECTORY) 12 | CheckVariable(OUTPUT_DIRECTORY) 13 | CheckVariable(PUBLIC_HEADERS) 14 | CheckVariable(PRIVATE_HEADERS) 15 | 16 | file(REMOVE_RECURSE "${OUTPUT_DIRECTORY}") 17 | 18 | set(QTORM_MODULE_HEADER "${OUTPUT_DIRECTORY}/QtOrm") 19 | file(WRITE ${QTORM_MODULE_HEADER} "#ifndef QT_QTORM_MODULE_H\n") 20 | file(APPEND ${QTORM_MODULE_HEADER} "#define QT_QTORM_MODULE_H\n") 21 | 22 | foreach(HEADER ${PUBLIC_HEADERS}) 23 | message(STATUS "Parsing ${HEADER}...") 24 | 25 | get_filename_component(OUTPUT_HEADER "${HEADER}" NAME) 26 | 27 | file(WRITE 28 | "${OUTPUT_DIRECTORY}/${OUTPUT_HEADER}" 29 | "#include \"${SOURCE_DIRECTORY}/${HEADER}\"") 30 | 31 | ExtractClassNames(${SOURCE_DIRECTORY}/${HEADER} CLASS_NAMES) 32 | 33 | foreach(CLASS_NAME ${CLASS_NAMES}) 34 | file(WRITE 35 | "${OUTPUT_DIRECTORY}/${CLASS_NAME}" 36 | "#include \"${SOURCE_DIRECTORY}/${HEADER}\"") 37 | endforeach() 38 | 39 | file(APPEND "${QTORM_MODULE_HEADER}" "#include \"${OUTPUT_HEADER}\"\n") 40 | endforeach() 41 | 42 | foreach(HEADER ${PRIVATE_HEADERS}) 43 | get_filename_component(OUTPUT_HEADER "${HEADER}" NAME) 44 | 45 | file(WRITE 46 | "${OUTPUT_DIRECTORY}/private/${OUTPUT_HEADER}" 47 | "#include \"${SOURCE_DIRECTORY}/${HEADER}\"") 48 | endforeach() 49 | 50 | file(APPEND ${QTORM_MODULE_HEADER} "#endif\n") 51 | 52 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/withqvariant.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019-2021 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | class WithQVariant : public QObject 27 | { 28 | Q_OBJECT 29 | 30 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 31 | Q_PROPERTY(QVariant data READ data WRITE setData NOTIFY dataChanged) 32 | 33 | public: 34 | Q_INVOKABLE WithQVariant(QObject* parent = nullptr) 35 | : QObject{parent} 36 | { 37 | } 38 | 39 | int id() const; 40 | void setId(int id); 41 | 42 | QVariant data() const; 43 | void setData(const QVariant& data); 44 | 45 | signals: 46 | void idChanged(); 47 | void dataChanged(); 48 | 49 | private: 50 | int m_id{0}; 51 | QVariant m_data; 52 | }; 53 | -------------------------------------------------------------------------------- /src/orm/qormmetadata_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMMETADATA_P_H 22 | #define QORMMETADATA_P_H 23 | 24 | #include "QtOrm/qormpropertymapping.h" 25 | 26 | #include 27 | 28 | #include 29 | 30 | class QOrmMetadataPrivate : public QSharedData 31 | { 32 | public: 33 | QOrmMetadataPrivate(const QMetaObject& metaObject) 34 | : m_qMetaObject{metaObject} 35 | { 36 | } 37 | 38 | const QMetaObject& m_qMetaObject; 39 | 40 | QString m_className; 41 | QString m_tableName; 42 | std::vector m_propertyMappings; 43 | 44 | int m_objectIdPropertyMappingIdx{-1}; 45 | QHash m_classPropertyMappingIndex; 46 | QHash m_tableFieldMappingIndex; 47 | QOrmUserMetadata m_userMetadata; 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/orm/qormerror.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019-2021 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormerror.h" 22 | 23 | #include 24 | 25 | QT_BEGIN_NAMESPACE 26 | 27 | QOrmError::QOrmError() = default; 28 | 29 | QOrmError::QOrmError(QOrm::ErrorType error, const QString& text) 30 | : m_type{error} 31 | , m_text{text} 32 | { 33 | } 34 | 35 | QOrm::ErrorType QOrmError::type() const 36 | { 37 | return m_type; 38 | } 39 | 40 | QString QOrmError::text() const 41 | { 42 | return m_text; 43 | } 44 | 45 | QDebug operator<<(QDebug dbg, const QOrmError& error) 46 | { 47 | QDebugStateSaver saver{dbg}; 48 | 49 | dbg.nospace().noquote() << "QOrmError(" << error.type() << QStringLiteral(", ") << error.text() 50 | << QStringLiteral(")"); 51 | 52 | return dbg; 53 | } 54 | 55 | QT_END_NAMESPACE 56 | -------------------------------------------------------------------------------- /src/orm/qormorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMORDER_H 22 | #define QORMORDER_H 23 | 24 | #include 25 | #include 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | class Q_ORM_EXPORT QOrmOrder 30 | { 31 | public: 32 | QOrmOrder(const QOrmPropertyMapping& mapping, Qt::SortOrder direction) 33 | : m_propertyMapping{mapping} 34 | , m_direction{direction} 35 | { 36 | } 37 | 38 | const QOrmPropertyMapping& mapping() const { return m_propertyMapping; } 39 | Qt::SortOrder direction() const { return m_direction; } 40 | 41 | private: 42 | QOrmPropertyMapping m_propertyMapping; 43 | Qt::SortOrder m_direction{Qt::AscendingOrder}; 44 | }; 45 | 46 | Q_ORM_EXPORT QDebug operator<<(QDebug debug, const QOrmOrder& order); 47 | 48 | QT_END_NAMESPACE 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/orm/orm.pro: -------------------------------------------------------------------------------- 1 | TARGET = QtOrm 2 | 3 | QT = core sql 4 | 5 | QMAKE_DOCS = $$PWD/doc/qtorm.qdocconf 6 | 7 | PUBLIC_HEADERS += \ 8 | qormabstractprovider.h \ 9 | qormclassproperty.h \ 10 | qormentityinstancecache.h \ 11 | qormentitylistmodel.h \ 12 | qormerror.h \ 13 | qormfilter.h \ 14 | qormfilterexpression.h \ 15 | qormglobal.h \ 16 | qormmetadata.h \ 17 | qormmetadatacache.h \ 18 | qormorder.h \ 19 | qormpropertymapping.h \ 20 | qormquery.h \ 21 | qormquerybuilder.h \ 22 | qormqueryresult.h \ 23 | qormrelation.h \ 24 | qormsession.h \ 25 | qormsessionconfiguration.h \ 26 | qormsqliteconfiguration.h \ 27 | qormsqliteprovider.h \ 28 | qormtransactiontoken.h \ 29 | 30 | PRIVATE_HEADERS = \ 31 | qormglobal_p.h \ 32 | qormmetadata_p.h \ 33 | qormsqlitestatementgenerator_p.h \ 34 | 35 | SOURCES += \ 36 | qormabstractprovider.cpp \ 37 | qormclassproperty.cpp \ 38 | qormentityinstancecache.cpp \ 39 | qormentitylistmodel.cpp \ 40 | qormerror.cpp \ 41 | qormfilter.cpp \ 42 | qormfilterexpression.cpp \ 43 | qormglobal.cpp \ 44 | qormglobal_p.cpp \ 45 | qormmetadata.cpp \ 46 | qormmetadatacache.cpp \ 47 | qormorder.cpp \ 48 | qormpropertymapping.cpp \ 49 | qormquery.cpp \ 50 | qormquerybuilder.cpp \ 51 | qormqueryresult.cpp \ 52 | qormrelation.cpp \ 53 | qormsession.cpp \ 54 | qormsessionconfiguration.cpp \ 55 | qormsqliteconfiguration.cpp \ 56 | qormsqliteprovider.cpp \ 57 | qormsqlitestatementgenerator_p.cpp \ 58 | qormtransactiontoken.cpp \ 59 | 60 | HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS 61 | 62 | load(qt_module) 63 | 64 | CONFIG += c++17 65 | 66 | DEFINES -= QT_ASCII_CAST_WARNINGS 67 | -------------------------------------------------------------------------------- /src/orm/qormclassproperty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2022 Dmitriy Purgin 3 | * Copyright (C) 2019-2022 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMCLASSPROPERTY_H 22 | #define QORMCLASSPROPERTY_H 23 | 24 | #include 25 | 26 | #include 27 | 28 | QT_BEGIN_NAMESPACE 29 | 30 | class QOrmFilterExpression; 31 | 32 | class Q_ORM_EXPORT QOrmClassProperty 33 | { 34 | public: 35 | explicit QOrmClassProperty(const char* descriptor); 36 | 37 | QString descriptor() const; 38 | 39 | QOrmFilterExpression contains(const QVariant& value) const; 40 | QOrmFilterExpression notContains(const QVariant& value) const; 41 | 42 | private: 43 | QString m_descriptor; 44 | }; 45 | 46 | extern Q_ORM_EXPORT QDebug operator<<(QDebug dbg, const QOrmClassProperty& classProperty); 47 | 48 | #define Q_ORM_CLASS_PROPERTY(descriptor) (QOrmClassProperty{#descriptor}) 49 | 50 | QT_END_NAMESPACE 51 | 52 | #endif // QORMCLASSPROPERTY_H 53 | -------------------------------------------------------------------------------- /tests/auto/qormsession/domain/town.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "town.h" 22 | 23 | Town::Town(QObject* parent) 24 | : QObject(parent) 25 | { 26 | } 27 | 28 | int Town::id() const 29 | { 30 | return m_id; 31 | } 32 | 33 | QString Town::name() const 34 | { 35 | return m_name; 36 | } 37 | 38 | void Town::setId(int id) 39 | { 40 | if (m_id == id) 41 | return; 42 | 43 | m_id = id; 44 | emit idChanged(m_id); 45 | } 46 | 47 | void Town::setName(QString name) 48 | { 49 | if (m_name == name) 50 | return; 51 | 52 | m_name = name; 53 | emit nameChanged(m_name); 54 | } 55 | 56 | Province* Town::province() const 57 | { 58 | return m_province; 59 | } 60 | 61 | void Town::setProvince(Province* province) 62 | { 63 | if (m_province == province) 64 | return; 65 | 66 | m_province = province; 67 | emit provinceChanged(m_province); 68 | } 69 | -------------------------------------------------------------------------------- /tests/auto/qormentityinstancecache/domain/town.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "town.h" 22 | 23 | Town::Town(QObject* parent) 24 | : QObject(parent) 25 | { 26 | } 27 | 28 | int Town::id() const 29 | { 30 | return m_id; 31 | } 32 | 33 | QString Town::name() const 34 | { 35 | return m_name; 36 | } 37 | 38 | void Town::setId(int id) 39 | { 40 | if (m_id == id) 41 | return; 42 | 43 | m_id = id; 44 | emit idChanged(m_id); 45 | } 46 | 47 | void Town::setName(QString name) 48 | { 49 | if (m_name == name) 50 | return; 51 | 52 | m_name = name; 53 | emit nameChanged(m_name); 54 | } 55 | 56 | Province* Town::province() const 57 | { 58 | return m_province; 59 | } 60 | 61 | void Town::setProvince(Province* province) 62 | { 63 | if (m_province == province) 64 | return; 65 | 66 | m_province = province; 67 | emit provinceChanged(m_province); 68 | } 69 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/town.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "town.h" 22 | 23 | Town::Town(QObject* parent) 24 | : QObject(parent) 25 | { 26 | } 27 | 28 | int Town::id() const 29 | { 30 | return m_id; 31 | } 32 | 33 | QString Town::name() const 34 | { 35 | return m_name; 36 | } 37 | 38 | void Town::setId(int id) 39 | { 40 | if (m_id == id) 41 | return; 42 | 43 | m_id = id; 44 | emit idChanged(m_id); 45 | } 46 | 47 | void Town::setName(QString name) 48 | { 49 | if (m_name == name) 50 | return; 51 | 52 | m_name = name; 53 | emit nameChanged(m_name); 54 | } 55 | 56 | Province* Town::province() const 57 | { 58 | return m_province; 59 | } 60 | 61 | void Town::setProvince(Province* province) 62 | { 63 | if (m_province == province) 64 | return; 65 | 66 | m_province = province; 67 | emit provinceChanged(m_province); 68 | } 69 | -------------------------------------------------------------------------------- /src/orm/qormentitylistmodel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Dmitriy Purgin 3 | * Copyright (C) 2020 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormentitylistmodel.h" 22 | 23 | QT_BEGIN_NAMESPACE 24 | 25 | QOrmEntityListModelBase::QOrmEntityListModelBase(QObject* parent) 26 | : QAbstractListModel{parent} 27 | { 28 | } 29 | 30 | QVariantMap QOrmEntityListModelBase::filter() const 31 | { 32 | return m_filter; 33 | } 34 | 35 | void QOrmEntityListModelBase::setFilter(QVariantMap filter) 36 | { 37 | if (m_filter != filter) 38 | { 39 | m_filter = filter; 40 | Q_EMIT filterChanged(); 41 | onFilterChanged(); 42 | } 43 | } 44 | 45 | QVariantList QOrmEntityListModelBase::order() const 46 | { 47 | return m_order; 48 | } 49 | 50 | void QOrmEntityListModelBase::setOrder(QVariantList order) 51 | { 52 | if (m_order != order) 53 | { 54 | m_order = order; 55 | Q_EMIT orderChanged(); 56 | onOrderChanged(); 57 | } 58 | } 59 | 60 | QT_END_NAMESPACE 61 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | project(QtOrm LANGUAGES CXX) 4 | 5 | # https://stackoverflow.com/questions/25199677/how-to-detect-if-current-scope-has-a-parent-in-cmake 6 | get_directory_property(hasParent PARENT_DIRECTORY) 7 | 8 | if (hasParent) 9 | option(QTORM_BUILD_EXAMPLES "Build QtOrm examples" OFF) 10 | option(QTORM_BUILD_TESTS "Build QtOrm tests" OFF) 11 | else() 12 | option(QTORM_BUILD_EXAMPLES "Build QtOrm examples" ON) 13 | option(QTORM_BUILD_TESTS "Build QtOrm tests" ON) 14 | endif() 15 | 16 | option(QTORM_BUILD_SHARED_LIBS "Build QtOrm as shared library (LGPLv3)" ON) 17 | set(QTORM_QT_VERSION_HINT "auto" CACHE STRING "Qt version to use (5, 6, or auto)") 18 | 19 | if (QTORM_QT_VERSION_HINT STREQUAL "auto") 20 | find_package(Qt6 COMPONENTS Core QUIET) 21 | 22 | if (Qt6_FOUND) 23 | set(QTORM_QT_VERSION_MAJOR 6) 24 | else() 25 | set(QTORM_QT_VERSION_MAJOR 5) 26 | endif() 27 | else() 28 | set(QTORM_QT_VERSION_MAJOR ${QTORM_QT_VERSION_HINT}) 29 | endif() 30 | 31 | message("QtOrm Configuration:") 32 | message(" Examples: ${QTORM_BUILD_EXAMPLES}") 33 | message(" Tests: ${QTORM_BUILD_TESTS}") 34 | message(" Shared libs (LGPLv3): ${QTORM_BUILD_SHARED_LIBS}") 35 | message(" Qt version: ${QTORM_QT_VERSION_HINT}, detected ${QTORM_QT_VERSION_MAJOR}") 36 | 37 | set(CMAKE_AUTOMOC ON) 38 | set(CMAKE_AUTORCC ON) 39 | 40 | find_package(Qt${QTORM_QT_VERSION_MAJOR} COMPONENTS Core Sql REQUIRED) 41 | 42 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") 43 | 44 | include(ExtractClassNames) 45 | include(GetGeneratedHeaders) 46 | 47 | add_subdirectory(src) 48 | 49 | if (QTORM_BUILD_EXAMPLES) 50 | add_subdirectory(examples) 51 | endif() 52 | 53 | if (QTORM_BUILD_TESTS) 54 | enable_testing() 55 | add_subdirectory(tests) 56 | endif() 57 | -------------------------------------------------------------------------------- /src/orm/qormerror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019-2021 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMERROR_H 22 | #define QORMERROR_H 23 | 24 | #include 25 | 26 | #include 27 | 28 | QT_BEGIN_NAMESPACE 29 | 30 | class QDebug; 31 | 32 | class Q_ORM_EXPORT QOrmError 33 | { 34 | public: 35 | QOrmError(); 36 | QOrmError(QOrm::ErrorType type, const QString& text); 37 | 38 | [[nodiscard]] QOrm::ErrorType type() const; 39 | [[nodiscard]] QString text() const; 40 | 41 | [[nodiscard]] bool operator==(QOrm::ErrorType errorType) const { return m_type == errorType; } 42 | 43 | [[nodiscard]] bool operator!=(QOrm::ErrorType errorType) const 44 | { 45 | return !operator==(errorType); 46 | } 47 | 48 | private: 49 | QOrm::ErrorType m_type{QOrm::ErrorType::None}; 50 | QString m_text; 51 | }; 52 | 53 | extern Q_ORM_EXPORT QDebug operator<<(QDebug dbg, const QOrmError& error); 54 | 55 | QT_END_NAMESPACE 56 | 57 | #endif // QORMERROR_H 58 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/domain/town.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019 Dmitriy Purgin 4 | * Copyright (C) 2019 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #include "town.h" 23 | 24 | Town::Town(QObject* parent) 25 | : QObject(parent) 26 | { 27 | } 28 | 29 | int Town::id() const 30 | { 31 | return m_id; 32 | } 33 | 34 | QString Town::name() const 35 | { 36 | return m_name; 37 | } 38 | 39 | void Town::setId(int id) 40 | { 41 | if (m_id == id) 42 | return; 43 | 44 | m_id = id; 45 | emit idChanged(m_id); 46 | } 47 | 48 | void Town::setName(QString name) 49 | { 50 | if (m_name == name) 51 | return; 52 | 53 | m_name = name; 54 | emit nameChanged(m_name); 55 | } 56 | 57 | Province* Town::province() const 58 | { 59 | return m_province; 60 | } 61 | 62 | void Town::setProvince(Province* province) 63 | { 64 | if (m_province == province) 65 | return; 66 | 67 | m_province = province; 68 | emit provinceChanged(m_province); 69 | } 70 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/domain/person.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2025 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #include "town.h" 26 | 27 | class Person : public QObject 28 | { 29 | Q_OBJECT 30 | 31 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 32 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 33 | Q_PROPERTY(Town* town READ town WRITE setTown NOTIFY townChanged) 34 | 35 | int m_id; 36 | QString m_name; 37 | Town* m_town{nullptr}; 38 | 39 | public: 40 | Q_INVOKABLE Person() = default; 41 | explicit Person(QString name); 42 | 43 | int id() const { return m_id; } 44 | void setId(int id); 45 | 46 | QString name() const { return m_name; } 47 | void setName(QString name); 48 | 49 | Town* town() const { return m_town; } 50 | void setTown(Town* town); 51 | 52 | signals: 53 | void idChanged(int id); 54 | void nameChanged(QString name); 55 | void townChanged(Town* town); 56 | }; 57 | -------------------------------------------------------------------------------- /src/orm/qormrelation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMRELATION_H 22 | #define QORMRELATION_H 23 | 24 | #include 25 | 26 | #include 27 | 28 | QT_BEGIN_NAMESPACE 29 | 30 | class QOrmMetadata; 31 | class QOrmQuery; 32 | class QOrmRelationPrivate; 33 | 34 | class Q_ORM_EXPORT QOrmRelation 35 | { 36 | public: 37 | explicit QOrmRelation(const QOrmMetadata& mapping); 38 | explicit QOrmRelation(const QOrmQuery& query); 39 | QOrmRelation(const QOrmRelation&); 40 | QOrmRelation(QOrmRelation&&); 41 | ~QOrmRelation(); 42 | 43 | QOrmRelation& operator=(const QOrmRelation&); 44 | QOrmRelation& operator=(QOrmRelation&&); 45 | 46 | QOrm::RelationType type() const; 47 | const QOrmMetadata* mapping() const; 48 | const QOrmQuery* query() const; 49 | 50 | private: 51 | QSharedDataPointer d; 52 | }; 53 | 54 | extern Q_ORM_EXPORT QDebug operator<<(QDebug dbg, const QOrmRelation& relation); 55 | 56 | QT_END_NAMESPACE 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/orm/qormtransactiontoken.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMTRANSACTIONTOKEN_H 22 | #define QORMTRANSACTIONTOKEN_H 23 | 24 | #include 25 | 26 | #include 27 | 28 | QT_BEGIN_NAMESPACE 29 | 30 | class QOrmSession; 31 | class QOrmTransactionTokenPrivate; 32 | 33 | class Q_ORM_EXPORT QOrmTransactionToken 34 | { 35 | public: 36 | QOrmTransactionToken(QOrmSession* session, QOrm::TransactionAction finalAction); 37 | QOrmTransactionToken(const QOrmTransactionToken&) = delete; 38 | QOrmTransactionToken(QOrmTransactionToken&&); 39 | ~QOrmTransactionToken(); 40 | 41 | QOrmTransactionToken& operator=(const QOrmTransactionToken&) = delete; 42 | QOrmTransactionToken& operator=(QOrmTransactionToken&&); 43 | 44 | Q_REQUIRED_RESULT bool isEngaged() const; 45 | void disengage(); 46 | 47 | bool commit(); 48 | bool rollback(); 49 | 50 | private: 51 | std::unique_ptr d; 52 | }; 53 | 54 | QT_END_NAMESPACE 55 | 56 | #endif // QORMTRANSACTIONTOKEN_H 57 | -------------------------------------------------------------------------------- /src/orm/qormclassproperty.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2022 Dmitriy Purgin 3 | * Copyright (C) 2019-2022 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormclassproperty.h" 22 | #include "qormfilterexpression.h" 23 | 24 | #include 25 | 26 | QT_BEGIN_NAMESPACE 27 | 28 | QDebug operator<<(QDebug dbg, const QOrmClassProperty& classProperty) 29 | { 30 | QDebugStateSaver saver{dbg}; 31 | 32 | dbg.noquote().nospace() << "QOrmClassProperty(\"" << classProperty.descriptor() << "\")"; 33 | 34 | return dbg; 35 | } 36 | 37 | QOrmClassProperty::QOrmClassProperty(const char* descriptor) 38 | : m_descriptor{descriptor} 39 | { 40 | } 41 | 42 | QString QOrmClassProperty::descriptor() const 43 | { 44 | return m_descriptor; 45 | } 46 | 47 | QOrmFilterExpression QOrmClassProperty::contains(const QVariant& value) const 48 | { 49 | return QOrmFilterTerminalPredicate{*this, QOrm::Comparison::Contains, value}; 50 | } 51 | 52 | QOrmFilterExpression QOrmClassProperty::notContains(const QVariant& value) const 53 | { 54 | return QOrmFilterTerminalPredicate{*this, QOrm::Comparison::NotContains, value}; 55 | } 56 | 57 | QT_END_NAMESPACE 58 | -------------------------------------------------------------------------------- /src/orm/qormentityinstancecache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMENTITYINSTANCECACHE_H 22 | #define QORMENTITYINSTANCECACHE_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | QT_BEGIN_NAMESPACE 29 | 30 | class QOrmEntityInstanceCachePrivate; 31 | class QOrmMetadata; 32 | 33 | class Q_ORM_EXPORT QOrmEntityInstanceCache 34 | { 35 | Q_DISABLE_COPY(QOrmEntityInstanceCache) 36 | 37 | public: 38 | QOrmEntityInstanceCache(); 39 | ~QOrmEntityInstanceCache(); 40 | 41 | QObject* get(const QOrmMetadata& meta, const QVariant& objectId); 42 | bool contains(const QObject* instance) const; 43 | void insert(const QOrmMetadata& meta, QObject* instance); 44 | QObject* take(QObject* instance); 45 | 46 | void finalize(const QOrmMetadata& metadata, QObject* instance); 47 | bool isModified(const QObject* instance) const; 48 | void markUnmodified(const QObject* instance) const; 49 | 50 | private: 51 | QScopedPointer d; 52 | }; 53 | 54 | QT_END_NAMESPACE 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /tests/auto/qormsession/domain/town.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | class Province; 26 | 27 | class Town : public QObject 28 | { 29 | Q_OBJECT 30 | 31 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 32 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 33 | Q_PROPERTY(Province* province READ province WRITE setProvince NOTIFY provinceChanged) 34 | 35 | int m_id; 36 | QString m_name; 37 | Province* m_province = nullptr; 38 | 39 | public: 40 | Q_INVOKABLE explicit Town(QObject* parent = nullptr); 41 | Town(const QString& name, Province* province) 42 | : m_name{name} 43 | , m_province{province} 44 | { 45 | } 46 | 47 | int id() const; 48 | void setId(int id); 49 | 50 | QString name() const; 51 | void setName(QString name); 52 | 53 | Province* province() const; 54 | void setProvince(Province* province); 55 | 56 | signals: 57 | void idChanged(int id); 58 | void nameChanged(QString name); 59 | void provinceChanged(Province* province); 60 | }; 61 | -------------------------------------------------------------------------------- /src/orm/qormsqliteconfiguration.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormsqliteconfiguration.h" 22 | 23 | QT_BEGIN_NAMESPACE 24 | 25 | QString QOrmSqliteConfiguration::connectOptions() const 26 | { 27 | return m_connectOptions; 28 | } 29 | 30 | void QOrmSqliteConfiguration::setConnectOptions(const QString& connectOptions) 31 | { 32 | m_connectOptions = connectOptions; 33 | } 34 | 35 | QString QOrmSqliteConfiguration::databaseName() const 36 | { 37 | return m_databaseName; 38 | } 39 | 40 | void QOrmSqliteConfiguration::setDatabaseName(const QString& databaseName) 41 | { 42 | m_databaseName = databaseName; 43 | } 44 | 45 | bool QOrmSqliteConfiguration::verbose() const 46 | { 47 | return m_verbose; 48 | } 49 | 50 | void QOrmSqliteConfiguration::setVerbose(bool verbose) 51 | { 52 | m_verbose = verbose; 53 | } 54 | 55 | QOrmSqliteConfiguration::SchemaMode QOrmSqliteConfiguration::schemaMode() const 56 | { 57 | return m_schemaMode; 58 | } 59 | 60 | void QOrmSqliteConfiguration::setSchemaMode(SchemaMode schemaMode) 61 | { 62 | m_schemaMode = schemaMode; 63 | } 64 | 65 | QT_END_NAMESPACE 66 | -------------------------------------------------------------------------------- /src/orm/qormabstractprovider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019-2022 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMABSTRACTPROVIDER_H 22 | #define QORMABSTRACTPROVIDER_H 23 | 24 | #include 25 | #include 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | class QObject; 30 | class QOrmEntityInstanceCache; 31 | class QOrmError; 32 | class QOrmMetadataCache; 33 | class QOrmQuery; 34 | 35 | class Q_ORM_EXPORT QOrmAbstractProvider 36 | { 37 | public: 38 | virtual ~QOrmAbstractProvider(); 39 | 40 | virtual QOrmError connectToBackend() = 0; 41 | virtual QOrmError disconnectFromBackend() = 0; 42 | virtual bool isConnectedToBackend() = 0; 43 | 44 | virtual QOrmError beginTransaction() = 0; 45 | virtual QOrmError commitTransaction() = 0; 46 | virtual QOrmError rollbackTransaction() = 0; 47 | 48 | virtual QOrmQueryResult execute(const QOrmQuery& query, 49 | QOrmEntityInstanceCache& entityInstanceCache) = 0; 50 | 51 | [[nodiscard]] virtual int capabilities() const = 0; 52 | }; 53 | 54 | QT_END_NAMESPACE 55 | 56 | #endif // QORMABSTRACTPROVIDER_H 57 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/domain/town.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | class Person; 27 | 28 | class Town : public QObject 29 | { 30 | Q_OBJECT 31 | 32 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 33 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 34 | Q_PROPERTY( 35 | QVector population READ population WRITE setPopulation NOTIFY populationChanged) 36 | 37 | int m_id; 38 | QString m_name; 39 | QVector m_population; 40 | 41 | public: 42 | Q_INVOKABLE explicit Town(QObject* parent = nullptr); 43 | 44 | virtual ~Town() {} 45 | 46 | int id() const { return m_id; } 47 | void setId(int id); 48 | 49 | QString name() const { return m_name; } 50 | void setName(QString name); 51 | 52 | QVector population() const { return m_population; } 53 | void setPopulation(QVector population); 54 | 55 | signals: 56 | void idChanged(int id); 57 | void nameChanged(QString name); 58 | void populationChanged(QVector population); 59 | }; 60 | -------------------------------------------------------------------------------- /tests/auto/qormentityinstancecache/domain/town.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | class Province; 26 | 27 | class Town : public QObject 28 | { 29 | Q_OBJECT 30 | 31 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 32 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 33 | Q_PROPERTY(Province* province READ province WRITE setProvince NOTIFY provinceChanged) 34 | 35 | int m_id; 36 | QString m_name; 37 | Province* m_province = nullptr; 38 | 39 | public: 40 | Q_INVOKABLE explicit Town(QObject* parent = nullptr); 41 | Town(int id, const QString& name, Province* province) 42 | : m_id{id} 43 | , m_name{name} 44 | , m_province{province} 45 | { 46 | } 47 | 48 | int id() const; 49 | void setId(int id); 50 | 51 | QString name() const; 52 | void setName(QString name); 53 | 54 | Province* province() const; 55 | void setProvince(Province* province); 56 | 57 | signals: 58 | void idChanged(int id); 59 | void nameChanged(QString name); 60 | void provinceChanged(Province* province); 61 | }; 62 | -------------------------------------------------------------------------------- /src/orm/qormmetadatacache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMMETADATACACHE_H 22 | #define QORMMETADATACACHE_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | QT_BEGIN_NAMESPACE 30 | 31 | class QOrmMetadata; 32 | class QOrmMetadataCachePrivate; 33 | class QMetaObject; 34 | 35 | class Q_ORM_EXPORT QOrmMetadataCache 36 | { 37 | Q_DISABLE_COPY(QOrmMetadataCache) 38 | 39 | public: 40 | QOrmMetadataCache(); 41 | QOrmMetadataCache(QOrmMetadataCache&&); 42 | ~QOrmMetadataCache(); 43 | 44 | QOrmMetadataCache& operator=(QOrmMetadataCache&&); 45 | 46 | Q_REQUIRED_RESULT 47 | const QOrmMetadata& operator[](const QMetaObject& qMetaObject); 48 | 49 | template 50 | Q_REQUIRED_RESULT 51 | const QOrmMetadata& get() 52 | { 53 | return operator[](T::staticMetaObject); 54 | } 55 | 56 | Q_REQUIRED_RESULT 57 | const QOrmMetadata& get(const QMetaObject& qMetaObject) { return operator[](qMetaObject); } 58 | 59 | private: 60 | std::unique_ptr d; 61 | }; 62 | 63 | QT_END_NAMESPACE 64 | 65 | #endif // QORMMETADATACACHE_H 66 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/domain/town.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019 Dmitriy Purgin 4 | * Copyright (C) 2019 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | class Province; 27 | 28 | class Town : public QObject 29 | { 30 | Q_OBJECT 31 | 32 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 33 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 34 | Q_PROPERTY(Province* province READ province WRITE setProvince NOTIFY provinceChanged) 35 | 36 | int m_id; 37 | QString m_name; 38 | Province* m_province = nullptr; 39 | 40 | public: 41 | Q_INVOKABLE explicit Town(QObject* parent = nullptr); 42 | Town(const QString& name, Province* province) 43 | : m_name{name} 44 | , m_province{province} 45 | { 46 | } 47 | 48 | int id() const; 49 | void setId(int id); 50 | 51 | QString name() const; 52 | void setName(QString name); 53 | 54 | Province* province() const; 55 | void setProvince(Province* province); 56 | 57 | signals: 58 | void idChanged(int id); 59 | void nameChanged(QString name); 60 | void provinceChanged(Province* province); 61 | }; 62 | -------------------------------------------------------------------------------- /src/orm/qormsqliteconfiguration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMSQLCONFIGURATION_H 22 | #define QORMSQLCONFIGURATION_H 23 | 24 | #include 25 | #include 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | class Q_ORM_EXPORT QOrmSqliteConfiguration 30 | { 31 | public: 32 | enum class SchemaMode 33 | { 34 | Recreate, 35 | Update, 36 | Validate, 37 | Bypass, 38 | Append 39 | }; 40 | 41 | public: 42 | Q_REQUIRED_RESULT 43 | QString connectOptions() const; 44 | void setConnectOptions(const QString& connectOptions); 45 | 46 | Q_REQUIRED_RESULT 47 | QString databaseName() const; 48 | void setDatabaseName(const QString& databaseName); 49 | 50 | Q_REQUIRED_RESULT 51 | bool verbose() const; 52 | void setVerbose(bool verbose); 53 | 54 | Q_REQUIRED_RESULT 55 | SchemaMode schemaMode() const; 56 | void setSchemaMode(SchemaMode schemaMode); 57 | 58 | private: 59 | QString m_connectOptions; 60 | QString m_databaseName; 61 | bool m_verbose{false}; 62 | SchemaMode m_schemaMode; 63 | }; 64 | 65 | QT_END_NAMESPACE 66 | 67 | #endif // QORMSQLCONFIGURATION_H 68 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/town.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | class Province; 26 | 27 | class Town : public QObject 28 | { 29 | Q_OBJECT 30 | 31 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 32 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 33 | Q_PROPERTY(Province* province READ province WRITE setProvince NOTIFY provinceChanged) 34 | 35 | int m_id; 36 | QString m_name; 37 | Province* m_province = nullptr; 38 | 39 | public: 40 | Q_INVOKABLE explicit Town(QObject* parent = nullptr); 41 | Town(int id, const QString& name, Province* province) 42 | : m_id{id} 43 | , m_name{name} 44 | , m_province{province} 45 | { 46 | } 47 | 48 | Town(const QString& name, Province* province) 49 | : m_name{name} 50 | , m_province{province} 51 | { 52 | } 53 | 54 | int id() const; 55 | void setId(int id); 56 | 57 | QString name() const; 58 | void setName(QString name); 59 | 60 | Province* province() const; 61 | void setProvince(Province* province); 62 | 63 | signals: 64 | void idChanged(int id); 65 | void nameChanged(QString name); 66 | void provinceChanged(Province* province); 67 | }; 68 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/domain/withenum.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2024 Dmitriy Purgin 3 | * Copyright (C) 2019-2024 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "withenum.h" 22 | 23 | int WithEnum::id() const 24 | { 25 | return m_id; 26 | } 27 | 28 | void WithEnum::setId(int id) 29 | { 30 | if (m_id != id) 31 | { 32 | m_id = id; 33 | emit idChanged(); 34 | } 35 | } 36 | 37 | MyNamespace::MyEnum WithEnum::myEnum() const 38 | { 39 | return m_myEnum; 40 | } 41 | 42 | void WithEnum::setMyEnum(MyNamespace::MyEnum myEnum) 43 | { 44 | if (m_myEnum != myEnum) 45 | { 46 | m_myEnum = myEnum; 47 | emit myEnumChanged(); 48 | } 49 | } 50 | 51 | MyNamespace::MyEnumClass WithEnum::myEnumClass() const 52 | { 53 | return m_myEnumClass; 54 | } 55 | 56 | void WithEnum::setMyEnumClass(MyNamespace::MyEnumClass myEnumClass) 57 | { 58 | if (m_myEnumClass != myEnumClass) 59 | { 60 | m_myEnumClass = myEnumClass; 61 | emit myEnumClassChanged(); 62 | } 63 | } 64 | 65 | MyNamespace::WithNamespace* WithEnum::myNamespacedClass() const 66 | { 67 | return m_myNamespacedClass; 68 | } 69 | 70 | void WithEnum::setMyNamespacedClass(MyNamespace::WithNamespace* myNamespacedClass) 71 | { 72 | if (m_myNamespacedClass != myNamespacedClass) 73 | { 74 | m_myNamespacedClass = myNamespacedClass; 75 | emit myNamespacedClassChanged(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/orm/qormsessionconfiguration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMSESSIONCONFIGURATION_H 22 | #define QORMSESSIONCONFIGURATION_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | QT_BEGIN_NAMESPACE 32 | 33 | class QOrmAbstractProvider; 34 | class QOrmSessionConfigurationData; 35 | 36 | class Q_ORM_EXPORT QOrmSessionConfiguration 37 | { 38 | public: 39 | static QOrmSessionConfiguration defaultConfiguration(); 40 | static QOrmSessionConfiguration fromFile(const QString& filePath); 41 | 42 | public: 43 | QOrmSessionConfiguration(QOrmAbstractProvider* provider, bool isVerbose); 44 | QOrmSessionConfiguration(const QOrmSessionConfiguration&); 45 | QOrmSessionConfiguration(QOrmSessionConfiguration&&); 46 | ~QOrmSessionConfiguration(); 47 | 48 | QOrmSessionConfiguration& operator=(const QOrmSessionConfiguration&); 49 | QOrmSessionConfiguration& operator=(QOrmSessionConfiguration&&); 50 | 51 | Q_REQUIRED_RESULT 52 | QOrmAbstractProvider* provider() const; 53 | 54 | Q_REQUIRED_RESULT 55 | bool isVerbose() const; 56 | 57 | private: 58 | QSharedDataPointer d; 59 | }; 60 | 61 | QT_END_NAMESPACE 62 | 63 | #endif // QORMSESSIONCONFIGURATION_H 64 | -------------------------------------------------------------------------------- /tests/auto/qormentityinstancecache/domain/province.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | class Town; 27 | 28 | class Province : public QObject 29 | { 30 | Q_OBJECT 31 | Q_DISABLE_COPY(Province) 32 | 33 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 34 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 35 | Q_PROPERTY(QVector towns READ towns WRITE setTowns NOTIFY townsChanged) 36 | 37 | int m_id; 38 | 39 | QString m_name; 40 | 41 | QVector m_towns; 42 | 43 | public: 44 | Q_INVOKABLE Province(QObject* parent = nullptr) 45 | : QObject(parent) 46 | { 47 | } 48 | explicit Province(int id, const QString& name, QObject* parent = nullptr) 49 | : QObject{parent} 50 | , m_id{id} 51 | , m_name{name} 52 | { 53 | } 54 | 55 | virtual ~Province() {} 56 | int id() const { return m_id; } 57 | QString name() const { return m_name; } 58 | 59 | QVector towns() const { return m_towns; } 60 | 61 | public slots: 62 | void setId(int id); 63 | void setName(QString name); 64 | void setTowns(QVector towns); 65 | 66 | signals: 67 | void idChanged(int id); 68 | void nameChanged(QString name); 69 | void townsChanged(QVector towns); 70 | }; 71 | -------------------------------------------------------------------------------- /src/orm/qormfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMFILTER_H 22 | #define QORMFILTER_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | QT_BEGIN_NAMESPACE 30 | 31 | class Q_ORM_EXPORT QOrmFilter 32 | { 33 | public: 34 | using Predicate = std::function; 35 | 36 | explicit QOrmFilter(QOrmFilterExpression expression) 37 | : m_type{QOrm::FilterType::Expression} 38 | , m_filter{std::move(expression)} 39 | { 40 | } 41 | 42 | explicit QOrmFilter(Predicate invokable) 43 | : m_type{QOrm::FilterType::Invokable} 44 | , m_filter{std::move(invokable)} 45 | { 46 | } 47 | 48 | Q_REQUIRED_RESULT 49 | QOrm::FilterType type() const 50 | { 51 | return m_type; 52 | } 53 | 54 | Q_REQUIRED_RESULT 55 | const QOrmFilterExpression* expression() const 56 | { 57 | return std::get_if(&m_filter); 58 | } 59 | 60 | Q_REQUIRED_RESULT 61 | const Predicate* invokable() const { return std::get_if(&m_filter); } 62 | 63 | private: 64 | QOrm::FilterType m_type; 65 | std::variant m_filter{nullptr}; 66 | }; 67 | 68 | extern Q_ORM_EXPORT QDebug operator<<(QDebug debug, const QOrmFilter& filter); 69 | 70 | QT_END_NAMESPACE 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/withenum.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2024 Dmitriy Purgin 3 | * Copyright (C) 2019-2024 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "withenum.h" 22 | 23 | namespace MyNamespace 24 | { 25 | void WithNamespace::setId(int id) 26 | { 27 | if (m_id != id) 28 | { 29 | m_id = id; 30 | emit idChanged(); 31 | } 32 | } 33 | 34 | void WithNamespace::setValue(QString value) 35 | { 36 | if (m_value != value) 37 | { 38 | m_value = value; 39 | emit valueChanged(); 40 | } 41 | } 42 | 43 | } // namespace MyNamespace 44 | 45 | int WithEnum::id() const 46 | { 47 | return m_id; 48 | } 49 | 50 | void WithEnum::setId(int id) 51 | { 52 | if (m_id != id) 53 | { 54 | m_id = id; 55 | emit idChanged(); 56 | } 57 | } 58 | 59 | MyNamespace::MyEnum WithEnum::myEnum() const 60 | { 61 | return m_myEnum; 62 | } 63 | 64 | void WithEnum::setMyEnum(MyNamespace::MyEnum myEnum) 65 | { 66 | if (m_myEnum != myEnum) 67 | { 68 | m_myEnum = myEnum; 69 | emit myEnumChanged(); 70 | } 71 | } 72 | 73 | MyNamespace::MyEnumClass WithEnum::myEnumClass() const 74 | { 75 | return m_myEnumClass; 76 | } 77 | 78 | void WithEnum::setMyEnumClass(MyNamespace::MyEnumClass myEnumClass) 79 | { 80 | if (m_myEnumClass != myEnumClass) 81 | { 82 | m_myEnumClass = myEnumClass; 83 | emit myEnumClassChanged(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/province.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | class Town; 27 | 28 | class Province : public QObject 29 | { 30 | Q_OBJECT 31 | Q_DISABLE_COPY(Province) 32 | 33 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 34 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 35 | Q_PROPERTY(QVector towns READ towns WRITE setTowns NOTIFY townsChanged) 36 | 37 | int m_id; 38 | QString m_name; 39 | QVector m_towns; 40 | 41 | public: 42 | Q_INVOKABLE Province(QObject* parent = nullptr) 43 | : QObject(parent) 44 | { 45 | } 46 | explicit Province(const QString& name, QObject* parent = nullptr) 47 | : QObject{parent} 48 | , m_name{name} 49 | { 50 | } 51 | Province(int id, QString name, QObject* parent = nullptr) 52 | : QObject{parent} 53 | , m_id{id} 54 | , m_name{name} 55 | { 56 | } 57 | 58 | virtual ~Province() {} 59 | int id() const { return m_id; } 60 | QString name() const { return m_name; } 61 | 62 | QVector towns() const { return m_towns; } 63 | 64 | public slots: 65 | void setId(int id); 66 | void setName(QString name); 67 | void setTowns(QVector towns); 68 | 69 | signals: 70 | void idChanged(int id); 71 | void nameChanged(QString name); 72 | void townsChanged(QVector towns); 73 | }; 74 | -------------------------------------------------------------------------------- /tests/auto/qormsession/domain/province.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | class Town; 27 | 28 | class Province : public QObject 29 | { 30 | Q_OBJECT 31 | Q_DISABLE_COPY(Province) 32 | 33 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 34 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 35 | Q_PROPERTY(QVector towns READ towns WRITE setTowns NOTIFY townsChanged) 36 | 37 | int m_id; 38 | 39 | QString m_name; 40 | 41 | QVector m_towns; 42 | 43 | public: 44 | Q_INVOKABLE Province(QObject* parent = nullptr) 45 | : QObject(parent) 46 | { 47 | } 48 | explicit Province(const QString& name, QObject* parent = nullptr) 49 | : QObject{parent} 50 | , m_name{name} 51 | { 52 | } 53 | Province(int id, const QString& name, QObject* parent = nullptr) 54 | : QObject{parent} 55 | , m_id{id} 56 | , m_name{name} 57 | { 58 | } 59 | 60 | virtual ~Province() {} 61 | int id() const { return m_id; } 62 | QString name() const { return m_name; } 63 | 64 | QVector towns() const { return m_towns; } 65 | 66 | public slots: 67 | void setId(int id); 68 | void setName(QString name); 69 | void setTowns(QVector towns); 70 | 71 | signals: 72 | void idChanged(int id); 73 | void nameChanged(QString name); 74 | void townsChanged(QVector towns); 75 | }; 76 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/domain/province.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019 Dmitriy Purgin 4 | * Copyright (C) 2019 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | class Town; 28 | 29 | class Province : public QObject 30 | { 31 | Q_OBJECT 32 | Q_DISABLE_COPY(Province) 33 | 34 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 35 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 36 | Q_PROPERTY(QVector towns READ towns WRITE setTowns NOTIFY townsChanged) 37 | 38 | int m_id; 39 | QString m_name; 40 | QVector m_towns; 41 | 42 | public: 43 | Q_INVOKABLE Province(QObject* parent = nullptr) 44 | : QObject(parent) 45 | { 46 | } 47 | explicit Province(const QString& name, QObject* parent = nullptr) 48 | : QObject{parent} 49 | , m_name{name} 50 | { 51 | } 52 | Province(int id, const QString& name, QObject* parent = nullptr) 53 | : QObject{parent} 54 | , m_id{id} 55 | , m_name{name} 56 | { 57 | } 58 | 59 | virtual ~Province() {} 60 | int id() const { return m_id; } 61 | QString name() const { return m_name; } 62 | 63 | QVector towns() const { return m_towns; } 64 | 65 | public slots: 66 | void setId(int id); 67 | void setName(QString name); 68 | void setTowns(QVector towns); 69 | 70 | signals: 71 | void idChanged(int id); 72 | void nameChanged(QString name); 73 | void townsChanged(QVector towns); 74 | }; 75 | -------------------------------------------------------------------------------- /src/orm/qormmetadata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019-2021 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMMETADATA_H 22 | #define QORMMETADATA_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | QT_BEGIN_NAMESPACE 33 | 34 | class QDebug; 35 | class QOrmMetadataPrivate; 36 | 37 | class Q_ORM_EXPORT QOrmMetadata 38 | { 39 | public: 40 | explicit QOrmMetadata(const QOrmMetadataPrivate* data); 41 | 42 | QOrmMetadata(const QOrmMetadata&); 43 | QOrmMetadata(QOrmMetadata&&); 44 | ~QOrmMetadata(); 45 | 46 | QOrmMetadata& operator=(const QOrmMetadata&); 47 | QOrmMetadata& operator=(QOrmMetadata&&); 48 | 49 | [[nodiscard]] const QMetaObject& qMetaObject() const; 50 | 51 | [[nodiscard]] QString className() const; 52 | [[nodiscard]] QString tableName() const; 53 | 54 | [[nodiscard]] const std::vector& propertyMappings() const; 55 | [[nodiscard]] const QOrmPropertyMapping* tableFieldMapping(const QString& fieldName) const; 56 | [[nodiscard]] const QOrmPropertyMapping* classPropertyMapping( 57 | const QString& classProperty) const; 58 | [[nodiscard]] const QOrmPropertyMapping* objectIdMapping() const; 59 | [[nodiscard]] const QOrmUserMetadata& userMetadata() const; 60 | 61 | private: 62 | QSharedDataPointer d; 63 | }; 64 | 65 | extern Q_ORM_EXPORT QDebug operator<<(QDebug dbg, const QOrmMetadata& metadata); 66 | 67 | QT_END_NAMESPACE 68 | 69 | #endif // QORMMETADATA_H 70 | -------------------------------------------------------------------------------- /src/orm/qormtransactiontoken.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormtransactiontoken.h" 22 | 23 | #include 24 | 25 | class QOrmTransactionTokenPrivate 26 | { 27 | friend class QOrmTransactionToken; 28 | 29 | QOrmTransactionTokenPrivate(QOrmSession* session, QOrm::TransactionAction action) 30 | : m_session{session} 31 | , m_action{action} 32 | { 33 | } 34 | 35 | QOrmSession* m_session{nullptr}; 36 | QOrm::TransactionAction m_action; 37 | bool m_engaged{true}; 38 | }; 39 | 40 | QOrmTransactionToken::QOrmTransactionToken(QOrmSession* session, QOrm::TransactionAction action) 41 | : d{new QOrmTransactionTokenPrivate{session, action}} 42 | { 43 | } 44 | 45 | QOrmTransactionToken::QOrmTransactionToken(QOrmTransactionToken&&) = default; 46 | 47 | QOrmTransactionToken& QOrmTransactionToken::operator=(QOrmTransactionToken&&) = default; 48 | 49 | QOrmTransactionToken::~QOrmTransactionToken() 50 | { 51 | if (d->m_engaged) 52 | { 53 | if (d->m_action == QOrm::TransactionAction::Commit) 54 | d->m_session->commitTransaction(); 55 | else 56 | d->m_session->rollbackTransaction(); 57 | } 58 | } 59 | 60 | bool QOrmTransactionToken::isEngaged() const 61 | { 62 | return d->m_engaged; 63 | } 64 | 65 | void QOrmTransactionToken::disengage() 66 | { 67 | d->m_engaged = false; 68 | } 69 | 70 | bool QOrmTransactionToken::commit() 71 | { 72 | disengage(); 73 | return d->m_session->commitTransaction(); 74 | } 75 | 76 | bool QOrmTransactionToken::rollback() 77 | { 78 | disengage(); 79 | return d->m_session->rollbackTransaction(); 80 | } 81 | -------------------------------------------------------------------------------- /tests/auto/qormsession/domain/person.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Dmitriy Purgin 3 | * Copyright (C) 2019 Dmitriy Purgin 4 | * Copyright (C) 2019 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #include "person.h" 23 | 24 | void Person::setId(int id) 25 | { 26 | if (m_id == id) 27 | return; 28 | 29 | m_id = id; 30 | emit idChanged(m_id); 31 | } 32 | 33 | void Person::setFirstName(QString firstName) 34 | { 35 | if (m_firstName == firstName) 36 | return; 37 | 38 | m_firstName = firstName; 39 | emit firstNameChanged(m_firstName); 40 | } 41 | 42 | void Person::setTown(Town* town) 43 | { 44 | if (m_town == town) 45 | return; 46 | 47 | m_town = town; 48 | emit townChanged(m_town); 49 | } 50 | 51 | QString Person::lastName() const 52 | { 53 | return m_lastName; 54 | } 55 | 56 | void Person::setLastName(QString lastName) 57 | { 58 | if (m_lastName == lastName) 59 | return; 60 | 61 | m_lastName = lastName; 62 | emit lastNameChanged(m_lastName); 63 | } 64 | 65 | Person* Person::personParent() const 66 | { 67 | return m_personParent; 68 | } 69 | 70 | void Person::setPersonParent(Person* personParent) 71 | { 72 | if (m_personParent == personParent) 73 | return; 74 | 75 | m_personParent = personParent; 76 | emit personParentChanged(personParent); 77 | } 78 | 79 | const QVector Person::personChildren() const 80 | { 81 | return m_personChildren; 82 | } 83 | 84 | void Person::setPersonChildren(const QVector personChildren) 85 | { 86 | if (m_personChildren == personChildren) 87 | return; 88 | 89 | m_personChildren = personChildren; 90 | emit personChildrenChanged(personChildren); 91 | } 92 | -------------------------------------------------------------------------------- /src/orm/qormsqliteprovider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2021 Dmitriy Purgin 3 | * Copyright (C) 2019-2022 Dmitriy Purgin 4 | * Copyright (C) 2019-2022 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #ifndef QORMSQLITEPROVIDER_H 23 | #define QORMSQLITEPROVIDER_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | QT_BEGIN_NAMESPACE 30 | 31 | class QOrmEntityInstanceCache; 32 | class QOrmSqliteConfiguration; 33 | class QOrmSqliteProviderPrivate; 34 | class QSqlDatabase; 35 | 36 | class Q_ORM_EXPORT QOrmSqliteProvider : public QOrmAbstractProvider 37 | { 38 | public: 39 | enum SqliteCapability 40 | { 41 | NoCapabilities = 0, 42 | SupportsReturningClause = 1 43 | }; 44 | Q_DECLARE_FLAGS(SqliteCapabilities, SqliteCapability) 45 | 46 | explicit QOrmSqliteProvider(const QOrmSqliteConfiguration& sqlConfiguration); 47 | ~QOrmSqliteProvider() override; 48 | 49 | QOrmError connectToBackend() override; 50 | QOrmError disconnectFromBackend() override; 51 | bool isConnectedToBackend() override; 52 | 53 | QOrmError beginTransaction() override; 54 | QOrmError commitTransaction() override; 55 | QOrmError rollbackTransaction() override; 56 | 57 | QOrmQueryResult execute(const QOrmQuery& query, 58 | QOrmEntityInstanceCache& entityInstanceCache) override; 59 | 60 | [[nodiscard]] int capabilities() const override; 61 | 62 | QOrmSqliteConfiguration configuration() const; 63 | QSqlDatabase database() const; 64 | 65 | private: 66 | Q_DECLARE_PRIVATE(QOrmSqliteProvider) 67 | QOrmSqliteProviderPrivate* d_ptr{nullptr}; 68 | }; 69 | 70 | QT_END_NAMESPACE 71 | 72 | #endif // QORMSQLITEPROVIDER_H 73 | -------------------------------------------------------------------------------- /tests/auto/qormqueryresult/tst_queryresult.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "domain/person.h" 8 | 9 | class QueryResultTest : public QObject 10 | { 11 | Q_OBJECT 12 | 13 | private slots: 14 | void testStlStyleConstIterator(); 15 | void testStlStyleMutableIterator(); 16 | }; 17 | 18 | void QueryResultTest::testStlStyleConstIterator() 19 | { 20 | QOrmSession session; 21 | 22 | for (int i = 0; i < 3; ++i) 23 | { 24 | Person* person = new Person; 25 | person->setName(QString{"Person %1"}.arg(i)); 26 | 27 | session.merge(person); 28 | } 29 | 30 | QOrmQueryResult result = session.from().select(); 31 | 32 | auto it = std::cbegin(result); 33 | QCOMPARE((*it)->id(), 1); 34 | QCOMPARE((*it)->name(), "Person 0"); 35 | 36 | ++it; 37 | QCOMPARE((*it)->id(), 2); 38 | QCOMPARE((*it)->name(), "Person 1"); 39 | 40 | ++it; 41 | QCOMPARE((*it)->id(), 3); 42 | QCOMPARE((*it)->name(), "Person 2"); 43 | 44 | ++it; 45 | QCOMPARE(it, std::cend(result)); 46 | } 47 | 48 | void QueryResultTest::testStlStyleMutableIterator() 49 | { 50 | QOrmSession session; 51 | 52 | for (int i = 0; i < 3; ++i) 53 | { 54 | Person* person = new Person; 55 | person->setName(QString{"Person %1"}.arg(i)); 56 | 57 | session.merge(person); 58 | } 59 | 60 | { 61 | QOrmQueryResult result = session.from().select(); 62 | 63 | auto it = std::begin(result); 64 | Person* p1 = *it; 65 | QCOMPARE(p1->id(), 1); 66 | QCOMPARE(p1->name(), "Person 0"); 67 | p1->setName("Person 00"); 68 | 69 | ++it; 70 | Person* p2 = *it; 71 | QCOMPARE(p2->id(), 2); 72 | QCOMPARE(p2->name(), "Person 1"); 73 | p2->setName("Person 11"); 74 | 75 | ++it; 76 | Person* p3 = *it; 77 | QCOMPARE(p3->id(), 3); 78 | QCOMPARE(p3->name(), "Person 2"); 79 | p3->setName("Person 22"); 80 | 81 | ++it; 82 | QCOMPARE(it, std::end(result)); 83 | 84 | QVERIFY(session.merge(p1, p2, p3)); 85 | } 86 | 87 | { 88 | QOrmQueryResult result = session.from().select(); 89 | 90 | for (Person* person : result) 91 | { 92 | QVERIFY(person->name().at(person->name().length() - 1) == 93 | person->name().at(person->name().length() - 2)); 94 | } 95 | } 96 | } 97 | 98 | QTEST_GUILESS_MAIN(QueryResultTest) 99 | 100 | #include "tst_queryresult.moc" 101 | -------------------------------------------------------------------------------- /src/orm/qormpropertymapping.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019-2021 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMPROPERTYMAPPING_H 22 | #define QORMPROPERTYMAPPING_H 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | QT_BEGIN_NAMESPACE 32 | 33 | class QOrmMetadata; 34 | class QOrmPropertyMappingPrivate; 35 | 36 | class Q_ORM_EXPORT QOrmPropertyMapping 37 | { 38 | public: 39 | QOrmPropertyMapping(const QOrmMetadata& enclosingEntity, 40 | QMetaProperty qMetaProperty, 41 | QString classPropertyName, 42 | QString tableFieldName, 43 | bool isObjectId, 44 | bool isAutoGenerated, 45 | QMetaType::Type dataType, 46 | const QOrmMetadata* referencedEntity, 47 | bool isTransient, 48 | QOrmUserMetadata userMetadata); 49 | QOrmPropertyMapping(const QOrmPropertyMapping&); 50 | QOrmPropertyMapping(QOrmPropertyMapping&&); 51 | ~QOrmPropertyMapping(); 52 | 53 | QOrmPropertyMapping& operator=(const QOrmPropertyMapping&); 54 | QOrmPropertyMapping& operator=(QOrmPropertyMapping&&); 55 | 56 | [[nodiscard]] const QOrmMetadata& enclosingEntity() const; 57 | [[nodiscard]] const QMetaProperty& qMetaProperty() const; 58 | [[nodiscard]] QString classPropertyName() const; 59 | [[nodiscard]] QString tableFieldName() const; 60 | [[nodiscard]] bool isObjectId() const; 61 | [[nodiscard]] bool isAutogenerated() const; 62 | [[nodiscard]] QMetaType::Type dataType() const; 63 | [[nodiscard]] QString dataTypeName() const; 64 | [[nodiscard]] bool isReference() const; 65 | [[nodiscard]] const QOrmMetadata* referencedEntity() const; 66 | [[nodiscard]] bool isTransient() const; 67 | [[nodiscard]] const QOrmUserMetadata& userMetadata() const; 68 | 69 | private: 70 | QSharedDataPointer d; 71 | }; 72 | 73 | extern Q_ORM_EXPORT QDebug operator<<(QDebug dbg, const QOrmPropertyMapping& propertyMapping); 74 | 75 | QT_END_NAMESPACE 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/domain/province.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * All rights reserved. 5 | * 6 | * This file is part of the examples of the QtOrm library 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the sequality software engineering e.U. nor the 16 | * names of its contributors may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef PROVINCE_H 32 | #define PROVINCE_H 33 | 34 | #include 35 | #include 36 | 37 | class Community; 38 | 39 | class Province : public QObject 40 | { 41 | Q_OBJECT 42 | 43 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 44 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 45 | Q_PROPERTY(QVector communityList READ communityList WRITE setCommunityList NOTIFY 46 | communityListChanged) 47 | 48 | int m_id; 49 | QString m_name; 50 | QVector m_communityList; 51 | 52 | public: 53 | Q_INVOKABLE explicit Province(QObject* parent = nullptr); 54 | explicit Province(const QString& name, QObject* parent = nullptr); 55 | 56 | int id() const; 57 | void setId(int id); 58 | 59 | QString name() const; 60 | void setName(QString name); 61 | 62 | QVector communityList() const; 63 | void setCommunityList(const QVector& communityList); 64 | 65 | signals: 66 | void idChanged(int id); 67 | void nameChanged(QString name); 68 | void communityListChanged(); 69 | }; 70 | 71 | extern QDebug operator<<(QDebug dbg, const Province& province); 72 | 73 | #endif // PROVINCE_H 74 | -------------------------------------------------------------------------------- /tests/auto/qormsession/domain/person.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021-2025 Dmitriy Purgin 3 | * Copyright (C) 2019 Dmitriy Purgin 4 | * Copyright (C) 2019 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "person.h" 28 | #include "town.h" 29 | 30 | class Person : public QObject 31 | { 32 | Q_OBJECT 33 | 34 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 35 | Q_PROPERTY(QString firstName READ firstName WRITE setFirstName NOTIFY firstNameChanged) 36 | Q_PROPERTY(QString lastName READ lastName WRITE setLastName NOTIFY lastNameChanged) 37 | Q_PROPERTY(Town* town READ town WRITE setTown NOTIFY townChanged) 38 | Q_PROPERTY( 39 | Person* personParent READ personParent WRITE setPersonParent NOTIFY personParentChanged) 40 | Q_PROPERTY(QVector personChildren READ personChildren WRITE setPersonChildren NOTIFY 41 | personChildrenChanged) 42 | 43 | int m_id; 44 | QString m_firstName; 45 | QString m_lastName; 46 | Town* m_town{nullptr}; 47 | Person* m_personParent{nullptr}; 48 | QVector m_personChildren; 49 | 50 | public: 51 | Q_INVOKABLE Person() = default; 52 | Person(QString firstName, QString lastName, Town* town) 53 | : m_firstName{firstName} 54 | , m_lastName{lastName} 55 | , m_town{town} 56 | { 57 | } 58 | explicit Person(QString name); 59 | 60 | int id() const { return m_id; } 61 | void setId(int id); 62 | 63 | QString firstName() const { return m_firstName; } 64 | void setFirstName(QString firstName); 65 | 66 | Town* town() const { return m_town; } 67 | void setTown(Town* town); 68 | 69 | QString lastName() const; 70 | void setLastName(QString lastName); 71 | 72 | Person* personParent() const; 73 | void setPersonParent(Person* personParent); 74 | 75 | const QVector personChildren() const; 76 | void setPersonChildren(const QVector personChildren); 77 | 78 | signals: 79 | void idChanged(int id); 80 | void firstNameChanged(QString firstName); 81 | void lastNameChanged(QString lastName); 82 | void townChanged(Town* town); 83 | void personParentChanged(Person* personParent); 84 | void personChildrenChanged(const QVector& personChildren); 85 | }; 86 | -------------------------------------------------------------------------------- /src/orm/qormquery.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMQUERY_H 22 | #define QORMQUERY_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | QT_BEGIN_NAMESPACE 34 | 35 | class QOrmFilter; 36 | class QOrmOrder; 37 | class QOrmQueryPrivate; 38 | class QOrmRelation; 39 | class QOrmMetadata; 40 | 41 | class Q_ORM_EXPORT QOrmQuery 42 | { 43 | public: 44 | QOrmQuery(QOrm::Operation operation, 45 | const QOrmRelation& relation, 46 | const std::optional& projection, 47 | const std::optional& expressionFilter, 48 | const std::optional& invokableFilter, 49 | const std::vector& order, 50 | const QFlags& flags); 51 | QOrmQuery(QOrm::Operation operation, const QOrmMetadata& relation, QObject* entityInstance); 52 | QOrmQuery(const QOrmQuery&); 53 | QOrmQuery(QOrmQuery&&); 54 | ~QOrmQuery(); 55 | 56 | QOrmQuery& operator=(const QOrmQuery&); 57 | QOrmQuery& operator=(QOrmQuery&&); 58 | 59 | Q_REQUIRED_RESULT 60 | QOrm::Operation operation() const; 61 | 62 | Q_REQUIRED_RESULT 63 | const QOrmRelation& relation() const; 64 | 65 | Q_REQUIRED_RESULT 66 | const std::optional& projection() const; 67 | 68 | Q_REQUIRED_RESULT 69 | const std::optional& expressionFilter() const; 70 | 71 | Q_REQUIRED_RESULT 72 | const std::optional& invokableFilter() const; 73 | 74 | Q_REQUIRED_RESULT 75 | const std::vector& order() const; 76 | 77 | Q_REQUIRED_RESULT 78 | const QObject* entityInstance() const; 79 | 80 | Q_REQUIRED_RESULT 81 | const QFlags& flags() const; 82 | 83 | [[nodiscard]] std::optional limit() const; 84 | void setLimit(std::optional limit); 85 | 86 | [[nodiscard]] std::optional offset() const; 87 | void setOffset(std::optional offset); 88 | 89 | private: 90 | QSharedDataPointer d; 91 | }; 92 | 93 | QDebug operator<<(QDebug dbg, const QOrmQuery& query); 94 | 95 | QT_END_NAMESPACE 96 | 97 | #endif // QORMQUERY_H 98 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/domain/province.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * All rights reserved. 5 | * 6 | * This file is part of the examples of the QtOrm library 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the sequality software engineering e.U. nor the 16 | * names of its contributors may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "province.h" 32 | 33 | #include 34 | #include 35 | 36 | QDebug operator<<(QDebug dbg, const Province& province) 37 | { 38 | QDebugStateSaver saver{dbg}; 39 | dbg.noquote().nospace() 40 | << "Province(" << province.id() << ", \"" << province.name() << "\")"; 41 | return dbg; 42 | } 43 | 44 | Province::Province(QObject* parent) 45 | : QObject(parent) 46 | { 47 | } 48 | 49 | Province::Province(const QString& name, QObject* parent) 50 | : QObject{parent} 51 | , m_name{name} 52 | { 53 | } 54 | 55 | int Province::id() const 56 | { 57 | return m_id; 58 | } 59 | 60 | QString Province::name() const 61 | { 62 | return m_name; 63 | } 64 | 65 | void Province::setId(int id) 66 | { 67 | if (m_id == id) 68 | { 69 | return; 70 | } 71 | 72 | m_id = id; 73 | emit idChanged(m_id); 74 | } 75 | 76 | void Province::setName(QString name) 77 | { 78 | if (m_name == name) 79 | return; 80 | 81 | m_name = name; 82 | emit nameChanged(m_name); 83 | } 84 | 85 | QVector Province::communityList() const 86 | { 87 | return m_communityList; 88 | } 89 | 90 | void Province::setCommunityList(const QVector& communityList) 91 | { 92 | if (m_communityList == communityList) 93 | return; 94 | 95 | m_communityList = communityList; 96 | emit communityListChanged(); 97 | } 98 | -------------------------------------------------------------------------------- /src/orm/qormrelation.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) 2019 Dmitriy Purgin 4 | * Copyright (C) 2019 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #include "qormrelation.h" 23 | #include "qormmetadata.h" 24 | #include "qormquery.h" 25 | 26 | #include 27 | #include 28 | 29 | QT_BEGIN_NAMESPACE 30 | 31 | class QOrmRelationPrivate : public QSharedData 32 | { 33 | friend class QOrmRelation; 34 | 35 | using RelationStorageType = std::variant; 36 | 37 | QOrmRelationPrivate(RelationStorageType relation) 38 | : m_relation{std::move(relation)} 39 | { 40 | } 41 | 42 | std::variant m_relation; 43 | }; 44 | 45 | QOrmRelation::QOrmRelation(const QOrmMetadata& mapping) 46 | : d{new QOrmRelationPrivate{mapping}} 47 | { 48 | } 49 | 50 | QOrmRelation::QOrmRelation(const QOrmQuery& query) 51 | : d{new QOrmRelationPrivate{query}} 52 | { 53 | } 54 | 55 | QOrmRelation::QOrmRelation(const QOrmRelation&) = default; 56 | 57 | QOrmRelation::QOrmRelation(QOrmRelation&&) = default; 58 | 59 | QOrmRelation::~QOrmRelation() = default; 60 | 61 | QOrmRelation& QOrmRelation::operator=(const QOrmRelation&) = default; 62 | 63 | QOrmRelation& QOrmRelation::operator=(QOrmRelation&&) = default; 64 | 65 | QOrm::RelationType QOrmRelation::type() const 66 | { 67 | if (std::holds_alternative(d->m_relation)) 68 | return QOrm::RelationType::Mapping; 69 | else if (std::holds_alternative(d->m_relation)) 70 | return QOrm::RelationType::Query; 71 | 72 | qFatal("QtORM: Unexpected state of QOrmRelation"); 73 | } 74 | 75 | const QOrmMetadata* QOrmRelation::mapping() const 76 | { 77 | return std::get_if(&d->m_relation); 78 | } 79 | 80 | const QOrmQuery* QOrmRelation::query() const 81 | { 82 | return std::get_if(&d->m_relation); 83 | } 84 | 85 | QDebug operator<<(QDebug dbg, const QOrmRelation& relation) 86 | { 87 | QDebugStateSaver saver{dbg}; 88 | 89 | dbg.noquote().nospace() << "QOrmRelation(" << relation.type() << ", "; 90 | 91 | switch (relation.type()) 92 | { 93 | case QOrm::RelationType::Query: 94 | dbg << *relation.query(); 95 | break; 96 | 97 | case QOrm::RelationType::Mapping: 98 | dbg << *relation.mapping(); 99 | break; 100 | } 101 | 102 | dbg << ")"; 103 | 104 | return dbg; 105 | } 106 | 107 | QT_END_NAMESPACE 108 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/withenum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2024 Dmitriy Purgin 3 | * Copyright (C) 2019-2024 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | namespace MyNamespace 26 | { 27 | enum MyEnum 28 | { 29 | MyEnumValue0, 30 | MyEnumValue1, 31 | MyEnumValue2 32 | }; 33 | 34 | enum class MyEnumClass 35 | { 36 | MyEnumClassValue0, 37 | MyEnumClassValue1, 38 | MyEnumClassValue2 39 | }; 40 | 41 | class WithNamespace : public QObject 42 | { 43 | Q_OBJECT 44 | 45 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 46 | Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged) 47 | 48 | public: 49 | Q_INVOKABLE WithNamespace(QObject* parent = nullptr) 50 | : QObject{parent} 51 | { 52 | } 53 | 54 | [[nodiscard]] int id() const { return m_id; } 55 | void setId(int id); 56 | 57 | [[nodiscard]] QString value() { return m_value; } 58 | void setValue(QString value); 59 | 60 | signals: 61 | void idChanged(); 62 | void valueChanged(); 63 | 64 | private: 65 | int m_id; 66 | QString m_value; 67 | }; 68 | } 69 | 70 | Q_DECLARE_METATYPE(MyNamespace::MyEnum); 71 | Q_DECLARE_METATYPE(MyNamespace::MyEnumClass); 72 | 73 | class WithEnum : public QObject 74 | { 75 | Q_OBJECT 76 | 77 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 78 | Q_PROPERTY(MyNamespace::MyEnum myEnum READ myEnum WRITE setMyEnum NOTIFY myEnumChanged) 79 | Q_PROPERTY(MyNamespace::MyEnumClass myEnumClass READ myEnumClass WRITE setMyEnumClass NOTIFY myEnumClassChanged) 80 | 81 | public: 82 | Q_INVOKABLE WithEnum(QObject* parent = nullptr) 83 | : QObject{parent} 84 | { 85 | } 86 | 87 | [[nodiscard]] int id() const; 88 | void setId(int id); 89 | 90 | [[nodiscard]] MyNamespace::MyEnum myEnum() const; 91 | void setMyEnum(MyNamespace::MyEnum myEnum); 92 | 93 | [[nodiscard]] MyNamespace::MyEnumClass myEnumClass() const; 94 | void setMyEnumClass(MyNamespace::MyEnumClass myEnumClass); 95 | 96 | signals: 97 | void idChanged(); 98 | void myEnumChanged(); 99 | void myEnumClassChanged(); 100 | 101 | private: 102 | int m_id{0}; 103 | MyNamespace::MyEnum m_myEnum{MyNamespace::MyEnumValue0}; 104 | MyNamespace::MyEnumClass m_myEnumClass{MyNamespace::MyEnumClass::MyEnumClassValue0}; 105 | }; 106 | -------------------------------------------------------------------------------- /tests/auto/qormsqlitestatementgenerator/domain/community.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2025 Dmitriy Purgin 3 | * 4 | * This file is part of QtOrm library. 5 | * 6 | * QtOrm is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * QtOrm is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with QtOrm. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include "province.h" 27 | 28 | class Community : public QObject 29 | { 30 | Q_OBJECT 31 | 32 | Q_PROPERTY(long communityId READ communityId WRITE setCommunityId NOTIFY communityIdChanged) 33 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 34 | Q_PROPERTY(int population READ population WRITE setPopulation NOTIFY populationChanged) 35 | Q_PROPERTY(Province* province READ province WRITE setProvince NOTIFY provinceChanged) 36 | Q_PROPERTY(bool hasLargePopulation READ hasLargePopulation STORED false) 37 | Q_PROPERTY(bool hasSmallPopulation READ hasSmallPopulation) 38 | 39 | Q_ORM_CLASS(TABLE communities) 40 | Q_ORM_PROPERTY(communityId COLUMN community_id IDENTITY) 41 | Q_ORM_PROPERTY(hasSmallPopulation TRANSIENT) 42 | 43 | public: 44 | Q_INVOKABLE Community(QObject* parent = nullptr); 45 | 46 | long communityId() const { return m_communityId; } 47 | void setCommunityId(long communityId) 48 | { 49 | if (m_communityId != communityId) 50 | { 51 | m_communityId = communityId; 52 | emit communityIdChanged(); 53 | } 54 | } 55 | 56 | QString name() const { return m_name; } 57 | void setName(QString name) 58 | { 59 | if (m_name != name) 60 | { 61 | m_name = name; 62 | emit nameChanged(); 63 | } 64 | } 65 | 66 | int population() const { return m_population; } 67 | void setPopulation(int population) 68 | { 69 | if (m_population != population) 70 | { 71 | m_population = population; 72 | emit populationChanged(); 73 | } 74 | } 75 | 76 | Province* province() const { return m_province; } 77 | void setProvince(Province* province) 78 | { 79 | if (m_province != province) 80 | { 81 | m_province = province; 82 | emit provinceChanged(); 83 | } 84 | } 85 | 86 | bool hasLargePopulation() const { return m_population > 5000; } 87 | bool hasSmallPopulation() const { return !hasLargePopulation(); } 88 | 89 | signals: 90 | void communityIdChanged(); 91 | void nameChanged(); 92 | void populationChanged(); 93 | void provinceChanged(); 94 | 95 | private: 96 | long m_communityId{0}; 97 | QString m_name; 98 | int m_population{0}; 99 | Province* m_province{nullptr}; 100 | }; 101 | -------------------------------------------------------------------------------- /src/orm/qormmetadata.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2021 Dmitriy Purgin 3 | * Copyright (C) 2019-2021 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormmetadata.h" 22 | #include "qormglobal_p.h" 23 | #include "qormmetadata_p.h" 24 | 25 | #include 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | QOrmMetadata::QOrmMetadata(const QOrmMetadataPrivate* data) 30 | : d{data} 31 | { 32 | } 33 | 34 | QOrmMetadata::QOrmMetadata(const QOrmMetadata&) = default; 35 | 36 | QOrmMetadata::QOrmMetadata(QOrmMetadata&&) = default; 37 | 38 | QOrmMetadata::~QOrmMetadata() = default; 39 | 40 | QOrmMetadata& QOrmMetadata::operator=(const QOrmMetadata&) = default; 41 | 42 | QOrmMetadata& QOrmMetadata::operator=(QOrmMetadata&&) = default; 43 | 44 | const QMetaObject& QOrmMetadata::qMetaObject() const 45 | { 46 | return d->m_qMetaObject; 47 | } 48 | 49 | QString QOrmMetadata::className() const 50 | { 51 | return d->m_className; 52 | } 53 | 54 | QString QOrmMetadata::tableName() const 55 | { 56 | return d->m_tableName; 57 | } 58 | 59 | const std::vector& QOrmMetadata::propertyMappings() const 60 | { 61 | return d->m_propertyMappings; 62 | } 63 | 64 | const QOrmPropertyMapping* QOrmMetadata::tableFieldMapping(const QString& fieldName) const 65 | { 66 | auto it = d->m_tableFieldMappingIndex.find(fieldName); 67 | 68 | if (it == std::end(d->m_tableFieldMappingIndex)) 69 | return nullptr; 70 | 71 | return &d->m_propertyMappings[static_cast(it.value())]; 72 | } 73 | 74 | const QOrmPropertyMapping* QOrmMetadata::classPropertyMapping(const QString& classProperty) const 75 | { 76 | auto it = d->m_classPropertyMappingIndex.find(classProperty); 77 | 78 | if (it == std::end(d->m_classPropertyMappingIndex)) 79 | return nullptr; 80 | 81 | return &d->m_propertyMappings[static_cast(it.value())]; 82 | } 83 | 84 | const QOrmPropertyMapping* QOrmMetadata::objectIdMapping() const 85 | { 86 | return d->m_objectIdPropertyMappingIdx == -1 87 | ? nullptr 88 | : &d->m_propertyMappings[static_cast(d->m_objectIdPropertyMappingIdx)]; 89 | } 90 | 91 | const QOrmUserMetadata& QOrmMetadata::userMetadata() const 92 | { 93 | return d->m_userMetadata; 94 | } 95 | 96 | QDebug operator<<(QDebug dbg, const QOrmMetadata& metadata) 97 | { 98 | QDebugStateSaver saver{dbg}; 99 | dbg.nospace().nospace() << "QOrmMetadata(" << metadata.className() << " => " 100 | << metadata.tableName() << ")"; 101 | return dbg; 102 | } 103 | 104 | QT_END_NAMESPACE 105 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QTORM_PUBLIC_HEADERS 2 | orm/qormabstractprovider.h 3 | orm/qormclassproperty.h 4 | orm/qormentityinstancecache.h 5 | orm/qormentitylistmodel.h 6 | orm/qormerror.h 7 | orm/qormfilter.h 8 | orm/qormfilterexpression.h 9 | orm/qormglobal.h 10 | orm/qormmetadata.h 11 | orm/qormmetadatacache.h 12 | orm/qormorder.h 13 | orm/qormpropertymapping.h 14 | orm/qormquery.h 15 | orm/qormquerybuilder.h 16 | orm/qormqueryresult.h 17 | orm/qormrelation.h 18 | orm/qormsession.h 19 | orm/qormsessionconfiguration.h 20 | orm/qormsqliteconfiguration.h 21 | orm/qormsqliteprovider.h 22 | orm/qormtransactiontoken.h 23 | ) 24 | 25 | set(QTORM_PRIVATE_HEADERS 26 | orm/qormglobal_p.h 27 | orm/qormmetadata_p.h 28 | orm/qormsqlitestatementgenerator_p.h 29 | ) 30 | 31 | set(GENERATED_INCLUDE_DIRECTORY "${CMAKE_BINARY_DIR}/QtOrmGenerated/include") 32 | 33 | GetGeneratedHeaders("${GENERATED_INCLUDE_DIRECTORY}/QtOrm" 34 | "${QTORM_PUBLIC_HEADERS}" 35 | "${QTORM_PRIVATE_HEADERS}" 36 | QTORM_GENERATED_HEADERS) 37 | 38 | list(JOIN QTORM_PUBLIC_HEADERS "\\;" QTORM_PUBLIC_HEADERS_JOINED) 39 | list(JOIN QTORM_PRIVATE_HEADERS "\\;" QTORM_PRIVATE_HEADERS_JOINED) 40 | 41 | add_custom_command( 42 | OUTPUT ${QTORM_GENERATED_HEADERS} 43 | COMMAND ${CMAKE_COMMAND} 44 | -DSOURCE_DIRECTORY:STRING="${CMAKE_CURRENT_SOURCE_DIR}" 45 | -DOUTPUT_DIRECTORY:STRING="${GENERATED_INCLUDE_DIRECTORY}/QtOrm" 46 | -DPUBLIC_HEADERS:STRING="${QTORM_PUBLIC_HEADERS_JOINED}" 47 | -DPRIVATE_HEADERS:STRING="${QTORM_PRIVATE_HEADERS_JOINED}" 48 | -P "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/GenerateHeaders.cmake" 49 | DEPENDS ${QTORM_PUBLIC_HEADERS} ${QTORM_PRIVATE_HEADERS} 50 | COMMENT "Generating module headers...") 51 | 52 | set(QTORM_SOURCES 53 | orm/qormabstractprovider.cpp 54 | orm/qormclassproperty.cpp 55 | orm/qormentityinstancecache.cpp 56 | orm/qormentitylistmodel.cpp 57 | orm/qormerror.cpp 58 | orm/qormfilter.cpp 59 | orm/qormfilterexpression.cpp 60 | orm/qormglobal.cpp 61 | orm/qormglobal_p.cpp 62 | orm/qormmetadata.cpp 63 | orm/qormmetadatacache.cpp 64 | orm/qormorder.cpp 65 | orm/qormpropertymapping.cpp 66 | orm/qormquery.cpp 67 | orm/qormquerybuilder.cpp 68 | orm/qormqueryresult.cpp 69 | orm/qormrelation.cpp 70 | orm/qormsession.cpp 71 | orm/qormsessionconfiguration.cpp 72 | orm/qormsqliteconfiguration.cpp 73 | orm/qormsqliteprovider.cpp 74 | orm/qormsqlitestatementgenerator_p.cpp 75 | orm/qormtransactiontoken.cpp 76 | ) 77 | 78 | set(BUILD_SHARED_LIBS ${QTORM_BUILD_SHARED_LIBS}) 79 | 80 | add_library(qtorm 81 | ${QTORM_PUBLIC_HEADERS} 82 | ${QTORM_PRIVATE_HEADERS} 83 | ${QTORM_SOURCES} 84 | ${QTORM_GENERATED_HEADERS} 85 | ) 86 | 87 | target_link_libraries(qtorm PUBLIC Qt${QTORM_QT_VERSION_MAJOR}::Core PRIVATE Qt${QTORM_QT_VERSION_MAJOR}::Sql) 88 | 89 | target_compile_definitions(qtorm PRIVATE QT_BUILD_ORM_LIB) 90 | target_include_directories(qtorm 91 | PUBLIC 92 | "${GENERATED_INCLUDE_DIRECTORY}" 93 | "${GENERATED_INCLUDE_DIRECTORY}/QtOrm" 94 | ) 95 | target_compile_features(qtorm PUBLIC cxx_std_17) 96 | #add_dependencies(qtorm qtorm-headers) 97 | 98 | if (MSVC) 99 | target_compile_definitions(qtorm PRIVATE __PRETTY_FUNCTION__=__FUNCTION__) 100 | endif() 101 | -------------------------------------------------------------------------------- /tests/auto/qormmetadatacache/domain/withenum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2024 Dmitriy Purgin 3 | * Copyright (C) 2019-2024 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | namespace MyNamespace 26 | { 27 | enum MyEnum 28 | { 29 | MyEnumValue0, 30 | MyEnumValue1, 31 | MyEnumValue2 32 | }; 33 | 34 | enum class MyEnumClass 35 | { 36 | MyEnumClassValue0, 37 | MyEnumClassValue1, 38 | MyEnumClassValue2 39 | }; 40 | 41 | class WithNamespace : public QObject 42 | { 43 | Q_OBJECT 44 | 45 | Q_PROPERTY(int id MEMBER m_id NOTIFY idChanged) 46 | Q_PROPERTY(QString value MEMBER m_value NOTIFY valueChanged) 47 | 48 | public: 49 | Q_INVOKABLE WithNamespace(QObject* parent = nullptr) 50 | : QObject{parent} 51 | { 52 | } 53 | 54 | signals: 55 | void idChanged(); 56 | void valueChanged(); 57 | 58 | private: 59 | int m_id; 60 | QString m_value; 61 | }; 62 | } 63 | 64 | Q_DECLARE_METATYPE(MyNamespace::MyEnum); 65 | Q_DECLARE_METATYPE(MyNamespace::MyEnumClass); 66 | 67 | class WithEnum : public QObject 68 | { 69 | Q_OBJECT 70 | 71 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 72 | Q_PROPERTY(MyNamespace::MyEnum myEnum READ myEnum WRITE setMyEnum NOTIFY myEnumChanged) 73 | Q_PROPERTY(MyNamespace::MyEnumClass myEnumClass READ myEnumClass WRITE setMyEnumClass NOTIFY myEnumClassChanged) 74 | Q_PROPERTY(MyNamespace::WithNamespace* myNamespacedClass READ myNamespacedClass WRITE 75 | setMyNamespacedClass NOTIFY myNamespacedClassChanged) 76 | 77 | public: 78 | Q_INVOKABLE WithEnum(QObject* parent = nullptr) 79 | : QObject{parent} 80 | { 81 | } 82 | 83 | [[nodiscard]] int id() const; 84 | void setId(int id); 85 | 86 | [[nodiscard]] MyNamespace::MyEnum myEnum() const; 87 | void setMyEnum(MyNamespace::MyEnum myEnum); 88 | 89 | [[nodiscard]] MyNamespace::MyEnumClass myEnumClass() const; 90 | void setMyEnumClass(MyNamespace::MyEnumClass myEnumClass); 91 | 92 | [[nodiscard]] MyNamespace::WithNamespace* myNamespacedClass() const; 93 | void setMyNamespacedClass(MyNamespace::WithNamespace* myNamespacedClass); 94 | 95 | signals: 96 | void idChanged(); 97 | void myEnumChanged(); 98 | void myEnumClassChanged(); 99 | void myNamespacedClassChanged(); 100 | 101 | private: 102 | int m_id{0}; 103 | MyNamespace::MyEnum m_myEnum{MyNamespace::MyEnumValue0}; 104 | MyNamespace::MyEnumClass m_myEnumClass{MyNamespace::MyEnumClass::MyEnumClassValue0}; 105 | MyNamespace::WithNamespace* m_myNamespacedClass{nullptr}; 106 | }; 107 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/domain/community.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * All rights reserved. 5 | * 6 | * This file is part of the examples of the QtOrm library 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the sequality software engineering e.U. nor the 16 | * names of its contributors may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef COMMUNITY_H 32 | #define COMMUNITY_H 33 | 34 | #include 35 | 36 | #include "province.h" 37 | 38 | class Community : public QObject 39 | { 40 | Q_OBJECT 41 | 42 | Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged) 43 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 44 | Q_PROPERTY(Province* province READ province WRITE setProvince NOTIFY provinceChanged) 45 | Q_PROPERTY(QString postCode READ postCode WRITE setPostCode NOTIFY postCodeChanged) 46 | Q_PROPERTY(int population READ population WRITE setPopulation NOTIFY populationChanged) 47 | Q_PROPERTY(qreal latitude READ latitude WRITE setLatitude NOTIFY latitudeChanged) 48 | Q_PROPERTY(qreal longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged) 49 | 50 | int m_id; 51 | QString m_name; 52 | Province* m_province{nullptr}; 53 | QString m_postCode; 54 | int m_population{0}; 55 | qreal m_latitude{0}; 56 | qreal m_longitude{0}; 57 | 58 | public: 59 | Q_INVOKABLE explicit Community(QObject* parent = nullptr); 60 | explicit Community(QString name, 61 | Province* province, 62 | QString postCode, 63 | int population, 64 | qreal latitude, 65 | qreal longitude, 66 | QObject* parent = nullptr); 67 | 68 | int id() const; 69 | void setId(int id); 70 | 71 | QString name() const; 72 | void setName(QString name); 73 | 74 | Province* province() const; 75 | void setProvince(Province* province); 76 | 77 | QString postCode() const; 78 | void setPostCode(QString postCode); 79 | 80 | int population() const; 81 | void setPopulation(int population); 82 | 83 | qreal latitude() const; 84 | void setLatitude(qreal latitude); 85 | 86 | qreal longitude() const; 87 | void setLongitude(qreal longitude); 88 | 89 | public slots: 90 | 91 | signals: 92 | void idChanged(); 93 | void nameChanged(); 94 | void provinceChanged(); 95 | void postCodeChanged(); 96 | void populationChanged(); 97 | void latitudeChanged(); 98 | void longitudeChanged(); 99 | }; 100 | 101 | #endif // COMMUNITY_H 102 | -------------------------------------------------------------------------------- /tests/auto/qormentitylistmodel/tst_qormentitylistmodel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2021 Dmitriy Purgin 3 | * Copyright (C) 2019 Dmitriy Purgin 4 | * Copyright (C) 2019 sequality software engineering e.U. 5 | * 6 | * This file is part of QtOrm library. 7 | * 8 | * QtOrm is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * QtOrm is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with QtOrm. If not, see . 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "domain/province.h" 29 | #include "domain/town.h" 30 | 31 | class EntityListModelTest : public QObject 32 | { 33 | Q_OBJECT 34 | 35 | private slots: 36 | void initTestCase(); 37 | 38 | void testQVectorTInData(); 39 | }; 40 | 41 | void EntityListModelTest::initTestCase() 42 | { 43 | qRegisterOrmEntity(); 44 | } 45 | 46 | // Source: https://github.com/dpurgin/qtorm/issues/15 47 | void EntityListModelTest::testQVectorTInData() 48 | { 49 | QOrmSession session; 50 | 51 | { 52 | Province* upperAustria = new Province(QString::fromUtf8("Oberösterreich")); 53 | Province* lowerAustria = new Province(QString::fromUtf8("Niederösterreich")); 54 | Province* tirol = new Province(QString::fromUtf8("Tirol")); 55 | 56 | Town* hagenberg = new Town(QString::fromUtf8("Hagenberg"), upperAustria); 57 | Town* pregarten = new Town(QString::fromUtf8("Pregarten"), upperAustria); 58 | Town* melk = new Town(QString::fromUtf8("Melk"), lowerAustria); 59 | 60 | upperAustria->setTowns({hagenberg, pregarten}); 61 | lowerAustria->setTowns({melk}); 62 | 63 | QVERIFY(session.merge(hagenberg, pregarten, melk, upperAustria, lowerAustria, tirol)); 64 | } 65 | 66 | QOrmEntityListModel provinces{session}; 67 | QCOMPARE(provinces.rowCount(), 3); 68 | 69 | // Roles are generated automatically in the same order as QObject properties 70 | // Province::id: UserRole 71 | // Province::name: UserRole+1 72 | // Province::rowns: UserRole+2 73 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 74 | QCOMPARE(provinces.data(provinces.index(0), Qt::UserRole).type(), QMetaType::Int); 75 | #else 76 | QCOMPARE(provinces.data(provinces.index(0), Qt::UserRole).metaType().id(), QMetaType::Int); 77 | #endif 78 | QCOMPARE(provinces.data(provinces.index(0), Qt::UserRole).toInt(), 1); 79 | 80 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 81 | QCOMPARE(provinces.data(provinces.index(0), Qt::UserRole + 1).type(), QMetaType::QString); 82 | #else 83 | QCOMPARE(provinces.data(provinces.index(0), Qt::UserRole + 1).metaType().id(), 84 | QMetaType::QString); 85 | #endif 86 | QCOMPARE(provinces.data(provinces.index(0), Qt::UserRole + 1).toString(), 87 | QString::fromUtf8("Oberösterreich")); 88 | 89 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 90 | QCOMPARE(provinces.data(provinces.index(0), Qt::UserRole + 2).type(), QMetaType::QVariantList); 91 | 92 | #else 93 | QCOMPARE(provinces.data(provinces.index(0), Qt::UserRole + 2).metaType(), 94 | QMetaType::fromType()); 95 | #endif 96 | 97 | auto val = provinces.data(provinces.index(0), Qt::UserRole + 2).toList(); 98 | QCOMPARE(val.size(), 2); 99 | 100 | Town* hagenberg = qobject_cast(val.first().value()); 101 | QVERIFY(hagenberg != nullptr); 102 | QCOMPARE(hagenberg->id(), 1); 103 | QCOMPARE(hagenberg->name(), QString::fromUtf8("Hagenberg")); 104 | } 105 | 106 | QTEST_GUILESS_MAIN(EntityListModelTest) 107 | 108 | #include "tst_qormentitylistmodel.moc" 109 | -------------------------------------------------------------------------------- /examples/orm/navigationdb/domain/community.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * All rights reserved. 5 | * 6 | * This file is part of the examples of the QtOrm library 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the sequality software engineering e.U. nor the 16 | * names of its contributors may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "community.h" 32 | 33 | Community::Community(QObject* parent) 34 | : QObject{parent} 35 | { 36 | } 37 | 38 | Community::Community(QString name, 39 | Province* province, 40 | QString postCode, 41 | int population, 42 | qreal latitude, 43 | qreal longitude, 44 | QObject* parent) 45 | : QObject{parent} 46 | , m_name{std::move(name)} 47 | , m_province{province} 48 | , m_postCode{std::move(postCode)} 49 | , m_population{population} 50 | , m_latitude{latitude} 51 | , m_longitude{longitude} 52 | { 53 | } 54 | 55 | int Community::id() const 56 | { 57 | return m_id; 58 | } 59 | 60 | void Community::setId(int id) 61 | { 62 | if (m_id == id) 63 | return; 64 | 65 | m_id = id; 66 | emit idChanged(); 67 | } 68 | 69 | QString Community::name() const 70 | { 71 | return m_name; 72 | } 73 | 74 | void Community::setName(QString name) 75 | { 76 | if (m_name == name) 77 | return; 78 | 79 | m_name = name; 80 | emit nameChanged(); 81 | } 82 | 83 | Province* Community::province() const 84 | { 85 | return m_province; 86 | } 87 | 88 | void Community::setProvince(Province* province) 89 | { 90 | if (m_province == province) 91 | return; 92 | 93 | m_province = province; 94 | emit provinceChanged(); 95 | } 96 | 97 | QString Community::postCode() const 98 | { 99 | return m_postCode; 100 | } 101 | 102 | void Community::setPostCode(QString postCode) 103 | { 104 | if (m_postCode == postCode) 105 | return; 106 | 107 | m_postCode = postCode; 108 | emit postCodeChanged(); 109 | } 110 | 111 | int Community::population() const 112 | { 113 | return m_population; 114 | } 115 | 116 | void Community::setPopulation(int population) 117 | { 118 | if (m_population == population) 119 | return; 120 | 121 | m_population = population; 122 | emit populationChanged(); 123 | } 124 | 125 | qreal Community::longitude() const 126 | { 127 | return m_longitude; 128 | } 129 | 130 | void Community::setLongitude(qreal longitude) 131 | { 132 | if (qFuzzyCompare(m_longitude, longitude)) 133 | return; 134 | 135 | m_longitude = longitude; 136 | emit longitudeChanged(); 137 | } 138 | 139 | qreal Community::latitude() const 140 | { 141 | return m_latitude; 142 | } 143 | 144 | void Community::setLatitude(qreal latitude) 145 | { 146 | if (qFuzzyCompare(m_latitude, latitude)) 147 | return; 148 | 149 | m_latitude = latitude; 150 | emit latitudeChanged(); 151 | } 152 | -------------------------------------------------------------------------------- /tests/auto/qormentityinstancecache/tst_entityinstancecache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "domain/province.h" 27 | #include "domain/town.h" 28 | 29 | // add necessary includes here 30 | 31 | class EntityInstanceCache : public QObject 32 | { 33 | Q_OBJECT 34 | 35 | public: 36 | EntityInstanceCache(); 37 | ~EntityInstanceCache(); 38 | 39 | private slots: 40 | void init(); 41 | 42 | void testWithObjectId(); 43 | void testModificationTracked(); 44 | }; 45 | 46 | EntityInstanceCache::EntityInstanceCache() 47 | { 48 | 49 | } 50 | 51 | EntityInstanceCache::~EntityInstanceCache() 52 | { 53 | 54 | } 55 | 56 | void EntityInstanceCache::init() 57 | { 58 | qRegisterOrmEntity(); 59 | } 60 | 61 | void EntityInstanceCache::testWithObjectId() 62 | { 63 | QOrmMetadataCache metadataCache; 64 | QOrmEntityInstanceCache instanceCache; 65 | 66 | std::unique_ptr upperAustria{new Province(1, QString::fromUtf8("Oberösterreich"))}; 67 | 68 | instanceCache.insert(metadataCache.get(), upperAustria.get()); 69 | instanceCache.finalize(metadataCache.get(), upperAustria.get()); 70 | 71 | QVERIFY(instanceCache.contains(upperAustria.get())); 72 | QVERIFY(!instanceCache.isModified(upperAustria.get())); 73 | QCOMPARE(instanceCache.get(metadataCache.get(), 1), upperAustria.get()); 74 | QCOMPARE(instanceCache.get(metadataCache.get(), 2), nullptr); 75 | QCOMPARE(instanceCache.get(metadataCache.get(), 1), nullptr); 76 | QCOMPARE(instanceCache.get(metadataCache.get(), 2), nullptr); 77 | 78 | std::unique_ptr hagenberg{new Town(1, QString::fromUtf8("Hagenberg"), nullptr)}; 79 | instanceCache.insert(metadataCache.get(), hagenberg.get()); 80 | instanceCache.finalize(metadataCache.get(), hagenberg.get()); 81 | 82 | QVERIFY(instanceCache.contains(upperAustria.get())); 83 | QVERIFY(instanceCache.contains(hagenberg.get())); 84 | QVERIFY(!instanceCache.isModified(upperAustria.get())); 85 | QVERIFY(!instanceCache.isModified(hagenberg.get())); 86 | QCOMPARE(instanceCache.get(metadataCache.get(), 1), upperAustria.get()); 87 | QCOMPARE(instanceCache.get(metadataCache.get(), 2), nullptr); 88 | QCOMPARE(instanceCache.get(metadataCache.get(), 1), hagenberg.get()); 89 | QCOMPARE(instanceCache.get(metadataCache.get(), 2), nullptr); 90 | 91 | QCOMPARE(instanceCache.take(upperAustria.get()), upperAustria.get()); 92 | QCOMPARE(instanceCache.get(metadataCache.get(), 1), nullptr); 93 | QVERIFY(!instanceCache.contains(upperAustria.get())); 94 | 95 | QCOMPARE(instanceCache.take(hagenberg.get()), hagenberg.get()); 96 | QCOMPARE(instanceCache.get(metadataCache.get(), 1), nullptr); 97 | QVERIFY(!instanceCache.contains(hagenberg.get())); 98 | } 99 | 100 | void EntityInstanceCache::testModificationTracked() 101 | { 102 | QOrmMetadataCache metadataCache; 103 | QOrmEntityInstanceCache instanceCache; 104 | 105 | Province* upperAustria = new Province(1, QString::fromUtf8("Oberösterreich")); 106 | instanceCache.insert(metadataCache.get(), upperAustria); 107 | instanceCache.finalize(metadataCache.get(), upperAustria); 108 | 109 | QVERIFY(!instanceCache.isModified(upperAustria)); 110 | 111 | upperAustria->setName(QString::fromUtf8("Upper Austria")); 112 | QVERIFY(instanceCache.isModified(upperAustria)); 113 | 114 | instanceCache.markUnmodified(upperAustria); 115 | QVERIFY(!instanceCache.isModified(upperAustria)); 116 | } 117 | 118 | QTEST_APPLESS_MAIN(EntityInstanceCache) 119 | 120 | #include "tst_entityinstancecache.moc" 121 | -------------------------------------------------------------------------------- /src/orm/qormentityinstancecache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #include "qormentityinstancecache.h" 22 | #include "qormglobal_p.h" 23 | #include "qormmetadata.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | QT_BEGIN_NAMESPACE 31 | 32 | class QOrmEntityInstanceCachePrivate : public QObject 33 | { 34 | Q_OBJECT 35 | 36 | friend class QOrmEntityInstanceCache; 37 | using ObjectId = QPair; 38 | 39 | private slots: 40 | void onEntityInstanceChanged(); 41 | 42 | private: 43 | QHash m_cache; 44 | QMap m_byObjectId; 45 | QSet m_modifiedInstances; 46 | }; 47 | 48 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 49 | inline bool operator<(const QVariant& lhs, const QVariant& rhs) 50 | { 51 | QPartialOrdering ordering = QVariant::compare(lhs, rhs); 52 | return ordering == QPartialOrdering::Less; 53 | } 54 | #endif 55 | 56 | void QOrmEntityInstanceCachePrivate::onEntityInstanceChanged() 57 | { 58 | Q_ASSERT(m_cache.contains(sender())); 59 | m_modifiedInstances.insert(sender()); 60 | } 61 | 62 | QOrmEntityInstanceCache::QOrmEntityInstanceCache() 63 | : d{new QOrmEntityInstanceCachePrivate} 64 | { 65 | } 66 | 67 | QOrmEntityInstanceCache::~QOrmEntityInstanceCache() 68 | { 69 | for (auto it = std::begin(d->m_cache); it != std::end(d->m_cache); ++it) 70 | { 71 | it.key()->disconnect(d.get()); 72 | delete it.key(); 73 | } 74 | 75 | d->m_cache.clear(); 76 | } 77 | 78 | QObject* QOrmEntityInstanceCache::get(const QOrmMetadata& meta, const QVariant& objectId) 79 | { 80 | return d->m_byObjectId.value(qMakePair(meta.className(), objectId), nullptr); 81 | } 82 | 83 | bool QOrmEntityInstanceCache::contains(const QObject* instance) const 84 | { 85 | return d->m_cache.contains(const_cast(instance)); 86 | } 87 | 88 | void QOrmEntityInstanceCache::insert(const QOrmMetadata& metadata, QObject* instance) 89 | { 90 | Q_ASSERT(metadata.objectIdMapping() != nullptr); 91 | Q_ASSERT(instance != nullptr); 92 | 93 | if (d->m_cache.contains(instance)) 94 | return; 95 | 96 | auto objectId = 97 | qMakePair(metadata.className(), QOrmPrivate::objectIdPropertyValue(instance, metadata)); 98 | 99 | d->m_cache.insert(instance, objectId); 100 | d->m_byObjectId.insert(objectId, instance); 101 | } 102 | 103 | QObject* QOrmEntityInstanceCache::take(QObject* instance) 104 | { 105 | d->m_byObjectId.remove(d->m_cache[instance]); 106 | d->m_modifiedInstances.remove(instance); 107 | d->m_cache.remove(instance); 108 | 109 | return instance; 110 | } 111 | 112 | void QOrmEntityInstanceCache::finalize(const QOrmMetadata& metadata, QObject* instance) 113 | { 114 | for (const QOrmPropertyMapping& mapping : metadata.propertyMappings()) 115 | { 116 | if (mapping.isTransient() && !mapping.isReference()) 117 | continue; 118 | 119 | // connect to NOTIFY signals of the entity to mark the instance dirty on any change 120 | QMetaMethod notifySignal = mapping.qMetaProperty().notifySignal(); 121 | int slotIndex = QOrmEntityInstanceCachePrivate::staticMetaObject.indexOfSlot( 122 | "onEntityInstanceChanged()"); 123 | QMetaMethod slot = QOrmEntityInstanceCachePrivate::staticMetaObject.method(slotIndex); 124 | 125 | QObject::connect(instance, notifySignal, d.get(), slot); 126 | } 127 | } 128 | 129 | bool QOrmEntityInstanceCache::isModified(const QObject* instance) const 130 | { 131 | return d->m_modifiedInstances.contains(instance); 132 | } 133 | 134 | void QOrmEntityInstanceCache::markUnmodified(const QObject* instance) const 135 | { 136 | d->m_modifiedInstances.remove(instance); 137 | } 138 | 139 | QT_END_NAMESPACE 140 | 141 | #include "qormentityinstancecache.moc" 142 | -------------------------------------------------------------------------------- /src/orm/qormsession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Dmitriy Purgin 3 | * Copyright (C) 2019 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMSESSION_H 22 | #define QORMSESSION_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | 36 | QT_BEGIN_NAMESPACE 37 | 38 | class QOrmAbstractProvider; 39 | class QOrmEntityInstanceCache; 40 | class QOrmError; 41 | class QOrmQuery; 42 | class QOrmSessionPrivate; 43 | 44 | template 45 | class QOrmQueryBuilder; 46 | 47 | class Q_ORM_EXPORT QOrmSession 48 | { 49 | Q_DECLARE_PRIVATE(QOrmSession) 50 | 51 | public: 52 | explicit QOrmSession( 53 | QOrmSessionConfiguration configuration = QOrmSessionConfiguration::defaultConfiguration()); 54 | ~QOrmSession(); 55 | 56 | Q_REQUIRED_RESULT 57 | QOrmQueryResult execute(const QOrmQuery& query); 58 | 59 | Q_REQUIRED_RESULT 60 | QOrmQueryBuilder from(const QOrmQuery& query); 61 | 62 | template 63 | bool merge(T* entityInstance) 64 | { 65 | return doMerge(entityInstance, T::staticMetaObject); 66 | } 67 | 68 | template 69 | bool merge(std::unique_ptr& entityInstance) 70 | { 71 | if (merge(entityInstance.get())) 72 | { 73 | entityInstance.release(); 74 | return true; 75 | } 76 | 77 | return false; 78 | } 79 | 80 | template 81 | bool merge(std::initializer_list instances) 82 | { 83 | QOrmTransactionToken token = declareTransaction(QOrm::TransactionPropagation::Require, 84 | QOrm::TransactionAction::Commit); 85 | 86 | for (T* instance : instances) 87 | { 88 | if (!merge(instance)) 89 | { 90 | token.rollback(); 91 | return false; 92 | } 93 | } 94 | 95 | return true; 96 | } 97 | 98 | template 99 | bool merge(Ts... instances) 100 | { 101 | QOrmTransactionToken token = declareTransaction(QOrm::TransactionPropagation::Require, 102 | QOrm::TransactionAction::Commit); 103 | 104 | if (!(... && merge(instances))) 105 | { 106 | token.rollback(); 107 | return false; 108 | } 109 | 110 | return true; 111 | } 112 | 113 | template 114 | std::unique_ptr remove(T* entityInstance) 115 | { 116 | return doRemove(entityInstance, T::staticMetaObject) ? std::unique_ptr(entityInstance) 117 | : nullptr; 118 | } 119 | 120 | template 121 | QOrmQueryBuilder from() 122 | { 123 | return queryBuilderFor(T::staticMetaObject); 124 | } 125 | 126 | template 127 | QOrmQueryBuilder into() 128 | { 129 | return queryBuilderFor(T::staticMetaObject); 130 | } 131 | 132 | Q_REQUIRED_RESULT 133 | QOrmTransactionToken declareTransaction(QOrm::TransactionPropagation propagation, 134 | QOrm::TransactionAction finalAction); 135 | 136 | Q_REQUIRED_RESULT 137 | QOrmError lastError() const; 138 | 139 | Q_REQUIRED_RESULT 140 | const QOrmSessionConfiguration& configuration() const; 141 | 142 | Q_REQUIRED_RESULT 143 | QOrmMetadataCache* metadataCache(); 144 | 145 | Q_REQUIRED_RESULT 146 | QOrmEntityInstanceCache* entityInstanceCache(); 147 | 148 | bool beginTransaction(); 149 | bool commitTransaction(); 150 | bool rollbackTransaction(); 151 | bool isTransactionActive() const; 152 | 153 | private: 154 | bool doMerge(QObject* entityInstance, const QMetaObject& qMetaObject); 155 | bool doRemove(QObject* entityInstance, const QMetaObject& qMetaObject); 156 | 157 | QOrmQueryBuilder queryBuilderFor(const QMetaObject& relationMetaObject); 158 | 159 | private: 160 | QOrmSessionPrivate* d_ptr{nullptr}; 161 | }; 162 | 163 | QT_END_NAMESPACE 164 | 165 | 166 | #endif // QORMSESSION_H 167 | -------------------------------------------------------------------------------- /src/orm/orm.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | import qbs.File 3 | import qbs.FileInfo 4 | import qbs.TextFile 5 | 6 | Project { 7 | DynamicLibrary { 8 | name: "QtOrm" 9 | install: true 10 | Group { 11 | name: "public" 12 | files: [ 13 | "qormabstractprovider.h", 14 | "qormclassproperty.h", 15 | "qormentityinstancecache.h", 16 | "qormentitylistmodel.h", 17 | "qormerror.h", 18 | "qormfilter.h", 19 | "qormfilterexpression.h", 20 | "qormglobal.h", 21 | "qormmetadata.h", 22 | "qormmetadatacache.h", 23 | "qormorder.h", 24 | "qormpropertymapping.h", 25 | "qormquery.h", 26 | "qormquerybuilder.h", 27 | "qormqueryresult.h", 28 | "qormrelation.h", 29 | "qormsession.h", 30 | "qormsessionconfiguration.h", 31 | "qormsqliteconfiguration.h", 32 | "qormsqliteprovider.h", 33 | "qormtransactiontoken.h", 34 | ] 35 | fileTags: ["public_headers"] 36 | } 37 | Group { 38 | name: "private" 39 | files: [ 40 | "qormglobal_p.h", 41 | "qormmetadata_p.h", 42 | "qormsqlitestatementgenerator_p.h", 43 | ] 44 | fileTags: ["private_headers"] 45 | } 46 | Rule { 47 | inputs: ["public_headers"] 48 | outputArtifacts: [{ 49 | filePath: FileInfo.joinPaths(project.buildDirectory, "include", "QtOrm", 50 | input.fileName), 51 | fileTags: ["hpp"], 52 | }] 53 | outputFileTags: "hpp" 54 | prepare: { 55 | var cmd = new JavaScriptCommand(); 56 | cmd.description = "copy " + input.fileName; 57 | cmd.sourceCode = function() { 58 | File.copy(input.filePath, output.filePath); 59 | var file = new TextFile(input.filePath, TextFile.ReadOnly); 60 | var regexp = /[\s]*class[\t ]+(Q_ORM_EXPORT[\t ]+)?(QOrm[A-Za-z0-9_]+)[^;]*$/ 61 | while (!file.atEof()) { 62 | match = regexp.exec(file.readLine()); 63 | if (match) { 64 | var path = FileInfo.joinPaths(project.buildDirectory, "include"); 65 | var headerFile = new TextFile( 66 | FileInfo.joinPaths(path, match[2]), TextFile.WriteOnly); 67 | headerFile.write("#include \"" + input.filePath + "\""); 68 | } 69 | } 70 | file.close(); 71 | }; 72 | return [cmd]; 73 | } 74 | } 75 | Rule { 76 | inputs: ["private_headers"] 77 | outputArtifacts: [{ 78 | filePath: FileInfo.joinPaths(project.buildDirectory, "include", "QtOrm", 79 | "private", input.fileName), 80 | fileTags: ["hpp"], 81 | }] 82 | outputFileTags: "hpp" 83 | prepare: { 84 | var cmd = new JavaScriptCommand(); 85 | cmd.description = "copy " + input.fileName; 86 | cmd.sourceCode = function() { 87 | File.copy(input.filePath, output.filePath); 88 | }; 89 | return [cmd]; 90 | } 91 | } 92 | 93 | Depends { name: "cpp" } 94 | cpp.includePaths: FileInfo.joinPaths(project.buildDirectory, "include") 95 | cpp.cxxLanguageVersion: "c++17" 96 | Depends { name: "Qt"; submodules: ["core", "sql"] } 97 | Export { 98 | Depends { name: "cpp" } 99 | cpp.includePaths: [ 100 | FileInfo.joinPaths(project.buildDirectory, "include"), 101 | FileInfo.joinPaths(project.buildDirectory, "include", "QtOrm") 102 | ] 103 | } 104 | 105 | files: [ 106 | "qormabstractprovider.cpp", 107 | "qormclassproperty.cpp", 108 | "qormentityinstancecache.cpp", 109 | "qormentitylistmodel.cpp", 110 | "qormerror.cpp", 111 | "qormfilter.cpp", 112 | "qormfilterexpression.cpp", 113 | "qormglobal.cpp", 114 | "qormglobal_p.cpp", 115 | "qormmetadata.cpp", 116 | "qormmetadatacache.cpp", 117 | "qormorder.cpp", 118 | "qormpropertymapping.cpp", 119 | "qormquery.cpp", 120 | "qormquerybuilder.cpp", 121 | "qormqueryresult.cpp", 122 | "qormrelation.cpp", 123 | "qormsession.cpp", 124 | "qormsessionconfiguration.cpp", 125 | "qormsqliteconfiguration.cpp", 126 | "qormsqliteprovider.cpp", 127 | "qormsqlitestatementgenerator_p.cpp", 128 | "qormtransactiontoken.cpp", 129 | ] 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /src/orm/qormquerybuilder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019-2025 Dmitriy Purgin 3 | * Copyright (C) 2019-2025 sequality software engineering e.U. 4 | * 5 | * This file is part of QtOrm library. 6 | * 7 | * QtOrm is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * QtOrm is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with QtOrm. If not, see . 19 | */ 20 | 21 | #ifndef QORMQUERYBUILDER_H 22 | #define QORMQUERYBUILDER_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | QT_BEGIN_NAMESPACE 37 | 38 | class QOrmAbstractProvider; 39 | class QOrmFilterExpression; 40 | class QOrmMetadataCache; 41 | class QOrmQueryBuilderPrivate; 42 | class QOrmRelation; 43 | class QOrmSession; 44 | 45 | namespace QOrmPrivate 46 | { 47 | class QueryBuilderHelperPrivate; 48 | 49 | class Q_ORM_EXPORT QueryBuilderHelper 50 | { 51 | public: 52 | QueryBuilderHelper(QOrmSession* session, const QOrmRelation& relation); 53 | QueryBuilderHelper(const QueryBuilderHelper&) = delete; 54 | QueryBuilderHelper(QueryBuilderHelper&&) noexcept; 55 | ~QueryBuilderHelper(); 56 | 57 | QueryBuilderHelper& operator=(const QueryBuilderHelper&) = delete; 58 | QueryBuilderHelper& operator=(QueryBuilderHelper&&) noexcept; 59 | 60 | void setInstance(const QMetaObject& qMetaObject, QObject* instance); 61 | void addFilter(const QOrmFilter& filter); 62 | void addOrder(const QOrmClassProperty& classProperty, Qt::SortOrder direction); 63 | void setLimit(int limit); 64 | void setOffset(int offset); 65 | 66 | Q_REQUIRED_RESULT 67 | QOrmQuery build(QOrm::Operation operation, QOrm::QueryFlags flags) const; 68 | 69 | [[nodiscard]] QOrmQueryResult select(QOrm::QueryFlags flags) const; 70 | [[nodiscard]] QOrmQueryResult remove() const; 71 | [[nodiscard]] QOrmQueryResult count() const; 72 | 73 | private: 74 | std::unique_ptr d; 75 | }; 76 | } // namespace QOrmPrivate 77 | 78 | template 79 | class QOrmQueryBuilder 80 | { 81 | template 82 | friend class QOrmQueryBuilder; 83 | 84 | public: 85 | using Projection = std::decay_t; 86 | using UnaryPredicate = std::function; 87 | 88 | explicit QOrmQueryBuilder(QOrmSession* session, const QOrmRelation& relation) 89 | : m_helper{session, relation} 90 | { 91 | } 92 | 93 | QOrmQueryBuilder(const QOrmQueryBuilder&) = delete; 94 | 95 | template || std::is_same_v>> 97 | QOrmQueryBuilder(QOrmQueryBuilder&& other) 98 | : m_helper{std::move(other.m_helper)} 99 | { 100 | } 101 | 102 | QOrmQueryBuilder& operator=(const QOrmQueryBuilder&) = delete; 103 | QOrmQueryBuilder& operator=(QOrmQueryBuilder&&) = default; 104 | 105 | QOrmQueryBuilder& filter(QOrmFilterExpression expression) 106 | { 107 | m_helper.addFilter(QOrmFilter{expression}); 108 | return *this; 109 | } 110 | 111 | QOrmQueryBuilder& filter(UnaryPredicate predicate) 112 | { 113 | m_helper.addFilter(QOrmFilter{[predicate](const QObject* value) { 114 | return predicate(qobject_cast(value)); 115 | }}); 116 | return *this; 117 | } 118 | 119 | QOrmQueryBuilder& order(const QOrmClassProperty& classProperty, 120 | Qt::SortOrder direction = Qt::AscendingOrder) 121 | { 122 | m_helper.addOrder(classProperty, direction); 123 | return *this; 124 | } 125 | 126 | QOrmQueryBuilder& instance(const QMetaObject& qMetaObject, QObject* instance) 127 | { 128 | m_helper.setInstance(qMetaObject, instance); 129 | return *this; 130 | } 131 | 132 | QOrmQueryBuilder& limit(int limit) 133 | { 134 | m_helper.setLimit(limit); 135 | return *this; 136 | } 137 | 138 | QOrmQueryBuilder& offset(int offset) 139 | { 140 | m_helper.setOffset(offset); 141 | return *this; 142 | } 143 | 144 | Q_REQUIRED_RESULT 145 | QOrmQueryResult select(QOrm::QueryFlags flags = QOrm::QueryFlags::None) const 146 | { 147 | return m_helper.select(flags); 148 | } 149 | 150 | [[nodiscard]] QOrmQueryResult remove() { return m_helper.remove(); } 151 | 152 | [[nodiscard]] QOrmQueryResult count() const { return m_helper.count(); } 153 | 154 | Q_REQUIRED_RESULT 155 | QOrmQuery build(QOrm::Operation operation, QOrm::QueryFlags flags = QOrm::QueryFlags::None) const { return m_helper.build(operation, flags); } 156 | 157 | private: 158 | QOrmPrivate::QueryBuilderHelper m_helper; 159 | }; 160 | 161 | QT_END_NAMESPACE 162 | 163 | #endif // QORMQUERYBUILDER_H 164 | --------------------------------------------------------------------------------