Skip to content

Commit

Permalink
Perform a column alias mapping (#29)
Browse files Browse the repository at this point in the history
* Perform a column alias mapping

* Use debug build to enable tiny output

* Read query while there's data to read rather then after all data has
been readt.

* Rebase vcpkg to TinyORM upstream port PR for 3.36.4
  • Loading branch information
SchaichAlonso authored Nov 2, 2023
1 parent b34683f commit 6462ecf
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/typical-presets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
vcpkg_target_triplet: ['x64-windows', 'x64-linux']
build_type: ['release']
build_type: ['debug']
include:
- vcpkg_target_triplet: 'x64-linux'
mono: 'mono'
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ set_target_properties(TinyOrmQueryTest PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RU

enable_testing()

add_test(NAME QSqlQueryTest COMMAND QSqlQueryTest -o "${CMAKE_CURRENT_BINARY_DIR}/QSqlQueryTest.xml,junitxml" COMMAND_EXPAND_LISTS)
add_test(NAME QSqlQueryTest COMMAND QSqlQueryTest -o -,txt -o "${CMAKE_CURRENT_BINARY_DIR}/QSqlQueryTest.xml,junitxml" COMMAND_EXPAND_LISTS)
set_property(TEST QSqlQueryTest PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/bin")
set_property(TEST QSqlQueryTest APPEND PROPERTY ENVIRONMENT_MODIFICATION "QT_PLUGIN_PATH=set:${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/Qt6/plugins")

add_test(NAME TinyOrmQueryTest COMMAND TinyOrmQueryTest -o "${CMAKE_CURRENT_BINARY_DIR}/TinyOrmQueryTest.xml,junitxml" COMMAND_EXPAND_LISTS)
add_test(NAME TinyOrmQueryTest COMMAND TinyOrmQueryTest -o -,txt -o "${CMAKE_CURRENT_BINARY_DIR}/TinyOrmQueryTest.xml,junitxml" COMMAND_EXPAND_LISTS)
set_property(TEST TinyOrmQueryTest PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/bin")
set_property(TEST TinyOrmQueryTest APPEND PROPERTY ENVIRONMENT_MODIFICATION "QT_PLUGIN_PATH=set:${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/Qt6/plugins")
62 changes: 62 additions & 0 deletions TinyOrmQueryTest.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtSql/QSqlRecord>

#include "TinyOrmQueryTest.hpp"

namespace MyNamespace
Expand Down Expand Up @@ -120,6 +124,64 @@ namespace MyNamespace
QVERIFY(exceptionReceived);
QCOMPARE(rowCount, 2);
}

void MyTinyTest::columnAlias()
{
try {

Orm::DB::beginTransaction();
Orm::Schema::create(
"users",
[](Orm::SchemaNs::Blueprint &table)
{
table.id();
table.text("email").nullable();
table.text("name").nullable();
}
);

Orm::DB::table("users")->insertGetId(
QVariantMap{
{"name", "John Doe"},
{"email", "[email protected]"}
}
);

Orm::DB::table("users")->insertGetId(
QVariantMap{
{"name", "Jane Doe"},
{"email", "[email protected]"}
}
);

QSqlQuery query = Orm::DB::table("users")
->select({"name", "email AS user_email"})
.get();

for(int n=0; query.next(); ++n) {
QSqlRecord record(query.record());
for(int i=0; i<record.count(); ++i) {
qDebug() << QJsonDocument(
QJsonObject{
{ "row number", n },
{ "column index", i },
{ "column name", record.fieldName(i) },
{ "column value", query.value(record.fieldName(i)).toString() }
}).toJson().constData();
}

QVERIFY((QStringList() << "[email protected]" << "[email protected]").contains(query.value("user_email")));
}

Orm::Schema::drop("users");
Orm::DB::commit();
}
catch (const std::exception &ex)
{
Orm::DB::rollBack();
qCritical() << ex.what();
}
}
}

QTEST_MAIN(MyNamespace::MyTinyTest);
1 change: 1 addition & 0 deletions TinyOrmQueryTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace MyNamespace

void helloWorld();
void invalidInsert();
void columnAlias();

private:
std::shared_ptr<Orm::DatabaseManager> m_db;
Expand Down
2 changes: 1 addition & 1 deletion vcpkg
Submodule vcpkg updated 356 files

0 comments on commit 6462ecf

Please sign in to comment.