### C++ TinyORM Hello World with Qt Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx This C++ code snippet demonstrates a basic 'Hello World' example using the TinyORM library. It initializes a QCoreApplication, sets up a database connection using QSQLITE, and performs a simple SELECT query on a 'posts' table, printing the 'id' and 'name' columns. It requires Qt and TinyORM to be installed and configured. ```cpp #include #endif #include using Orm::DB; int main(int argc, char *argv[]) { #ifdef _WIN32 SetConsoleOutputCP(CP_UTF8); // SetConsoleOutputCP(1250); #endif /* Needed from Qt v6.5.3 to avoid: qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter */ QCoreApplication app(argc, argv); // Ownership of a shared_ptr() auto manager = DB::create({ {"driver", "QSQLITE"}, {"database", qEnvironmentVariable("TINYORM_HELLOWORLD_DB_SQLITE_DATABASE", "../../HelloWorld.sqlite3")}, {"check_database_exists", true}, }); auto posts = DB::select("select * from posts"); while(posts.next()) qDebug() << posts.value("id").toULongLong() << posts.value("name").toString(); } ``` -------------------------------- ### Copy conf.pri Example Files for Manual Configuration (Bash) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Copies example conf.pri files to their active counterparts for manual configuration of TinyORM's qmake build dependencies in Bash. This method is for older versions or non-standard installations. ```bash cd ${applicationFolderPath(bash)}/TinyORM/TinyORM cp conf.pri.example conf.pri cp tests/conf.pri.example tests/conf.pri cp tests/testdata_tom/conf.pri.example tests/testdata_tom/conf.pri cp examples/tom/conf.pri.example examples/tom/conf.pri ``` -------------------------------- ### Manage Qt Installations (Linux) Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt Provides commands for managing Qt installations on Linux, including removing old versions, listing available versions, and installing new versions using aqt and the Maintenance Tool. It details how to install specific Qt versions and packages, and how to search, install, and remove packages using the Maintenance Tool. ```bash # Removing old Qt sudo rm -rf /opt/Qt/6.5.3 # Install Qt v6.7.2 aqt list-qt linux desktop aqt list-qt linux desktop --arch 6.7.2 aqt install-qt --external 7z --outputdir /opt/Qt linux desktop 6.7.2 linux_gcc_64 # Qt Maintenance Tool - Update Qt (e.g., 6.7.0 -> 6.7.2) ./MaintenanceTool --type package --filter-packages "DisplayName=Desktop" search qt.qt6.671.linux_gcc_64 ./MaintenanceTool install qt.qt6.671.linux_gcc_64 ./MaintenanceTool --mirror https://qt-mirror.dannhauer.de install qt.qt6.671.linux_gcc_64 ./MaintenanceTool remove qt.qt6.670.linux_gcc_64 # Initial installation of Qt base FW only (w/o user input): ./qt-unified-linux-x64-4.7.0-online.run --root /opt/Qt --email 'silver.zachara@gmail.com' --password '' --accept-licenses --default-answer --confirm-command install qt.qt6.670.linux_gcc_64 # Following install also QtCreator, QtDesignerStudio, CMake, and Ninja: ./qt-unified-linux-x64-4.7.0-online.run --root /opt/Qt --email 'silver.zachara@gmail.com' --password '' install # Searching packages: ./MaintenanceTool --type package --filter-packages "DisplayName=Desktop, Version=6.7.0" search qt.qt6.670.linux_gcc_64 ./MaintenanceTool --type package --filter-packages "DisplayName=Desktop" search qt.qt6.670.linux_gcc_64 # Install packages: ./MaintenanceTool install qt.qt6.672.linux_gcc_64 ./MaintenanceTool --mirror https://qt-mirror.dannhauer.de install qt.qt6.672.linux_gcc_64 # Removing packages: ./MaintenanceTool remove qt.tools.cmake qt.tools.ninja qt.tools.qtcreator_gui qt.tools.qtdesignstudio # Updating packages (not tested yet): ./MaintenanceTool update ./MaintenanceTool update qt.qt6.670.linux_gcc_64 # Others: ./MaintenanceTool check-updates ./MaintenanceTool clear-cache (if cache is too big: du -sh ~/.cache/qt-unified-linux-online) ``` -------------------------------- ### Copy conf.pri Example Files for Manual Configuration (PowerShell) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Copies example conf.pri files to their active counterparts for manual configuration of TinyORM's qmake build dependencies in PowerShell. This method is for older versions or non-standard installations. ```powershell cd ${applicationFolderPath(pwsh)}/TinyORM/TinyORM cp conf.pri.example conf.pri cp tests/conf.pri.example tests/conf.pri cp tests/testdata_tom/conf.pri.example tests/testdata_tom/conf.pri cp examples/tom/conf.pri.example examples/tom/conf.pri ``` -------------------------------- ### Install and Update Development Tools (Linux) Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt Installs essential development tools such as clang, clang-tidy, and lld using apt. It also includes steps to upgrade pip and aqtinstall, which is a prerequisite for managing Qt installations. ```bash sudo apt install clang-18 clang-tidy-18 lld-18 python3 -m pip install --upgrade pip aqt version pip list pip show aqtinstall pip install --upgrade aqtinstall ``` -------------------------------- ### Vcpkg Install Commands for TinyORM Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt Demonstrates various vcpkg install commands for TinyORM, including core dependencies, Qt6 with SQL support, and options for dry-run, editable installs, and testing with the latest commit (--head). ```bash vcpkg install tinyorm[core] qtbase[core,sql] --dry-run vcpkg install tinyorm[core] qtbase[core,sql-sqlite] --dry-run vcpkg install tinyorm[core] vcpkg install tinyorm[core] --editable ``` ```bash vcpkg install tinyorm[core,sql-mysql,tom-example]:x64-windows --recurse --editable --head vcpkg install tinyorm[core,build-mysql-driver,tom-example]:x64-windows --recurse --editable --head vcpkg install tinyorm[core,sql-mysql,tom-example]:x64-windows-static --recurse --editable --head vcpkg install tinyorm[core,build-mysql-driver,tom-example]:x64-windows-static --recurse --editable --head ``` ```bash vcpkg install libmysql libmysql:x64-windows-static vcpkg install qtbase[core] qtbase[core]:x64-windows-static --recurse vcpkg install qtbase[core,sql-mysql] qtbase[core,sql-mysql]:x64-windows-static --recurse ``` -------------------------------- ### Executing TinyORM Hello World Example Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx Details on how to run the 'Hello World' example after building the TinyORM project. It explains how QtCreator manages environment paths for dependencies and how to configure the run settings to execute the example in a new terminal window. ```text The `QtCreator` takes care of all the necessary configurations, sets up the build environment correctly, and also prepends dependency libraries on the system path on Windows and on the `LD_LIBRARY_PATH` on Linux. The only thing you might want to change is to run the `HelloWorld` example in the new terminal window. To do so, hit Ctrl+5 to open the `Project Settings` tab and select `Run` in the left sidebar to open the `Run Settings`, then in the `Run` section select the `Run in terminal` checkbox. To execute the `HelloWorld` example press Ctrl + r. ``` -------------------------------- ### Integrate TinyORM Library using .qmake.conf Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx This example demonstrates how to set up the .qmake.conf file to integrate the TinyORM library into your qmake project. It specifies paths for the TinyORM source and build directories, vcpkg installation, and dotenv root. These settings are crucial for qmake to locate and configure the TinyORM library correctly. ```qmake # Path to the PARENT folder of the TinyORM source folder TINY_MAIN_DIR = $$clean_path() # To find .env and .env.$$QMAKE_PLATFORM files in YOUR project TINY_DOTENV_ROOT = $$PWD # Path to the TinyORM build folder (specified manually) TINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_2_MSVC2019_64bit-Debug/) # vcpkg - range-v3 and tabulate TINY_VCPKG_ROOT = $$quote(/vcpkg/) #TINY_VCPKG_TRIPLET = x64-windows ``` -------------------------------- ### Build and Install TinyORM Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx These commands demonstrate how to build and install the TinyORM library. The first command builds all targets, and the second installs the built targets. An alternative single-step command is also provided. ```bash cmake --build . --target all cmake --install . ``` ```bash cmake --build . --target install ``` -------------------------------- ### Clone and Bootstrap vcpkg (Bash) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Clones the vcpkg repository from GitHub and bootstraps the installation using Bash. This is the initial setup step for vcpkg on Linux. ```bash git clone git@github.com:microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ``` -------------------------------- ### Install Basic TinyORM and with Features Source: https://github.com/silverqx/tinyorm/blob/main/cmake/vcpkg/README.md Demonstrates installing the base TinyORM package and installing it with additional features like 'tom-example' and PostgreSQL support. ```bash vcpkg install tinyorm vcpkg install tinyorm[core,tom-example] vcpkg install tinyorm[core,sql-psql] ``` -------------------------------- ### Clone and Bootstrap vcpkg (PowerShell) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Clones the vcpkg repository from GitHub and bootstraps the installation using PowerShell. This is the initial setup step for vcpkg on Windows. ```powershell git clone git@github.com:microsoft/vcpkg.git cd vcpkg .\bootstrap-vcpkg.bat ``` -------------------------------- ### Install Dependencies with vcpkg (Manual) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx Installs the 'range-v3' and 'tabulate' libraries using the vcpkg package manager manually. This method is compatible with both CMake and qmake. ```bash cd ../../vcpkg vcpkg search range-v3 vcpkg search tabulate vcpkg install range-v3 tabulate vcpkg list ``` -------------------------------- ### Install TinyORM Package Source: https://github.com/silverqx/tinyorm/blob/main/tools/distributions/gentoo/var/db/repos/README.md Installs the tinyorm package using the 'emerge' command with quiet build and verbose output. This command fetches, compiles, and installs the package according to the configured repository and USE flags. ```bash sudo emerge --quiet-build -va tinyorm ``` -------------------------------- ### Upgrade Qt Build Script Example Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt This PowerShell script demonstrates how to build the QMYSQL driver for Qt version 6.7.2. It's part of the process for upgrading Qt versions in the project. ```powershell qtbuild-qmysql-driver.ps1 6.7.2 ``` -------------------------------- ### Copy .env Example Files for Auto-configuration (Bash) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Copies the platform-specific .env example file to a usable .env file for auto-configuration in Bash. This is part of the recommended auto-configuration method for TinyORM. ```bash cd ${applicationFolderPath(bash)}/TinyORM/TinyORM cp .env.unix.example .env.unix ``` -------------------------------- ### Prepare SQLite Database Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx Creates an SQLite database file named 'HelloWorld.sqlite3' and populates it with a 'posts' table containing two initial entries. This database is used by the 'Hello world' example. ```bash sqlite3 HelloWorld.sqlite3 " create table posts(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL); insert into posts values(1, 'First Post'); insert into posts values(2, 'Second Post'); select * from posts;" ``` -------------------------------- ### MySQL Configuration Command Example Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt This command-line snippet is used to print all configurations from the MySQL configuration editor. It's relevant for managing MySQL server settings, particularly time zone tables. ```bash mysql_config_editor print --all ``` -------------------------------- ### Copy .env Example Files for Auto-configuration (PowerShell) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Copies the platform-specific .env example file to a usable .env file for auto-configuration in PowerShell. This is part of the recommended auto-configuration method for TinyORM. ```powershell cd ${applicationFolderPath(pwsh)}/TinyORM/TinyORM cp .env.win32.example .env.win32 ``` -------------------------------- ### Generate Download Hash Script Example Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt This PowerShell script is used to generate a hash for downloaded files, likely for integrity checks. It's part of the upgrade process for Qt and its associated DLLs. ```powershell .\tools\Get-DownloadsHash.ps1 -Platform Linux, Windows ``` -------------------------------- ### Set up Qt Environment Scripts for Windows and Linux Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx These scripts configure the environment for using a specific Qt version. They set the Qt installation path and update the system's PATH and LD_LIBRARY_PATH environment variables. The scripts are designed to be sourced, not executed directly, and can utilize the TINY_QT_ROOT environment variable for the Qt installation directory. ```powershell #!/usr/bin/env pwsh Set-StrictMode -Version 3.0 Write-Host 'Setting up environment for Qt 6.7.2 usage...' -ForegroundColor Magenta Write-Host $Script:QtRoot = $env:TINY_QT_ROOT ?? 'C:\Qt' $env:Path = "$Script:QtRoot\6.7.2\msvc2019_64\bin;" + $env:Path . vcvars64.ps1 ``` ```bash #!/usr/bin/env sh echo 'Setting up environment for Qt 6.7.2 usage...' QtRoot="${TINY_QT_ROOT:-/opt/Qt}" export PATH="$QtRoot/6.7.2/gcc_64/bin${PATH:+:}$PATH" export LD_LIBRARY_PATH="$QtRoot/6.7.2/gcc_64/lib${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH ``` -------------------------------- ### Include Database Sources with TinySources Source: https://github.com/silverqx/tinyorm/blob/main/examples/tom/CMakeLists.txt Uses the tiny_tom_example_database_sources macro from TinySources to include header files related to database operations for the Tom example. These headers are then added to the executable target's sources. ```cmake include(TinySources) tiny_tom_example_database_sources(${TomExample_target}_headers) target_sources(${TomExample_target} PRIVATE ${${TomExample_target}_headers} ) ``` -------------------------------- ### Static Tab Completion Installation for bash Source: https://github.com/silverqx/tinyorm/blob/main/docs/database/migrations.mdx Sets up bash tab completion by outputting the completion script to a file and then sourcing it in the ~/.bashrc file. This method avoids dynamic evaluation. ```bash mkdir -p ~/.local/share/tom tom integrate bash --stdout > ~/.local/share/tom/tom.bash # Then source this file in the ~/.bashrc source $HOME/.local/share/tom/tom.bash ``` -------------------------------- ### Define Basic Project with CMake Source: https://github.com/silverqx/tinyorm/blob/main/examples/tom/CMakeLists.txt Configures the main project with its name, description, homepage URL, supported languages, and version. This sets up the fundamental properties for the CMake build system. ```cmake project(${TomExample_ns} DESCRIPTION "Tom console application for TinyORM C++ library" HOMEPAGE_URL "https://www.tinyorm.org" LANGUAGES CXX VERSION ${TINY_VERSION} ) ``` -------------------------------- ### Setup CMake Build Directory Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/migrations.mdx Shell commands to navigate to the parent directory, create a build directory for CMake, and then return to the project root. This prepares the environment for CMake builds. ```powershell cd .. mkdir tom-builds-cmake/build-debug cd tom ``` ```bash cd .. mkdir -p tom-builds-cmake/build-debug cd tom ``` -------------------------------- ### Manual TinyORM Library Linking (Bash) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx This example demonstrates manual linking against the TinyORM library using qmake in a Bash environment. It specifies the main directory, includes the TinyORM configuration, sets the build tree path, and appends the library path and name to LIBS. ```qmake # Link against TinyORM library # --- TINY_MAIN_DIR = $$clean_path() # Configure TinyORM library include($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri) # TinyORM library path TINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake) LIBS += $$quote(-L$$TINYORM_BUILD_TREE/build-TinyORM-Desktop_Qt_6_7_2_GCC_64bit-Debug/src$${TINY_BUILD_SUBFOLDER}/) LIBS += -lTinyOrm ``` -------------------------------- ### Manual Tab Completion Setup for zsh Source: https://github.com/silverqx/tinyorm/blob/main/docs/database/migrations.mdx Installs zsh tab completion by creating a symbolic link for the 'tom.zsh' completion script to the zsh site-functions directory. This enables autocompletion for the 'tom' command. ```bash sudo ln -s ${applicationFolderPath(bash)}/TinyORM/tools/completions/tom.zsh /usr/local/share/zsh/site-functions/_tom ``` -------------------------------- ### Configure SQLite Database Connection in C++ Source: https://github.com/silverqx/tinyorm/blob/main/docs/database/getting-started.mdx This code example illustrates setting up a SQLite database connection using TinyORM's `DB::create`. It specifies the driver, database file path, and options for foreign key constraints and database existence checks. Timezone handling is also configured. ```cpp #include using Orm::DB; // Ownership of a shared_ptr() auto manager = DB::create({ {"driver", "QSQLITE"}, {"database", qEnvironmentVariable("DB_DATABASE", "/example/example.sqlite3")}, {"foreign_key_constraints", qEnvironmentVariable("DB_FOREIGN_KEYS", "true")}, {"check_database_exists", true}, /* Specifies what time zone all QDateTime-s will have, the overridden default is the QTimeZone::UTC, set to the QTimeZone::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ {"qt_timezone", QVariant::fromValue(QTimeZone::UTC)}, /* Return a QDateTime/QDate with the correct time zone instead of the QString, only works when the qt_timezone isn't set to the DontConvert. */ {"return_qdatetime", true}, {"prefix", ""}, {"prefix_indexes", false}, }); ``` -------------------------------- ### Manage GitHub Runner Services (Windows PowerShell) Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt A collection of PowerShell scripts for managing GitHub Actions runner services on Windows. These scripts allow for getting service status, stopping, starting, and restarting the runner services. ```powershell # sg-a.ps1 (Get-Service) # sst-a.ps1 (Stop-Service) # ss-a.ps1 (Start-Service) # sr-a.ps1 (Restart-Service) ``` -------------------------------- ### Execute UPDATE Statement and Get Affected Rows (C++) Source: https://github.com/silverqx/tinyorm/blob/main/docs/database/getting-started.mdx Demonstrates executing an UPDATE statement using DB::update, returning the number of affected rows and the QSqlQuery object. Includes an example of checking if any records were updated. ```cpp #include #include auto [affected, query] = DB::update( "update users set updated_at = ? where name = ?", {QDateTime::currentDateTimeUtc(), "Anita"} ); if (!affected) qDebug() << "Any record was updated."; ``` -------------------------------- ### Manual Tab Completion Setup for bash Source: https://github.com/silverqx/tinyorm/blob/main/docs/database/migrations.mdx Installs bash tab completion by creating a symbolic link for the 'tom.bash' completion script to the system's bash completion directory. This enables autocompletion for the 'tom' command. ```bash sudo ln -s ${applicationFolderPath(bash)}/TinyORM/tools/completions/tom.bash /usr/share/bash-completion/completions/tom ``` -------------------------------- ### MySQL Connection Initialization - MySqlDriver::open() Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt This snippet details the steps involved in establishing a connection to a MySQL database using the MySqlDriver. It includes initializing the MySQL client library, setting connection options, character set, and selecting the database. It also checks for support of prepared statements. ```cpp MySqlDriverPrivate::MYSQL *mysql = nullptr; mysql = mysql_init(nullptr); mysql_options(mysql, MYSQL_SET_CHARSET_NAME, characterSetName.toUtf8().constData()); mysql_real_connect(mysql, host.toUtf8().constData(), user.toUtf8().constData(), password.toUtf8().constData(), database.toUtf8().constData(), port, nullptr, 0); mysql_set_character_set(mysql, characterSetName.toUtf8().constData()); mysql_select_db(mysql, database.toUtf8().constData()); // check if this client and server version of MySQL/MariaDB supports prepared statements checkPreparedQueries(mysql); mysql_stmt_init(mysql); mysql_stmt_prepare(d->stmt); // Assuming d->stmt is initialized elsewhere mysql_stmt_param_count(d->stmt); // mysql_thread_init() is called automatically by mysql_init() ``` -------------------------------- ### Configure CMake Prefix Path for TinyORM Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx This snippet demonstrates how to add the TinyORM build tree or installation prefix to the `CMAKE_PREFIX_PATH`. This is necessary for CMake to locate TinyORM's package configuration file when it's not exported to the User Package Registry. It provides examples for both PowerShell and Bash environments. ```cmake # build tree list(APPEND CMAKE_PREFIX_PATH "${convertToCmakeEnvVariable(pwsh, applicationFolderPath(pwsh))}/TinyORM/TinyORM-builds-cmake/build-debug") # installation folder - CMAKE_INSTALL_PREFIX list(APPEND CMAKE_PREFIX_PATH "${convertToCmakeEnvVariable(pwsh, rootFolderPath(pwsh))}/tmp/TinyORM") ``` ```cmake # build tree list(APPEND CMAKE_PREFIX_PATH "${convertToCmakeEnvVariable(bash, applicationFolderPath(bash))}/TinyORM/TinyORM-builds-cmake/build-debug") ``` -------------------------------- ### Manual TinyORM Library Linking (PowerShell) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx This example demonstrates manual linking against the TinyORM library using qmake in a PowerShell environment. It specifies the main directory, includes the TinyORM configuration, sets the build tree path, and appends the library path and name to LIBS. ```qmake # Link against TinyORM library # --- TINY_MAIN_DIR = $$clean_path() # Configure TinyORM library include($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri) # TinyORM library path TINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake) LIBS += $$quote(-L$$TINYORM_BUILD_TREE/build-TinyORM-Desktop_Qt_6_7_2_MSVC2019_64bit-Debug/src$${TINY_BUILD_SUBFOLDER}/) LIBS += -lTinyOrm ``` -------------------------------- ### Retrieve All Rows From A Table - C++ Source: https://github.com/silverqx/tinyorm/blob/main/docs/database/query-builder.mdx Demonstrates how to retrieve all rows from a specified table using TinyORM's query builder. It utilizes the `DB::table()` method to start a query and the `get()` method to execute it, returning a `QSqlQuery` object. The results can then be iterated using `QSqlQuery::next()` and accessed by column name using `QSqlQuery::value()`. ```cpp #include // Log a list of all of the application's users auto query = DB::table("users")->get(); while (query.next()) qDebug() << "id :" << query.value("id").toULongLong() << ";" << "name :" << query.value("name").toString(); ``` ```cpp #include #include auto users = DB::table("users")->get(); while(users.next()) qDebug() << users.value("name").toString(); ``` -------------------------------- ### Connect to MySQL with QSqlDatabase Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt This C++ code demonstrates how to establish a connection to a MySQL server using QSqlDatabase. It configures host, database name, credentials, port, and SSL options using environment variables before attempting to open the connection. ```cpp auto db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName(qEnvironmentVariable("DB_MYSQL_HOST")); db.setDatabaseName(qEnvironmentVariable("DB_MYSQL_DATABASE")); db.setUserName(qEnvironmentVariable("DB_MYSQL_USERNAME")); db.setPassword(qEnvironmentEnvironmentVariable("DB_MYSQL_PASSWORD")); db.setPort(qEnvironmentVariable("DB_MYSQL_PORT").toInt()); db.setConnectOptions(QStringLiteral("SSL_CERT=%1;SSL_KEY=%2;SSL_CA=%3;MYSQL_OPT_SSL_MODE=%4") .arg(qEnvironmentVariable("DB_MYSQL_SSL_CERT"), qEnvironmentVariable("DB_MYSQL_SSL_KEY"), qEnvironmentVariable("DB_MYSQL_SSL_CA"), qEnvironmentVariable("DB_MYSQL_SSL_MODE"))); auto ok = db.open(); if (ok) { qDebug() << "yes"; } else { qDebug() << "no"; } ``` -------------------------------- ### Avoiding .env Files with QMake Configuration Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx Explains how to avoid using `.env` files by moving `TINYORM_BUILD_TREE` to `.qmake.conf` or using partial guessing. It also suggests setting the `VCPKG_ROOT` environment variable at the system level for a cleaner setup. ```bash You can entirely avoid the `.env` files, just move the `TINYORM_BUILD_TREE` to the `.qmake.conf` or remove it by help of [Partial guessing of the `TINYORM_BUILD_TREE`](tinyorm.mdx#partial-guessing-of-the-tinyorm_build_tree) and set the `VCPKG_ROOT` environment variable at system level as is described in [`Set up vcpkg environment`](tinyorm.mdx#set-up-vcpkg-environment). ``` -------------------------------- ### Install TinyORM with QtSql and MySQL Support Source: https://github.com/silverqx/tinyorm/blob/main/cmake/vcpkg/README.md Installs TinyORM with QtSql support, specifically enabling the MySQL driver. This involves installing Qt base with SQL MySQL support and the MySQL connector. ```bash vcpkg install tinyorm[core] qtbase[core] --dry-run vcpkg install tinyorm[core,mysql] qtbase[core,sql-mysql] --dry-run ``` -------------------------------- ### Configure Compile Definitions for Tom Example Source: https://github.com/silverqx/tinyorm/blob/main/CMakeLists.txt Sets compile definitions for the 'tom example' functionality, including specifying directories for migrations, models, and seeders. It also defines a private macro to indicate that the tom example is being built. ```cmake if(TOM_EXAMPLE) target_compile_definitions(${TinyOrm_target} PUBLIC # Will be stringified in the tom/application.cpp TINYTOM_MIGRATIONS_DIR=${TOM_MIGRATIONS_DIR} # Will be stringified in the tom/application.cpp TINYTOM_MODELS_DIR=${TOM_MODELS_DIR} # Will be stringified in the tom/application.cpp TINYTOM_SEEDERS_DIR=${TOM_SEEDERS_DIR} PRIVATE # For the tom about command TINYORM_TOM_EXAMPLE ) endif() ``` -------------------------------- ### Configure HelloWorld.pro for qmake Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx Defines the qmake project file for the 'Hello World' application. It specifies build template, configuration, defines, source files, and includes the TinyORM library. ```qmake QT -= gui TEMPLATE = app CONFIG *= cmdline DEFINES *= PROJECT_TINYORM_HELLOWORLD SOURCES += $$PWD/main.cpp # Auto-configure TinyORM library 🔥 include($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri) ``` -------------------------------- ### Sample Output from HelloWorld Application Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx This is the expected output when the HelloWorld application is successfully executed after building and linking with TinyORM. It shows a sample SQL query and its results. ```less Executed prepared query (6ms, -1 results, 0 affected, tinyorm_default) : select * from posts 1 "First Post" 2 "Second Post" ``` -------------------------------- ### CMakeLists.txt for TinyORM Project Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx This CMakeLists.txt file configures a C++ project to use TinyORM and Qt. It specifies the minimum CMake version, project name, C++ standard, and required Qt components. It also finds the TinyOrm package and links the necessary libraries (Qt::Core and TinyOrm::TinyOrm) to the executable. This configuration is essential for building the TinyORM 'Hello World' example. ```cmake cmake_minimum_required(VERSION VERSION 3.22...3.30 FATAL_ERROR) project(HelloWorld LANGUAGES CXX) # build tree list(APPEND CMAKE_PREFIX_PATH "${convertToCmakeEnvVariable(pwsh, applicationFolderPath(pwsh))}/TinyORM/TinyORM-builds-cmake/build-debug") set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) add_executable(HelloWorld main.cpp ) find_package(QT NAMES Qt6 COMPONENTS Core REQUIRED) find_package(Qt\${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) find_package(TinyOrm 0.38.1 CONFIG REQUIRED) target_link_libraries(HelloWorld PRIVATE Qt\${QT_VERSION_MAJOR}::Core TinyOrm::TinyOrm ) ``` ```cmake cmake_minimum_required(VERSION VERSION 3.22...3.30 FATAL_ERROR) project(HelloWorld LANGUAGES CXX) # build tree list(APPEND CMAKE_PREFIX_PATH "${convertToCmakeEnvVariable(bash, applicationFolderPath(bash))}/TinyORM/TinyORM-builds-cmake/build-debug") set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) add_executable(HelloWorld main.cpp ) find_package(QT NAMES Qt6 COMPONENTS Core REQUIRED) find_package(Qt\${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) find_package(TinyOrm 0.38.1 CONFIG REQUIRED) target_link_libraries(HelloWorld PRIVATE Qt\${QT_VERSION_MAJOR}::Core TinyOrm::TinyOrm ) ``` -------------------------------- ### C++ Hello World Source Code Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx The main C++ source file for the 'Hello world' example. It includes necessary headers for Qt Core Application and Debug output, with a preprocessor directive for Windows. ```cpp #include #include #ifdef _WIN32 ``` -------------------------------- ### Install TinyORM with QtSql and SQLite Support Source: https://github.com/silverqx/tinyorm/blob/main/cmake/vcpkg/README.md Installs TinyORM with QtSql support, enabling the SQLite driver. This command includes Qt base with SQL SQLite support. ```bash vcpkg install tinyorm[core,sqlite] qtbase[core,sql-sqlite] --dry-run ``` -------------------------------- ### Initialize Project Version and Basic Project Setup (CMake) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/migrations.mdx Reads the project version from a header file using a custom CMake module 'TinyHelpers'. It then initializes the main project with a description, homepage URL, supported language (CXX), and the determined version. This ensures the project is properly identified and versioned within the build system. ```cmake include(TinyHelpers) tiny_read_version(TINY_VERSION TINY_VERSION_MAJOR TINY_VERSION_MINOR TINY_VERSION_PATCH TINY_VERSION_TWEAK VERSION_HEADER "${TinyOrmSourceDir}/tom/include/tom/version.hpp" PREFIX TINYTOM HEADER_FOR "${Tom_ns}" ) project(${Tom_ns} DESCRIPTION "Tom console application for TinyORM C++ library" HOMEPAGE_URL "https://www.tinyorm.org" LANGUAGES CXX VERSION ${TINY_VERSION} ) ``` -------------------------------- ### TinyDrivers Operator Overload Output Examples Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt Example output strings demonstrating the overloaded operator<<() for various TinyDrivers classes, including SqlDatabase, SqlRecord, and SqlField. This shows how object data is represented as strings. ```text SqlDatabase(driver="QMYSQL", database="tinyorm_test_1", host="mysql.test", port=3306, user="szachara", open=true", options="SSL_CERT=C:/mysql/mysql_9.0/data/client-cert.pem;SSL_CA=C:/mysql/mysql_9.0/data/ca.pem;SSL_KEY=C:/mysql/mysql_9.0/data/client-key.pem") -- SqlRecord(7) 0: SqlField(name: "id", type: qulonglong, value: "1", isNull: false, isValid: true, length: 20, precision: 0, required: true, sqlType: 8, sqlTypeName: BIGINT, autoIncrement: true, tableName: "users") ``` -------------------------------- ### Configure Database Connections in C++ Source: https://context7.com/silverqx/tinyorm/llms.txt Demonstrates how to configure database connections for MySQL, PostgreSQL, and SQLite using the `DB::create` method with `QVariantHash`. Connections are lazily established upon first use. ```cpp #include using Orm::DB; // MySQL connection configuration auto manager = DB::create({ {"driver", "QMYSQL"}, {"host", qEnvironmentVariable("DB_HOST", "127.0.0.1")}, {"port", qEnvironmentVariable("DB_PORT", "3306")}, {"database", qEnvironmentVariable("DB_DATABASE", "")}, {"username", qEnvironmentVariable("DB_USERNAME", "root")}, {"password", qEnvironmentVariable("DB_PASSWORD", "")}, {"charset", "utf8mb4"}, {"collation", "utf8mb4_0900_ai_ci"}, {"timezone", "+00:00"}, {"qt_timezone", QVariant::fromValue(QTimeZone::UTC)}, {"prefix", ""}, {"strict", true}, {"engine", "InnoDB"}, }); // PostgreSQL connection auto pgManager = DB::create({ {"driver", "QPSQL"}, {"host", "127.0.0.1"}, {"port", "5432"}, {"database", "myapp"}, {"search_path", "public"}, {"username", "postgres"}, {"password", "secret"}, {"charset", "utf8"}, {"timezone", "UTC"}, {"qt_timezone", QVariant::fromValue(QTimeZone::UTC)}, }); // SQLite connection auto sqliteManager = DB::create({ {"driver", "QSQLITE"}, {"database", "/path/to/database.sqlite3"}, {"foreign_key_constraints", "true"}, {"check_database_exists", true}, {"qt_timezone", QVariant::fromValue(QTimeZone::UTC)}, {"return_qdatetime", true}, }); ``` -------------------------------- ### Dependent Feature Option (TOM Example) Source: https://github.com/silverqx/tinyorm/blob/main/CMakeLists.txt Defines a CMake feature option 'TOM_EXAMPLE' that is dependent on the 'TOM' build option. It controls whether the Tom command-line application example is built. ```cmake # Depends on the TOM build option feature_option_dependent(TOM_EXAMPLE "Build the Tom command-line application example" OFF "TOM" TOM_EXAMPLE-NOTFOUND ) ``` -------------------------------- ### Environment Variable Configuration for TinyORM Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx Demonstrates setting environment variables for TinyORM build paths. It highlights the use of `TINYORM_BUILD_TREE` and `TINY_VCPKG_ROOT`, suggesting customization based on project structure. It also mentions an alternative for partial guessing of `TINYORM_BUILD_TREE` by uncommenting a specific line. ```bash # Don't forget to update the `TINYORM_BUILD_TREE` and `TINY_VCPKG_ROOT` folder paths to your needs if you are not using the recommended [`Folders structure`](tinyorm.mdx#folders-structure). # You can use the [Partial guessing of the `TINYORM_BUILD_TREE`](tinyorm.mdx#partial-guessing-of-the-tinyorm_build_tree) if you don't like to specify it manually. Just comment out the `TINYORM_BUILD_TREE` and uncomment the `TINY_BUILD_TREE = $$shadowed($$PWD)` in the `.qmake.conf` file. ``` -------------------------------- ### C++ Main Application Setup with TinyORM Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/migrations.mdx Sets up the main C++ application using TinyORM. It initializes the database manager, registers migrations and seeders, and runs the application. Includes exception handling for logging. ```cpp #include #include #include "migrations/2014_10_12_000000_create_posts_table.hpp" #include "seeders/databaseseeder.hpp" using Orm::DatabaseManager; using Orm::DB; using TomApplication = Tom::Application; using namespace Migrations; // NOLINT(google-build-using-namespace) using namespace Seeders; // NOLINT(google-build-using-namespace) /*! Create the database manager instance and add a database connection. */ std::shared_ptr setupDatabaseManager(); /*! C++ main function. */ int main(int argc, char *argv[]) { try { // Ownership of the shared_ptr() auto db = setupDatabaseManager(); return TomApplication(argc, argv, std::move(db), "TOM_EXAMPLE_ENV") .migrations() .seeders() // Fire it up 🔥🚀✨ .run(); } catch (const std::exception &e) { TomApplication::logException(e); } return EXIT_FAILURE; } std::shared_ptr setupDatabaseManager() { using namespace Orm::Constants; // NOLINT(google-build-using-namespace) // Ownership of the shared_ptr() return DB::create({ {driver_, QMYSQL}, {host_, qEnvironmentVariable("DB_MYSQL_HOST", H127001)}, {port_, qEnvironmentVariable("DB_MYSQL_PORT", P3306)}, {database_, qEnvironmentVariable("DB_MYSQL_DATABASE", EMPTY)}, {username_, qEnvironmentVariable("DB_MYSQL_USERNAME", EMPTY)}, {password_, qEnvironmentVariable("DB_MYSQL_PASSWORD", EMPTY)}, {charset_, qEnvironmentVariable("DB_MYSQL_CHARSET", UTF8MB4)}, {collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)}, {timezone_, TZ00}, /* Specifies what time zone all QDateTime-s will have, the overridden default is the QTimeZone::UTC, set to the QTimeZone::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ {qt_timezone, QVariant::fromValue(QTimeZone::UTC)}, {strict_, true}, }, QStringLiteral("tinyorm_tom_mysql")); // shell:connection } ``` -------------------------------- ### Link Project Dependencies Source: https://github.com/silverqx/tinyorm/blob/main/examples/tom/CMakeLists.txt Links the necessary TinyORM libraries to the Tom example executable. It includes a conditional link to 'CommonConfig_target' if 'STRICT_MODE' is not enabled, and always links to the main 'TinyOrm_target'. ```cmake if(NOT STRICT_MODE) target_link_libraries(${TomExample_target} PRIVATE ${TinyOrm_ns}::${CommonConfig_target} ) endif() target_link_libraries(${TomExample_target} PRIVATE ${TinyOrm_ns}::${TinyOrm_target}) ``` -------------------------------- ### Configure .qmake.conf for TinyORM paths Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx Sets up the .qmake.conf file to define paths for the TinyORM library, including its source directory, dotenv root, and qmake features. This is crucial for correct library integration. ```qmake # Path to the PARENT folder of the TinyORM source folder TINY_MAIN_DIR = $$clean_path($$PWD/../../TinyORM/) # To find .env and .env.$$QMAKE_PLATFORM files TINY_DOTENV_ROOT = $$PWD # Path to the current build tree (used to guess the TinyORM build tree) #TINY_BUILD_TREE = $$shadowed($$PWD) # To find .prf files, needed by eg. CONFIG += tiny_system_headers inline/extern_constants QMAKEFEATURES *= $$quote($$TINY_MAIN_DIR/TinyORM/qmake/features) ``` -------------------------------- ### Set CMAKE_INSTALL_PREFIX for TinyORM Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Configures the CMake installation prefix to include a specific path for TinyORM. This ensures that when TinyORM is installed, it is placed in the expected directory, making it easier to locate during subsequent build or runtime configurations. ```cmake list(APPEND CMAKE_PREFIX_PATH "${convertToCmakeEnvVariable(bash, rootFolderPath(bash))}/tmp/TinyORM") ``` -------------------------------- ### Install TinyORM with MySQL Driver (TinyDrivers) Source: https://github.com/silverqx/tinyorm/blob/main/cmake/vcpkg/README.md Installs TinyORM with the MySQL database driver using TinyDrivers, bypassing the QtSql dependency. This command includes the build-mysql-driver feature and specifies Qt base and MySQL libraries. ```bash vcpkg install tinyorm[core,build-mysql-driver] qtbase[core] libmysql --dry-run vcpkg install tinyorm[core,build-mysql-driver,tom-example] ``` -------------------------------- ### QMake Configuration for TinyORM Build Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx This snippet shows how to configure QMake for building the TinyORM project. It includes directives for linker flags and environment variable settings for build paths. Note that `use_lld_linker` might not work with MinGW. ```qmake # CONFIG *= use_lld_linker does not work on MinGW #QMAKE_LFLAGS *= -fuse-ld=lld ``` -------------------------------- ### Preparing Prepared Queries - SqlQuery::prepare() Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt This snippet covers the preparation phase for prepared SQL queries. It involves initializing a statement handle, preparing the statement with the SQL query, and determining the number of parameters. It also sets up metadata for output bindings. ```cpp d->stmt = mysql_stmt_init(mysql); r = mysql_stmt_prepare(d->stmt); paramCount = mysql_stmt_param_count(d->stmt); d->outBinds = new MYSQL_BIND[paramCount](); bindInValues(); meta = mysql_stmt_result_metadata(stmt); fields.resize(mysql_num_fields(meta)); // Zero memory inBinds = new MYSQL_BIND[fields.size()]; ``` -------------------------------- ### Linux: Installing New Clang Version (Clang 18) Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt These commands illustrate how to install a newer version of Clang (Clang 18) on a Debian-based Linux system. It involves adding the LLVM GPG key and configuring the APT repository for the specific Clang version. ```bash wget -O- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/llvm-18.asc sudo add-apt-repository --yes --sourceslist 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' ``` -------------------------------- ### Build Clazy Standalone (Linux CMake) Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt Configures and builds Clazy standalone on Linux using CMake. It specifies the source and build directories, generator, C++ compiler launcher, build type, and installation prefix. It's crucial to install to '/usr' for clazy-standalone to function correctly. ```powershell cmake --log-level=DEBUG --log-context \ -S ~/Code/c/clazy/clazy \ -B ~/Code/c/clazy/clazy-builds/Release \ -G Ninja \ -D CMAKE_INSTALL_PREFIX:PATH=/usr \ -D CMAKE_CXX_COMPILER_LAUNCHER:FILEPATH=ccache \ -D CMAKE_BUILD_TYPE:STRING=Release \ -D CMAKE_CXX_SCAN_FOR_MODULES:BOOL=OFF sudo cmake --install . sudo cmake --install . --prefix /usr ``` -------------------------------- ### CMake FetchContent for TinyORM Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx This CMake code snippet demonstrates how to use the `FetchContent` module to automatically download and build the TinyORM library. It replaces the manual path configuration with a more convenient method for managing dependencies. This is useful for quickly setting up a project without needing to pre-build TinyORM separately. ```cmake cmake_minimum_required(VERSION VERSION 3.22...3.30 FATAL_ERROR) project(HelloWorld LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # build tree list(APPEND CMAKE_PREFIX_PATH "${convertToCmakeEnvVariable(pwsh, applicationFolderPath(pwsh))}/TinyORM/TinyORM-builds-cmake/build-debug") ``` ```cmake cmake_minimum_required(VERSION VERSION 3.22...3.30 FATAL_ERROR) project(HelloWorld LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # build tree list(APPEND CMAKE_PREFIX_PATH "${convertToCmakeEnvVariable(bash, applicationFolderPath(bash))}/TinyORM/TinyORM-builds-cmake/build-debug") ``` -------------------------------- ### Clone TinyORM Repository with qmake Setup Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Clones the TinyORM project repository and creates the necessary build directory structure for qmake. This is the initial step for building TinyORM using the qmake build system, preparing the project for subsequent configuration and compilation. ```powershell cd ${rootFolderPath(pwsh)} mkdir ${applicationFolder()}/TinyORM/TinyORM-builds-qmake cd ${applicationFolder()}/TinyORM git clone git@github.com:silverqx/TinyORM.git ``` -------------------------------- ### Tom Command Autocompletion (Argument) Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt Provides an example of how to use the 'tom complete' command for autocompleting arguments. This is useful for interactive command-line usage and debugging. ```powershell tom complete --word="mi" --commandline="tom mi" --position=6 ``` -------------------------------- ### Create Project Directory Structure (Bash) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/hello-world.mdx Creates the necessary directories for the 'HelloWorld' project using bash commands. This is a prerequisite for setting up the project files. ```bash cd /path/to/your/application/folder mkdir -p HelloWorld/HelloWorld cd HelloWorld ``` -------------------------------- ### Execute General SQL Statement (C++) Source: https://github.com/silverqx/tinyorm/blob/main/docs/database/getting-started.mdx Provides an example of executing a general SQL statement (like DDL) that does not return results using the DB::statement method. ```cpp DB::statement("drop table users"); ``` -------------------------------- ### Clone TinyORM Repository with qmake Setup (Bash) Source: https://github.com/silverqx/tinyorm/blob/main/docs/building/tinyorm.mdx Clones the TinyORM project repository and creates the necessary build directory structure for qmake using bash commands. This sets up the project for building with qmake, including creating directories and fetching the source code. ```bash cd ${rootFolderPath(bash)} mkdir -p ${applicationFolder()}/TinyORM/TinyORM-builds-qmake cd ${applicationFolder()}/TinyORM git clone git@github.com:silverqx/TinyORM.git ``` -------------------------------- ### Upgrade Laravel Project Steps Source: https://github.com/silverqx/tinyorm/blob/main/NOTES.txt A sequence of shell commands and manual steps to upgrade a Laravel project, including dependency management, package installation, configuration merging, and database migration. ```bash # Upgrade Laravel main version: composer selfup composer global outd -D composer global up laravel new laravel-10 cd .\laravel-10\ npm install composer require laravel/breeze --dev art breeze:install composer require --dev barryvdh/laravel-ide-helper npm install # ... (further steps involving file merging, database operations, and configuration) ```