diff --git a/assets/js/0ab078a9.f49a1d60.js b/assets/js/0ab078a9.76f73491.js
similarity index 84%
rename from assets/js/0ab078a9.f49a1d60.js
rename to assets/js/0ab078a9.76f73491.js
index 8242e735f..3bdebebf2 100644
--- a/assets/js/0ab078a9.f49a1d60.js
+++ b/assets/js/0ab078a9.76f73491.js
@@ -1 +1 @@
-"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[395],{993:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>O,contentTitle:()=>_,default:()=>I,frontMatter:()=>T,metadata:()=>v,toc:()=>R});var s=i(4848),d=i(8453),r=i(8774),l=i(6684),c=i(2364),t=i(9365),o=i(1470),a=i(5556),h=i.n(a),x=i(6694);function j(e){let{groupId:n}=e;return(0,s.jsx)("span",{children:(0,x.OZ)(n)})}j.propTypes={groupId:h().string.isRequired};const u=j;var p=i(4164),m=i(6362);const b={rootFolderInput:"rootFolderInput_ottS",input:"input_OR7e",application:"application_fjej"};function f(e){let{groupId:n,label:i}=e;const{rootFolder:d,setRootFolder:r}=(0,m.A)(),l=(0,x.T3)(n),c=l?"application":"root",t=l?"\nThis folder name is common for all shells (eg. pwsh, bash, ...)":"";return(0,s.jsx)("form",{name:"tinyorm-root-folder-form",className:(0,p.A)(b.rootFolderInput,b[n],n),onSubmit:e=>{e.preventDefault(),e.stopPropagation()},children:(0,s.jsx)("input",{name:"tinyorm-root-folder-input",className:(0,p.A)(b.input,b[n],n),placeholder:`Enter ${c} folder...`,title:`This ${c} folder will be used in all ${i} examples at tinyorm.org${t}`,onChange:e=>{r(n,e.target.value)},value:d[n]??(0,x.bw)(n)})})}f.propTypes={groupId:h().string.isRequired,label:h().string.isRequired};const g=f;var y=i(7324);const T={sidebar_position:0,sidebar_label:"TinyORM",hide_table_of_contents:!0,description:"How to compile the TinyORM C++ library on Windows and Linux.",keywords:["c++ orm","building","tinyorm"]},_="Building: TinyORM",v={id:"building/tinyorm",title:"Building: TinyORM",description:"How to compile the TinyORM C++ library on Windows and Linux.",source:"@site/docs/building/tinyorm.mdx",sourceDirName:"building",slug:"/building/tinyorm",permalink:"/building/tinyorm",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"TinyORM",hide_table_of_contents:!0,description:"How to compile the TinyORM C++ library on Windows and Linux.",keywords:["c++ orm","building","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Getting Started",permalink:"/tinydrivers/getting-started"},next:{title:"Hello world",permalink:"/building/hello-world"}},O={},R=[{value:"Introduction",id:"introduction",level:2},{value:"Common Prerequisites",id:"common-prerequisites",level:4},{value:"Windows Prerequisites",id:"windows-prerequisites",level:4},{value:"Build environment scripts",id:"build-environment-scripts",level:5},{value:"Allow symbolic links unprivileged",id:"allow-symbolic-links-unprivileged",level:5},{value:"Folders structure",id:"folders-structure",level:2},{value:"Getting started",id:"getting-started",level:2},{value:"vcpkg",id:"vcpkg",level:2},{value:"Set up vcpkg environment",id:"set-up-vcpkg-environment",level:4},{value:"C preprocessor macros",id:"c-preprocessor-macros",level:2},{value:"Building with CMake",id:"building-with-cmake",level:2},{value:"Configure & Build (cmake)",id:"configure-and-build-cmake",level:3},{value:"CMake STRICT_MODE option",id:"cmake-strict_mode-option",level:5},{value:"Build TinyORM",id:"build-tinyorm",level:4},{value:"CMake build options",id:"cmake-build-options",level:3},{value:"Consume TinyOrm library (cmake)",id:"consume-tinyorm-library-cmake",level:3},{value:"Building with qmake",id:"building-with-qmake",level:2},{value:"Install dependencies",id:"install-dependencies",level:3},{value:"Configure & Build (qmake)",id:"configure-and-build-qmake",level:3},{value:"Open QtCreator IDE",id:"open-qtcreator-ide",level:4},{value:"Configure TinyORM",id:"configure-tinyorm",level:4},{value:"Auto-configuration and tiny_dotenv",id:"auto-configuration-and-tiny_dotenv",level:5},{value:"Manual configuration (conf.pri)",id:"manual-configuration-confpri",level:5},{value:"Opening TinyORM.pro (main project file)",id:"opening-tinyormpro-main-project-file",level:5},{value:"Build TinyORM",id:"build-tinyorm-1",level:4},{value:"qmake build options",id:"qmake-build-options",level:3},{value:"Consume TinyOrm library (qmake)",id:"consume-tinyorm-library-qmake",level:3},{value:"Requirements",id:"requirements",level:4},{value:"QMAKEFEATURES",id:"qmakefeatures",level:5},{value:"Variables affecting TinyOrm.pri",id:"variables-affecting-tinyormpri",level:5},{value:"Manual configuration examples",id:"manual-configuration-examples",level:5},{value:"Auto-configuration internals",id:"auto-configuration-internals",level:3},{value:"Environment files",id:"environment-files",level:4},{value:"Partial guessing of the TINYORM_BUILD_TREE",id:"partial-guessing-of-the-tinyorm_build_tree",level:4},{value:"Manual configuration internals",id:"manual-configuration-internals",level:3},{value:"Ccache support",id:"ccache-support",level:2}];function M(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,d.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h1,{id:"building-tinyorm",children:"Building: TinyORM"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"#introduction",children:"Introduction"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#common-prerequisites",children:"Common Prerequisites"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#windows-prerequisites",children:"Windows Prerequisites"})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#folders-structure",children:"Folders structure"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#getting-started",children:"Getting started"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#vcpkg",children:"vcpkg"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#c-preprocessor-macros",children:"C preprocessor macros"})}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"#building-with-cmake",children:"Building with CMake"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#configure-and-build-cmake",children:"Configure & Build"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#cmake-build-options",children:"CMake build options"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#consume-tinyorm-library-cmake",children:"Consume TinyOrm library"})}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"#building-with-qmake",children:"Building with qmake"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#install-dependencies",children:"Install dependencies"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#configure-and-build-qmake",children:"Configure & Build"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#qmake-build-options",children:"qmake build options"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#consume-tinyorm-library-qmake",children:"Consume TinyOrm library"})}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"#auto-configuration-internals",children:"Auto-configuration internals"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#environment-files",children:"Environment files"})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#manual-configuration-internals",children:"Manual configuration internals"})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#ccache-support",children:"Ccache support"})}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsxs)(n.p,{children:["The build systems supported out of the box are ",(0,s.jsx)(n.code,{children:"CMake"})," and ",(0,s.jsx)(n.code,{children:"qmake"}),"."]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["All examples below assume that ",(0,s.jsx)(n.code,{children:"pwsh"})," runs on ",(0,s.jsx)(n.code,{children:"Windows"})," and ",(0,s.jsx)(n.code,{children:"bash"})," runs on ",(0,s.jsx)(n.code,{children:"Linux"}),"."]})}),"\n",(0,s.jsx)(n.h4,{id:"common-prerequisites",children:"Common Prerequisites"}),"\n",(0,s.jsxs)(n.p,{children:["Install the required ",(0,s.jsx)(n.a,{href:"/dependencies",children:"dependencies"})," before starting."]}),"\n",(0,s.jsx)(n.admonition,{type:"warning",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"QSqlDatabase"})," depends on ",(0,s.jsx)(n.code,{children:"QCoreApplication"})," from ",(0,s.jsx)(n.code,{children:"Qt v6.5.3"})," so you must create the ",(0,s.jsx)(n.code,{children:"QCoreApplication"})," instance before you will call anything from the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. \ud83e\udee4 The change was made ",(0,s.jsx)(n.a,{href:"https://github.com/qt/qtbase/commit/8d2bdc9cd5482eace12ba7e45304857bd24db0e6#diff-1d355c25c0b0eddec2be48253407780c4dc510d986739aec61e1ec892ccaf86e",children:"here"}),"."]})}),"\n",(0,s.jsx)(n.h4,{id:"windows-prerequisites",children:"Windows Prerequisites"}),"\n",(0,s.jsx)(n.h5,{id:"build-environment-scripts",children:"Build environment scripts"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Visual Studio"})," does not provide ",(0,s.jsx)(n.code,{children:"vcvars"})," scripts for ",(0,s.jsx)(n.code,{children:"pwsh"}),", you can use ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/tree/main/tools/vcvars64.ps1",children:(0,s.jsx)(n.code,{children:"vcvars64.ps1"})})," provided by ",(0,s.jsx)(n.code,{children:"TinyORM"})," in the ",(0,s.jsx)(n.code,{children:"tools/"})," folder. Place them on the ",(0,s.jsx)(n.code,{children:"$env:Path"})," user/system path and they will be available system-wide."]}),"\n",(0,s.jsxs)(n.p,{children:["The same is true for the ",(0,s.jsx)(n.code,{children:"Qt Framework"}),", it doesn't provide ",(0,s.jsx)(n.code,{children:"qtenv"})," scripts for ",(0,s.jsx)(n.code,{children:"pwsh"})," too. You can create your own script, place it on the ",(0,s.jsx)(n.code,{children:"$env:Path"})," user/system path and it will be available system-wide."]}),"\n",(0,s.jsxs)(n.p,{children:["Here is one simple example for ",(0,s.jsx)(n.code,{children:"pwsh"}),"."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:"qtenv6.ps1",label:"qtenv6.ps1",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"#!/usr/bin/env pwsh\n\nSet-StrictMode -Version 3.0\n\nWrite-Host 'Setting up environment for Qt 6.7.0 usage...' -ForegroundColor Magenta\nWrite-Host\n\n$Script:QtRoot = $env:TINY_QT_ROOT ?? 'C:\\Qt'\n\n$env:Path = \"$Script:QtRoot\\6.7.0\\msvc2019_64\\bin;\" + $env:Path\n\n. vcvars64.ps1\n"})})}),(0,s.jsx)(t.A,{value:"qtenv5.ps1",label:"qtenv5.ps1",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"#!/usr/bin/env pwsh\n\nSet-StrictMode -Version 3.0\n\nWrite-Host 'Setting up environment for Qt 5.15.2 usage...' -ForegroundColor Magenta\nWrite-Host\n\n$Script:QtRoot = $env:TINY_QT_ROOT ?? 'C:\\Qt'\n\n$env:Path = \"$Script:QtRoot\\5.15.2\\msvc2019_64\\bin;\" + $env:Path\n\n. vcvars64.ps1\n"})})})]}),"\n",(0,s.jsxs)(n.p,{children:["And here for ",(0,s.jsx)(n.code,{children:"Linux"}),"."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:"qtenv6",label:"qtenv6",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:'echo \'Setting up environment for Qt 6.7.0 usage...\'\n\nQtRoot="${TINY_QT_ROOT:-/opt/Qt}"\n\nexport PATH="$QtRoot/6.7.0/gcc_64/bin"${PATH:+:}$PATH\nexport LD_LIBRARY_PATH="$QtRoot/6.7.0/gcc_64/lib"${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH\n'})})}),(0,s.jsx)(t.A,{value:"qtenv5",label:"qtenv5",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:'echo \'Setting up environment for Qt 5.15.2 usage...\'\n\nQtRoot="${TINY_QT_ROOT:-/opt/Qt}"\n\nexport PATH="$QtRoot/5.15.2/gcc_64/bin"${PATH:+:}$PATH\nexport LD_LIBRARY_PATH="$QtRoot/5.15.2/gcc_64/lib"${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH\n'})})})]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["These scripts consider the ",(0,s.jsx)(n.code,{children:"TINY_QT_ROOT"})," environment variable that should point to the ",(0,s.jsx)(n.code,{children:"Qt"})," installation folder, you can define this environment variable globally in your OS."]})}),"\n",(0,s.jsx)(n.h5,{id:"allow-symbolic-links-unprivileged",children:"Allow symbolic links unprivileged"}),"\n",(0,s.jsxs)(n.p,{children:["Open ",(0,s.jsx)(n.code,{children:"Local Security Policy"}),", go to ",(0,s.jsx)(n.code,{children:"Local Policies - User Rights Assignment"}),", open ",(0,s.jsx)(n.code,{children:"Create symbolic links"})," and add your user account or user group, restart when it doesn't apply immediately."]}),"\n",(0,s.jsx)(n.h2,{id:"folders-structure",children:"Folders structure"}),"\n",(0,s.jsxs)(n.p,{children:["All ",(0,s.jsx)(n.code,{children:"tinyorm.org"})," examples are based on the following folders structure. The ",(0,s.jsx)(n.code,{children:"tom"})," folder will contain a ",(0,s.jsx)(n.a,{href:"/building/migrations",children:"migrations console application"}),"."]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can set the root and application folder paths in the form below and they will be used across the whole ",(0,s.jsx)(n.a,{href:"http://www.tinyorm.org",children:"www.tinyorm.org"})," website. \ud83e\udd73 The pwsh shell is supposed to use on Windows and the bash shell on Linux, but it is not a requirement."]})}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsxs)(t.A,{value:y.b,label:y.ux,className:"tiny-tree",children:[(0,s.jsx)("div",{className:"tiny-root-folder-info-wrapper",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)("span",{className:"tiny-root-folder-info-prefix",children:"Current pwsh path"}),"\xa0",(0,s.jsx)(u,{groupId:y.b})]})}),(0,s.jsx)(g,{groupId:y.b,label:y.ux}),(0,s.jsx)(g,{groupId:y.pW,label:y.kl}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-text",children:"\n\n\n\u251c\u2500\u2500\n\u2502 \u251c\u2500\u2500 HelloWorld/\n\u2502 | \u251c\u2500\u2500 HelloWorld/\n\u2502 | \u251c\u2500\u2500 HelloWorld-builds-cmake/\n\u2502 | | \u2514\u2500\u2500 build-debug/\n\u2502 | \u2514\u2500\u2500 HelloWorld-builds-qmake/\n\u2502 | \u2514\u2500\u2500 build-debug/\n\u2502 \u251c\u2500\u2500 TinyORM/\n\u2502 | \u251c\u2500\u2500 TinyORM/\n\u2502 | \u251c\u2500\u2500 TinyORM-builds-cmake/\n\u2502 | \u2502 \u251c\u2500\u2500 build-gcc-debug/\n\u2502 | \u2502 \u251c\u2500\u2500 build-gcc-release/\n\u2502 | \u2502 \u2514\u2500\u2500 build-clang-debug/\n\u2502 | \u2514\u2500\u2500 TinyORM-builds-qmake/\n\u2502 | \u251c\u2500\u2500 build-debug/\n\u2502 | \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/\n\u2502 | \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_2_MSYS2_UCRT64_64bit-Release/\n\u2502 \u2514\u2500\u2500 tom/\n\u2502 \u251c\u2500\u2500 tom/\n\u2502 \u2502 \u2514\u2500\u2500 database/\n\u2502 \u2502 \u251c\u2500\u2500 migrations/\n\u2502 \u2502 \u251c\u2500\u2500 seeders/\n\u2502 \u2502 \u251c\u2500\u2500 migrations.pri\n\u2502 \u2502 \u2514\u2500\u2500 seeders.pri\n\u2502 \u251c\u2500\u2500 tom-builds-cmake/\n\u2502 \u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_MSVC2019_64bit-Debug/\n\u2502 \u2514\u2500\u2500 tom-builds-qmake/\n\u2502 \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_3_MSYS2_UCRT64_64bit-Release/\n\u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_MSVC2019_64bit-Debug/\n\u251c\u2500\u2500 tmp/\n\u2514\u2500\u2500 vcpkg/\n"})})]}),(0,s.jsxs)(t.A,{value:y.xj,label:y.gg,className:"tiny-tree",children:[(0,s.jsx)("div",{className:"tiny-root-folder-info-wrapper",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)("span",{className:"tiny-root-folder-info-prefix",children:"Current bash path"}),"\xa0",(0,s.jsx)(u,{groupId:y.xj})]})}),(0,s.jsx)(g,{groupId:y.xj,label:y.gg}),(0,s.jsx)(g,{groupId:y.pW,label:y.pW}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-text",children:"\n\n\n\u251c\u2500\u2500\n\u2502 \u251c\u2500\u2500 HelloWorld/\n\u2502 | \u251c\u2500\u2500 HelloWorld/\n\u2502 | \u251c\u2500\u2500 HelloWorld-builds-cmake/\n\u2502 | | \u2514\u2500\u2500 build-debug/\n\u2502 | \u2514\u2500\u2500 HelloWorld-builds-qmake/\n\u2502 | \u2514\u2500\u2500 build-debug/\n\u2502 \u251c\u2500\u2500 TinyORM/\n\u2502 | \u251c\u2500\u2500 TinyORM/\n\u2502 | \u251c\u2500\u2500 TinyORM-builds-cmake/\n\u2502 | \u2502 \u251c\u2500\u2500 build-gcc-debug/\n\u2502 | \u2502 \u251c\u2500\u2500 build-gcc-release/\n\u2502 | \u2502 \u2514\u2500\u2500 build-clang-debug/\n\u2502 | \u2514\u2500\u2500 TinyORM-builds-qmake/\n\u2502 | \u251c\u2500\u2500 build-debug/\n\u2502 | \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_2_GCC_64bit-Debug/\n\u2502 | \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_2_clang13_64bit_ccache-Release/\n\u2502 \u2514\u2500\u2500 tom/\n\u2502 \u251c\u2500\u2500 tom/\n\u2502 \u2502 \u2514\u2500\u2500 database/\n\u2502 \u2502 \u251c\u2500\u2500 migrations/\n\u2502 \u2502 \u251c\u2500\u2500 seeders/\n\u2502 \u2502 \u251c\u2500\u2500 migrations.pri\n\u2502 \u2502 \u2514\u2500\u2500 seeders.pri\n\u2502 \u251c\u2500\u2500 tom-builds-cmake/\n\u2502 \u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_clang14_64bit_ccache-Debug/\n\u2502 \u2514\u2500\u2500 tom-builds-qmake/\n\u2502 \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_GCC_64bit-Debug/\n\u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_clang14_64bit_ccache-Release/\n\u251c\u2500\u2500 tmp/\n\u2514\u2500\u2500 vcpkg/\n"})})]})]}),"\n",(0,s.jsx)(n.admonition,{type:"danger",children:(0,s.jsxs)(n.p,{children:["Avoid paths with spaces with the ",(0,s.jsx)(n.code,{children:"qmake"})," build system, it will not compile."]})}),"\n",(0,s.jsx)(r.A,{id:"qtcreator-default-build-directory"}),"\n",(0,s.jsxs)(n.admonition,{type:"tip",children:[(0,s.jsxs)(n.p,{children:["You can force the ",(0,s.jsx)(n.code,{children:"QtCreator"})," to generate a build folders structure as is described above."]}),(0,s.jsxs)(n.p,{children:["To generate the required folders structure set the ",(0,s.jsx)(n.code,{children:"Settings"})," - ",(0,s.jsx)(n.code,{children:"Build & Run"})," - ",(0,s.jsx)(n.code,{children:"Default Build Properties"})," - ",(0,s.jsx)(n.code,{children:"Default build directory"})," to:",(0,s.jsx)("br",{}),"\n",(0,s.jsx)(n.code,{children:'../%{Project:Name}-builds-%{BuildSystem:Name}/%{JS: Util.asciify("build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name}")}'})]})]}),"\n",(0,s.jsx)(n.h2,{id:"getting-started",children:"Getting started"}),"\n",(0,s.jsxs)(n.p,{children:["Prepare compilation environment, we need to put the Qt Framework and Visual Studio MSVC compiler on the path on Windows. The compiler is already on the path on Linux and you can export ",(0,s.jsx)(n.code,{children:"PATH"})," and ",(0,s.jsx)(n.code,{children:"LD_LIBRARY_PATH"})," for Qt Framework, or use our ",(0,s.jsx)(n.code,{children:"qtenvX"})," scripts described above."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`mkdir ${(0,x.Sn)(y.b)}\ncd ${(0,x.Sn)(y.b)}\n$env:Path = 'C:\\Qt\\6.7.0\\msvc2019_64\\bin;' + $env:Path\nvcvars64.ps1`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`mkdir -p ${(0,x.Sn)(y.xj)}\ncd ${(0,x.Sn)(y.xj)}\nexport PATH=/opt/Qt/6.7.0/gcc_64/bin\${PATH:+:}$PATH\nexport LD_LIBRARY_PATH=/opt/Qt/6.7.0/gcc_64/lib\${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH`})})]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can also use the ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/tools/Add-FolderOnPath.ps1",children:(0,s.jsx)(n.code,{children:"tools/Add-FolderOnPath.ps1"})})," pwsh script to fastly prepend a path or ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"})," on the system ",(0,s.jsx)(n.code,{children:"PATH"}),"."]})}),"\n",(0,s.jsx)(n.h2,{id:"vcpkg",children:"vcpkg"}),"\n",(0,s.jsxs)(n.p,{children:["Installing the ",(0,s.jsx)(n.code,{children:"vcpkg"})," is highly recommended, it simplifies installation of the ",(0,s.jsx)(n.code,{children:"range-v3"})," and ",(0,s.jsx)(n.code,{children:"tabulate"})," dependencies."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"git clone git@github.com:microsoft/vcpkg.git\ncd vcpkg\n.\\bootstrap-vcpkg.bat\n"})})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"git clone git@github.com:microsoft/vcpkg.git\ncd vcpkg\n./bootstrap-vcpkg.sh\n"})})})]}),"\n",(0,s.jsxs)(n.p,{children:["Add ",(0,s.jsx)(n.code,{children:"vcpkg"})," on the system path, add the following to the ",(0,s.jsx)(n.code,{children:".bashrc"})," or ",(0,s.jsx)(n.code,{children:".zshrc"})," on Linux."]}),"\n",(0,s.jsx)(c.A,{className:"language-bash",children:`export PATH=${(0,x.Sn)(y.xj)}/vcpkg\${PATH:+:}$PATH`}),"\n",(0,s.jsxs)(n.p,{children:["On Windows, open the ",(0,s.jsx)(n.code,{children:"Environment variables"})," dialog and add ",(0,s.jsx)(n.code,{children:"vcpkg"})," on the user ",(0,s.jsx)(n.code,{children:"PATH"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"Or you can export it for the current session only."}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`$env:Path = "${(0,x.Sn)(y.b,!1)}\\vcpkg;" + $env:Path`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`export PATH=${(0,x.Sn)(y.xj)}/vcpkg\${PATH:+:}$PATH`})})]}),"\n",(0,s.jsxs)(n.h4,{id:"set-up-vcpkg-environment",children:["Set up ",(0,s.jsx)(n.code,{children:"vcpkg"})," environment"]}),"\n",(0,s.jsxs)(n.p,{children:["To export ",(0,s.jsx)(n.code,{children:"vcpkg"})," environment variables globally, add it to the ",(0,s.jsx)(n.code,{children:".bashrc"})," or ",(0,s.jsx)(n.code,{children:".zshrc"})," on Linux, and you can use the ",(0,s.jsx)(n.code,{children:"Environment variables"})," dialog on Windows."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",metastring:"title='Linux'",children:'export VCPKG_DEFAULT_TRIPLET=x64-linux\n#export VCPKG_DEFAULT_HOST_TRIPLET=x64-linux\nexport VCPKG_MAX_CONCURRENCY=11\nexport VCPKG_OVERLAY_PORTS="$HOME/.local/share/vcpkg/ports"\nexport VCPKG_OVERLAY_TRIPLETS="$HOME/.local/share/vcpkg/triplets"\nexport VCPKG_ROOT="$HOME/Code/c/vcpkg"\n'})}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["It is recommended to define these variables globally because the ",(0,s.jsx)(n.code,{children:"CMake"})," and ",(0,s.jsx)(n.code,{children:"qmake"})," build system are able to detect the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation from them so you don't have to configure them manually to detect the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation."]})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["On Windows, it's always better to create these types of variables as user variables instead of system variables in the ",(0,s.jsx)(n.code,{children:"Environment variables"})," dialog."]})}),"\n",(0,s.jsx)(n.h2,{id:"c-preprocessor-macros",children:"C preprocessor macros"}),"\n",(0,s.jsxs)(n.p,{children:["The following table summarizes all the C preprocessor macros defined in the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. These C macros are configured by ",(0,s.jsx)(n.code,{children:"CMake"})," or ",(0,s.jsx)(n.code,{children:"qmake"})," build systems. They are not sorted alphabetically, but they are sorted by how significant they are."]}),"\n",(0,s.jsxs)(n.p,{children:["In the ",(0,s.jsx)(n.code,{children:"CMake"})," build system, all the C macros are auto-detected / auto-configured or controlled by ",(0,s.jsx)(n.a,{href:"#cmake-build-options",children:(0,s.jsx)(n.code,{children:"CMake build options"})}),", so you don't have to care too much about them."]}),"\n",(0,s.jsxs)(n.p,{children:["In the ",(0,s.jsx)(n.code,{children:"qmake"})," build is important whether you are building ",(0,s.jsx)(n.code,{children:"TinyORM"})," library or you are building your application and linking against ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. When you are building the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library, all the C macros are auto-detected / auto-configured or controlled by ",(0,s.jsx)(n.a,{href:"#qmake-build-options",children:(0,s.jsx)(n.code,{children:"qmake build options"})}),", so you don't have to care too much about them."]}),"\n",(0,s.jsxs)(n.p,{children:["But a special situation is when you are building your application / library and you are linking against ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. In this particular case, you must configure all these C macros manually! For this reason, the ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/qmake/TinyOrm.pri",children:(0,s.jsx)(n.code,{children:"TinyOrm.pri"})})," has been created, so that's not a big deal either. Little more info ",(0,s.jsx)(n.a,{href:"#consume-tinyorm-library-qmake",children:"here"}),"."]}),"\n",(0,s.jsx)("div",{id:"apitable-c-macros",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"C Macro Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_LINKING_SHARED"})}),(0,s.jsxs)(n.td,{children:[(0,s.jsx)("u",{children:(0,s.jsx)(n.strong,{children:"Must"})})," be defined when you are linking against ",(0,s.jsx)(n.code,{children:"TinyORM"})," shared build (",(0,s.jsx)(n.code,{children:"dll"})," library), exported classes and functions will be tagged with ",(0,s.jsx)(n.code,{children:"__declspec(dllimport)"})," on ",(0,s.jsx)(n.code,{children:"msvc"})," and ",(0,s.jsx)(n.code,{children:'visibility("default")'})," on ",(0,s.jsx)(n.code,{children:"GCC >= 4"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_BUILDING_SHARED"})}),(0,s.jsxs)(n.td,{children:["Defined when ",(0,s.jsx)(n.code,{children:"TinyORM"})," is built as a ",(0,s.jsx)(n.code,{children:"dll"})," library (shared build)."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_DEBUG"})}),(0,s.jsx)(n.td,{children:"Defined in the debug build."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_NO_DEBUG"})}),(0,s.jsx)(n.td,{children:"Defined in the release build."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_DEBUG_SQL"})}),(0,s.jsx)(n.td,{children:"Defined in the debug build."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_NO_DEBUG_SQL"})}),(0,s.jsx)(n.td,{children:"Defined in the release build."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_MYSQL_PING"})}),(0,s.jsxs)(n.td,{children:["Enable ",(0,s.jsx)(n.code,{children:"Orm::MySqlConnection::pingDatabase()"})," method.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#mysql_ping",children:(0,s.jsx)(n.code,{children:"mysql_ping"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#MYSQL_PING",children:(0,s.jsx)(n.code,{children:"MYSQL_PING"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_DISABLE_ORM"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"ORM-related"})," source code, when this macro is ",(0,s.jsx)(n.code,{children:"defined"}),", then only the ",(0,s.jsx)(n.code,{children:"query builder"})," without ",(0,s.jsx)(n.code,{children:"ORM"})," is compiled. Also excludes ",(0,s.jsx)(n.code,{children:"ORM-related"})," unit tests.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#disable_orm",children:(0,s.jsx)(n.code,{children:"disable_orm"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#ORM",children:(0,s.jsx)(n.code,{children:"ORM"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled ",(0,s.jsx)("small",{children:"(qmake)"})," / disabled ",(0,s.jsx)("small",{children:"(cmake)"}),"."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_EXTERN_CONSTANTS"})}),(0,s.jsxs)(n.td,{children:["Defined when extern constants are used. Extern constants are enabled by default for shared builds and disabled for static builds.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Described at ",(0,s.jsx)(n.a,{href:"#extern_constants",children:(0,s.jsx)(n.code,{children:"qmake"})})," / ",(0,s.jsx)(n.a,{href:"#INLINE_CONSTANTS",children:(0,s.jsx)(n.code,{children:"CMake"})})," how it works."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_INLINE_CONSTANTS"})}),(0,s.jsxs)(n.td,{children:["Defined when global inline constants are used.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#inline_constants",children:(0,s.jsx)(n.code,{children:"inline_constants"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#INLINE_CONSTANTS",children:(0,s.jsx)(n.code,{children:"INLINE_CONSTANTS"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_TESTS_CODE"})}),(0,s.jsxs)(n.td,{children:["Enable code needed by unit tests, eg. connection overriding in the ",(0,s.jsx)(n.code,{children:"Orm::Tiny::Model"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#build_tests",children:(0,s.jsx)(n.code,{children:"build_tests"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#BUILD_TESTS",children:(0,s.jsx)(n.code,{children:"BUILD_TESTS"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_DISABLE_THREAD_LOCAL"})}),(0,s.jsxs)(n.td,{children:["Remove all ",(0,s.jsx)(n.a,{href:"https://en.cppreference.com/w/c/language/storage_duration",children:(0,s.jsx)(n.code,{children:"thread_local"})})," storage duration specifiers, it disables multi-threading support.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#disable_thread_local",children:(0,s.jsx)(n.code,{children:"disable_thread_local"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#DISABLE_THREAD_LOCAL",children:(0,s.jsx)(n.code,{children:"DISABLE_THREAD_LOCAL"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYTOM_MIGRATIONS_DIR"})}),(0,s.jsxs)(n.td,{children:["Default migrations path for the ",(0,s.jsx)(n.code,{children:"make:migration"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/migrations"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined by ",(0,s.jsx)(n.a,{href:"#TOM_MIGRATIONS_DIR",children:(0,s.jsx)(n.code,{children:"TOM_MIGRATIONS_DIR"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration build option.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["(qmake note) You can use ",(0,s.jsx)(n.code,{children:'DEFINES += TINYTOM_MIGRATIONS_DIR="\\"database/migrations\\""'})," on the command-line or set it in the ",(0,s.jsx)(n.strong,{children:"main"})," ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L65-L70",children:(0,s.jsx)(n.code,{children:"conf.pri"})})," file."]})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYTOM_MODELS_DIR"})}),(0,s.jsxs)(n.td,{children:["Default models path for the ",(0,s.jsx)(n.code,{children:"make:model"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/models"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined by ",(0,s.jsx)(n.a,{href:"#TOM_MODELS_DIR",children:(0,s.jsx)(n.code,{children:"TOM_MODELS_DIR"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration build option.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["(qmake note) You can use ",(0,s.jsx)(n.code,{children:'DEFINES += TINYTOM_MODELS_DIR="\\"database/models\\""'})," on the command-line or set it in the ",(0,s.jsx)(n.strong,{children:"main"})," ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L72-L73",children:(0,s.jsx)(n.code,{children:"conf.pri"})})," file."]})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYTOM_SEEDERS_DIR"})}),(0,s.jsxs)(n.td,{children:["Default seeders path for the ",(0,s.jsx)(n.code,{children:"make:seeder"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/seeders"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined by ",(0,s.jsx)(n.a,{href:"#TOM_SEEDERS_DIR",children:(0,s.jsx)(n.code,{children:"TOM_SEEDERS_DIR"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration build option.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["(qmake note) You can use ",(0,s.jsx)(n.code,{children:'DEFINES += TINYTOM_SEEDERS_DIR="\\"database/seeders\\""'})," on the command-line or set it in the ",(0,s.jsx)(n.strong,{children:"main"})," ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L75-L76",children:(0,s.jsx)(n.code,{children:"conf.pri"})})," file."]})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_USING_PCH"})}),(0,s.jsxs)(n.td,{children:["Defined if building with precompiled headers.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Controlled by ",(0,s.jsx)(n.a,{href:"#qmake-precompile_header",children:(0,s.jsx)(n.code,{children:"qmake"})})," / ",(0,s.jsx)(n.a,{href:"#CMAKE_DISABLE_PRECOMPILE_HEADERS",children:(0,s.jsx)(n.code,{children:"CMake"})}),"."]})]})]})]})]})})}),"\n",(0,s.jsx)(n.h2,{id:"building-with-cmake",children:"Building with CMake"}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["If something is not clear, you can still look at GitHub Action ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/tree/main/.github/workflows",children:(0,s.jsx)(n.code,{children:"workflows"})})," how a building is done."]})}),"\n",(0,s.jsxs)(n.p,{children:["First, create a basic folder structure and then clone the ",(0,s.jsx)(n.code,{children:"TinyORM"})," project."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cd ${(0,x.Sn)(y.b)}\nmkdir ${(0,x.np)()}/TinyORM/TinyORM-builds-cmake/build-debug\n\ncd ${(0,x.np)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cd ${(0,x.Sn)(y.xj)}\nmkdir -p ${(0,x.np)()}/TinyORM/TinyORM-builds-cmake/build-debug\n\ncd ${(0,x.np)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`})})]}),"\n",(0,s.jsxs)(n.h3,{id:"configure-and-build-cmake",children:["Configure & Build ",(0,s.jsx)("small",{children:"(cmake)"})]}),"\n",(0,s.jsxs)(n.p,{children:["Now you are ready to configure the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"cd TinyORM-builds-cmake/build-debug\n"})}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cmake.exe \`\n-S "${(0,x.OZ)(y.b)}/TinyORM/TinyORM" \`\n-B "${(0,x.OZ)(y.b)}/TinyORM/TinyORM-builds-cmake/build-debug" \`\n-G 'Ninja' \`\n-D CMAKE_BUILD_TYPE:STRING='Debug' \`\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,x.Sn)(y.b)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \`\n-D CMAKE_CXX_SCAN_FOR_MODULES:BOOL=OFF \`\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,x.Sn)(y.b)}/tmp/TinyORM" \`\n-D BUILD_TESTS:BOOL=OFF \`\n-D MATCH_EQUAL_EXPORTED_BUILDTREE:BOOL=ON \`\n-D MYSQL_PING:BOOL=OFF \`\n-D TOM:BOOL=ON \`\n-D TOM_EXAMPLE:BOOL=OFF \`\n-D VERBOSE_CONFIGURE:BOOL=ON`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cmake \\\n-S "${(0,x.OZ)(y.xj)}/TinyORM/TinyORM" \\\n-B "${(0,x.OZ)(y.xj)}/TinyORM/TinyORM-builds-cmake/build-debug" \\\n-G 'Ninja' \\\n-D CMAKE_BUILD_TYPE:STRING='Debug' \\\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,x.Sn)(y.xj)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \\\n-D CMAKE_CXX_SCAN_FOR_MODULES:BOOL=OFF \\\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,x.Sn)(y.xj)}/tmp/TinyORM" \\\n-D VERBOSE_CONFIGURE:BOOL=ON \\\n-D BUILD_TESTS:BOOL=OFF \\\n-D MYSQL_PING:BOOL=OFF \\\n-D TOM:BOOL=ON \\\n-D TOM_EXAMPLE:BOOL=OFF \\\n-D MATCH_EQUAL_EXPORTED_BUILDTREE:BOOL=ON`})})]}),"\n",(0,s.jsxs)(n.h5,{id:"cmake-strict_mode-option",children:["CMake ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," option"]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," ",(0,s.jsx)(n.code,{children:"CMake"})," configuration option was added in ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.37.3"}),". This option was added to avoid the propagation of aggressive strict warning compiler/linker options and Qt definitions from the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library to user code through the ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/cmake/CommonModules/TinyCommon.cmake",children:(0,s.jsx)(n.code,{children:"TinyOrm::CommonConfig"})})," interface library."]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"TinyORM"})," uses the strictest warning level options, virtually anything that can be enabled is enabled to produce a better code. I highly recommend enabling this option to produce better code and to follow good practices. It also helps to follow the ",(0,s.jsx)(n.code,{children:"ISOCPP"})," ",(0,s.jsx)(n.a,{href:"https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines",children:"C++ Core Guidelines"})," standards."]}),"\n",(0,s.jsxs)(n.p,{children:["If you want to enable these strict warning options in your code, you can enable the ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," ",(0,s.jsx)(n.code,{children:"CMake"})," configuration option and they will be propagated to your code. You can also enabled it globally using the ",(0,s.jsx)(n.code,{children:"TINYORM_STRICT_MODE"})," environment variable, and the value of this environment variable will be picked up during initial CMake configuration as the default value for the ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," ",(0,s.jsx)(n.code,{children:"CMake"})," configuration option."]}),"\n",(0,s.jsxs)(n.p,{children:["You can achieve the same result by manually linking against the ",(0,s.jsx)(n.code,{children:"TinyOrm::CommonConfig"})," interface library when the ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," is set to ",(0,s.jsx)(n.code,{children:"OFF"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cmake",children:"target_link_libraries( PRIVATE TinyOrm::CommonConfig)\n"})}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["The recommended way is to set the ",(0,s.jsx)(n.code,{children:"TINYORM_STRICT_MODE"})," environment variable to ",(0,s.jsx)(n.code,{children:"1"})," or ",(0,s.jsx)(n.code,{children:"ON"}),"."]})}),"\n",(0,s.jsx)(n.h4,{id:"build-tinyorm",children:"Build TinyORM"}),"\n",(0,s.jsx)(n.p,{children:"And build. You don't have to install it, you can use the build tree directly if you want."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"cmake --build . --target all\ncmake --install .\n"})}),"\n",(0,s.jsx)(n.p,{children:"Or build and install in one step."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"cmake --build . --target install\n"})}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["CMake multi-config generators like ",(0,s.jsx)(n.code,{children:"Ninja Multi-Config"})," or ",(0,s.jsx)(n.code,{children:"Visual Studio 16 2019"})," are also supported."]})}),"\n",(0,s.jsx)(n.h3,{id:"cmake-build-options",children:"CMake build options"}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Option Name"}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_DRIVERS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started",children:"TinyDrivers"})," SQL database drivers (core/common code; replaces QtSql module)."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_MYSQL_DRIVER"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," MySQL database driver.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)(n.code,{children:"BUILD_DRIVERS"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_SHARED_LIBS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsx)(n.td,{children:"Build as a shared/static library."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_TESTS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsx)(n.td,{children:"Build TinyORM unit tests."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_TREE_DEPLOY"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Copy ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," and ",(0,s.jsx)(n.code,{children:"TinyMySql"})," libraries to the root of the build tree."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"DRIVERS_TYPE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"Shared"})}),(0,s.jsxs)(n.td,{children:["How to build and link against ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," SQL database drivers.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["The ",(0,s.jsx)(n.code,{children:"Static"})," value will be select by default when the ",(0,s.jsx)(n.code,{children:"BUILD_SHARED_LIBS"})," is ",(0,s.jsx)(n.code,{children:"OFF"}),".",(0,s.jsx)("br",{}),"Supported values: ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-shared-library-build",children:(0,s.jsx)(n.code,{children:"Shared"})}),", ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-loadable-sql-drivers-build",children:(0,s.jsx)(n.code,{children:"Loadable"})}),", and ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-static-build",children:(0,s.jsx)(n.code,{children:"Static"})}),(0,s.jsx)("br",{}),"Available when: ",(0,s.jsx)(n.code,{children:"BUILD_DRIVERS AND BUILD_SHARED_LIBS"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"INLINE_CONSTANTS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Use inline constants instead of extern constants in the ",(0,s.jsx)(n.code,{children:"shared build"}),".",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"OFF"})," is highly recommended for the ",(0,s.jsx)(n.code,{children:"shared build"}),";",(0,s.jsx)("br",{}),"is always ",(0,s.jsx)(n.code,{children:"ON"})," for the ",(0,s.jsx)(n.code,{children:"static build"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)(n.code,{children:"BUILD_SHARED_LIBS"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"MSVC_RUNTIME_DYNAMIC"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Use MSVC dynamic runtime library (",(0,s.jsx)(n.code,{children:"-MD"}),") instead of static (",(0,s.jsx)(n.code,{children:"-MT"}),"), also considers a Debug configuration (",(0,s.jsx)(n.code,{children:"-MTd"}),", ",(0,s.jsx)(n.code,{children:"-MDd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)(n.code,{children:"MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"MYSQL_PING"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Enable ",(0,s.jsx)(n.code,{children:"Orm::MySqlConnection::pingDatabase()"})," method."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ORM"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"ORM-related"})," source code, when this option is ",(0,s.jsx)(n.code,{children:"disabled"}),", then only the ",(0,s.jsx)(n.code,{children:"query builder"})," without ",(0,s.jsx)(n.code,{children:"ORM"})," is compiled. Also excludes ",(0,s.jsx)(n.code,{children:"ORM-related"})," unit tests."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"STRICT_MODE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Controls propagation of strict compiler/linker options and Qt definitions using the ",(0,s.jsx)(n.code,{children:"TinyOrm::CommonConfig"})," interface library to the user code.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["(highly recommended; can also be set with the ",(0,s.jsx)(n.code,{children:"TINYORM_STRICT_MODE"})," environment variable; described ",(0,s.jsx)(n.a,{href:"#cmake-strict_mode-option",children:"here"}),")"]}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"Tom-related"})," source code, when this option is ",(0,s.jsx)(n.code,{children:"disabled"}),", then it also excludes ",(0,s.jsx)(n.code,{children:"Tom-related"})," unit tests."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM_EXAMPLE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build the ",(0,s.jsx)("abbr",{title:"TinyORM Migrations",children:(0,s.jsx)(n.code,{children:"tom"})})," console application example."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM_MIGRATIONS_DIR"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Default migrations path for the ",(0,s.jsx)(n.code,{children:"make:migration"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/migrations"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM_MODELS_DIR"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Default models path for the ",(0,s.jsx)(n.code,{children:"make:model"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/models"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM_SEEDERS_DIR"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Default seeders path for the ",(0,s.jsx)(n.code,{children:"make:seeder"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/seeders"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"VERBOSE_CONFIGURE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Show information about ",(0,s.jsx)(n.code,{children:"PACKAGES_FOUND"})," / ",(0,s.jsx)(n.code,{children:"PACKAGES_NOT_FOUND"})," in the CMake configure output."]})]})]})]})})}),"\n",(0,s.jsxs)(n.p,{children:["Advanced ",(0,s.jsx)(n.code,{children:"TinyORM"})," options."]}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Option Name"}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"DISABLE_THREAD_LOCAL"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Remove all ",(0,s.jsx)(n.a,{href:"https://en.cppreference.com/w/c/language/storage_duration",children:(0,s.jsx)(n.code,{children:"thread_local"})})," storage duration specifiers, it disables multi-threading support."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)("small",{children:(0,s.jsx)(n.code,{children:"MATCH_EQUAL_EXPORTED_BUILDTREE"})})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Exported package configuration from the build tree is considered to match only when ",(0,s.jsx)(n.code,{children:"the build type"})," of application/library that is linking against the TinyORM library ",(0,s.jsx)(n.strong,{children:"is equal"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when:",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"CMAKE_EXPORT_PACKAGE_REGISTRY AND NOT TINY_IS_MULTI_CONFIG"})]})]})]})]})]})})}),"\n",(0,s.jsxs)(n.p,{children:["Important ",(0,s.jsx)(n.code,{children:"CMake"})," options."]}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Option Name"}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_DISABLE_PRECOMPILE_HEADERS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsx)(n.td,{children:"Disable precompiled headers."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_CXX_COMPILER"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"auto"})}),(0,s.jsxs)(n.td,{children:["The full path to the ",(0,s.jsx)(n.code,{children:"C++"})," compiler."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_CXX_COMPILER_LAUNCHER"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Default compiler launcher to use for the ",(0,s.jsx)(n.code,{children:"C++"})," compiler.",(0,s.jsx)("br",{}),"Can be used to enable ",(0,s.jsx)(n.code,{children:"ccache"}),", eg. ",(0,s.jsx)(n.code,{children:"ccache.exe"})," on ",(0,s.jsx)(n.code,{children:"MinGW"})," or ",(0,s.jsx)(n.code,{children:"/usr/bin/ccache"})," on ",(0,s.jsx)(n.code,{children:"Linux"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_EXPORT_PACKAGE_REGISTRY"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Enable the ",(0,s.jsx)(n.code,{children:"export(TinyOrm)"})," command.",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"TinyORM"})," doesn't set this variable by default. Its initial value is taken from the ",(0,s.jsx)(n.code,{children:"TINYORM_EXPORT_PACKAGE_REGISTRY"})," environment variable if not already defined."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_VERBOSE_MAKEFILE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsx)(n.td,{children:"Enable verbose output from Makefile builds."})]})]})]})})}),"\n",(0,s.jsxs)(n.h3,{id:"consume-tinyorm-library-cmake",children:["Consume TinyOrm library ",(0,s.jsx)("small",{children:"(cmake)"})]}),"\n",(0,s.jsxs)(n.p,{children:["In your application or library ",(0,s.jsx)(n.code,{children:"CMakeLists.txt"})," file add following ",(0,s.jsx)(n.code,{children:"find_package()"})," call."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cmake",metastring:"title='CMakeLists.txt'",children:"find_package(TinyOrm 0.37.3 CONFIG REQUIRED)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build tree is not exported to the CMake's ",(0,s.jsx)(n.a,{href:"https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#user-package-registry",children:(0,s.jsx)(n.code,{children:"User Package Registry"})})," then also add the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build tree or ",(0,s.jsx)(n.code,{children:"CMAKE_INSTALL_PREFIX"})," folder to the ",(0,s.jsx)(n.code,{children:"CMAKE_PREFIX_PATH"}),", so CMake can find TinyORM's package configuration file during ",(0,s.jsx)(n.code,{children:"find_package(TinyOrm)"})," call."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:`cmake (${y.b})`,children:(0,s.jsx)(c.A,{className:"language-cmake",children:`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,x.nC)(y.b,(0,x.OZ)(y.b))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\n# installation folder - CMAKE_INSTALL_PREFIX\nlist(APPEND CMAKE_PREFIX_PATH "${(0,x.nC)(y.b,(0,x.Sn)(y.b))}/tmp/TinyORM")`})}),(0,s.jsx)(t.A,{value:y.xj,label:`cmake (${y.xj})`,children:(0,s.jsx)(c.A,{className:"language-cmake",children:`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,x.nC)(y.xj,(0,x.OZ)(y.xj))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\n# installation folder - CMAKE_INSTALL_PREFIX\nlist(APPEND CMAKE_PREFIX_PATH "${(0,x.nC)(y.xj,(0,x.Sn)(y.xj))}/tmp/TinyORM")`})})]}),"\n",(0,s.jsxs)(n.p,{children:["Or as an alternative, you can set ",(0,s.jsx)(n.code,{children:"CMAKE_PREFIX_PATH"})," environment variable."]}),"\n",(0,s.jsx)(r.A,{id:"tinyorm-on-path-cmake"}),"\n",(0,s.jsxs)(n.p,{children:["As the last thing, do not forget to add ",(0,s.jsx)(n.code,{children:"TinyOrm0d.dll"})," on the path on Windows and on the ",(0,s.jsx)(n.code,{children:"LD_LIBRARY_PATH"})," on Linux, so your application can find it during execution."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,name:"tinyorm-on-path",children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`$env:Path = "${(0,x.OZ)(y.b,!1)}\\TinyORM\\TinyORM-builds-cmake\\build-debug;" + $env:Path`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`export LD_LIBRARY_PATH=${(0,x.OZ)(y.xj)}/TinyORM/TinyORM-builds-cmake/build-debug\${PATH:+:}$PATH`})})]}),"\n",(0,s.jsxs)(n.p,{children:["Now you can try the ",(0,s.jsx)(n.a,{href:"/building/hello-world#hello-world-with-cmake",children:(0,s.jsx)(n.code,{children:"HelloWorld CMake"})})," example."]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["You can also try the ",(0,s.jsx)(n.a,{href:"/building/hello-world#fetchcontent",children:(0,s.jsx)(n.code,{children:"FetchContent"})})," method to fastly link against the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library."]})}),"\n",(0,s.jsx)(n.h2,{id:"building-with-qmake",children:"Building with qmake"}),"\n",(0,s.jsxs)(n.p,{children:["First, create a basic folder structure and then clone the ",(0,s.jsx)(n.code,{children:"TinyORM"})," project."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cd ${(0,x.Sn)(y.b)}\nmkdir ${(0,x.np)()}/TinyORM/TinyORM-builds-qmake\n\ncd ${(0,x.np)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cd ${(0,x.Sn)(y.xj)}\nmkdir -p ${(0,x.np)()}/TinyORM/TinyORM-builds-qmake\n\ncd ${(0,x.np)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`})})]}),"\n",(0,s.jsx)(n.h3,{id:"install-dependencies",children:"Install dependencies"}),"\n",(0,s.jsxs)(n.p,{children:["With the ",(0,s.jsx)(n.code,{children:"qmake"})," build system, you have to install ",(0,s.jsx)(n.code,{children:"TinyORM"})," dependencies manually. We will use the ",(0,s.jsx)(n.code,{children:"vcpkg"})," package manager."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"cd ../../vcpkg\n\nvcpkg search range-v3\nvcpkg search tabulate\nvcpkg install range-v3 tabulate\nvcpkg list\n"})}),"\n",(0,s.jsxs)(n.p,{children:["On ",(0,s.jsx)(n.code,{children:"Linux"}),", you can install the ",(0,s.jsx)(n.code,{children:"range-v3"})," library and some other ",(0,s.jsx)(n.a,{href:"/dependencies#install-dependencies",children:"dependencies"})," with the package manager."]}),"\n",(0,s.jsxs)(n.h3,{id:"configure-and-build-qmake",children:["Configure & Build ",(0,s.jsx)("small",{children:"(qmake)"})]}),"\n",(0,s.jsx)(n.h4,{id:"open-qtcreator-ide",children:"Open QtCreator IDE"}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["I recommend creating a new ",(0,s.jsx)(n.a,{href:"https://doc.qt.io/qtcreator/creator-project-managing-sessions.html",children:(0,s.jsx)(n.code,{children:"Session"})})," in the ",(0,s.jsx)(n.code,{children:"QtCreator"}),", this way you will have all the examples in one place and as a bonus, everything will be in the same place when you close and reopen ",(0,s.jsx)(n.code,{children:"QtCreator IDE"}),". You can name it ",(0,s.jsx)(n.code,{children:"tinyorm.org"})," or ",(0,s.jsx)(n.code,{children:"TinyORM examples"}),", it is up to you."]})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["If you are using sessions, you can use a single ",(0,s.jsx)(n.code,{children:"clangd"})," instance for all projects in this session in the ",(0,s.jsx)(n.code,{children:"QtCreator IDE"}),". One significant advantage of this method is that the ",(0,s.jsx)(n.code,{children:".qtc_clangd/"})," folder will not be created in the build folder, but will be stored globally in the Roaming profile. You can enable it in the ",(0,s.jsx)(n.code,{children:"Settings"})," - ",(0,s.jsx)(n.code,{children:"C++"})," - ",(0,s.jsx)(n.code,{children:"Clangd"})," - ",(0,s.jsx)(n.code,{children:"Sessions with a single clangd instance"}),"."]})}),"\n",(0,s.jsx)(n.h4,{id:"configure-tinyorm",children:"Configure TinyORM"}),"\n",(0,s.jsxs)(n.p,{children:["Now you are ready to configure the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. There are two ways how to configure the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library and it's the new ",(0,s.jsx)(n.code,{children:"Auto-configure"})," feature added in ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"})," using the ",(0,s.jsx)(n.code,{children:".env"})," files and the old way using the ",(0,s.jsx)(n.code,{children:"conf.pri"})," files."]}),"\n",(0,s.jsx)(n.h5,{id:"auto-configuration-and-tiny_dotenv",children:"Auto-configuration and tiny_dotenv"}),"\n",(0,s.jsxs)(n.p,{children:["This is the new recommended method to auto-configure TinyORM's ",(0,s.jsx)(n.code,{children:"qmake"})," build system and also the dependencies, it was added in ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"}),". You need to copy the prepared ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw).example"})," file to the ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw)"}),". One ",(0,s.jsx)(n.code,{children:".env"})," example file is prepared for each supported platform."]}),"\n",(0,s.jsxs)(n.p,{children:["All prepared ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw).example"})," files are simple and clear. You can also create a common ",(0,s.jsx)(n.code,{children:".env"})," file that is included before the platform-specific ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw)"})," files."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cd ${(0,x.OZ)(y.b)}/TinyORM/TinyORM\n\ncp .env.win32.example .env.win32`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cd ${(0,x.OZ)(y.xj)}/TinyORM/TinyORM\n\ncp .env.unix.example .env.unix`})})]}),"\n",(0,s.jsxs)(n.p,{children:["And that is all, if you have correctly set all ",(0,s.jsx)(n.code,{children:"qmake"})," variables in this ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw)"})," file or you have correctly set environment variables, then the ",(0,s.jsx)(n.code,{children:"qmake"})," build system should be able to ",(0,s.jsx)(n.code,{children:"auto-detect"})," all dependencies . \ud83d\udd25"]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"#auto-configuration-internals",children:(0,s.jsx)(n.code,{children:"Auto-configuration"})})," and ",(0,s.jsx)(n.a,{href:"#environment-files",children:(0,s.jsx)(n.code,{children:"Environment files"})})," internals are described at the end to make this section more clear."]})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature can be turned off using the ",(0,s.jsx)(n.a,{href:"#disable_autoconf",children:(0,s.jsx)(n.code,{children:"disable_autoconf"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_autoconf"}),")."]})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," feature can be turned off using the ",(0,s.jsx)(n.a,{href:"#disable_dotenv",children:(0,s.jsx)(n.code,{children:"disable_dotenv"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_dotenv"}),")."]})}),"\n",(0,s.jsx)(n.h5,{id:"manual-configuration-confpri",children:"Manual configuration (conf.pri)"}),"\n",(0,s.jsxs)(n.p,{children:["This is the old method used before ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"}),". You need to copy the ",(0,s.jsx)(n.code,{children:"conf.pri.example"})," files to ",(0,s.jsx)(n.code,{children:"conf.pri"})," (there are four, one for every project or sub-project) and manually update the ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," and ",(0,s.jsx)(n.code,{children:"LIBS"})," to configure TinyORM's ",(0,s.jsx)(n.code,{children:"qmake"})," build dependencies. This way you can override any ",(0,s.jsx)(n.code,{children:"qmake"})," build options or variables."]}),"\n",(0,s.jsxs)(n.p,{children:["To disable the ",(0,s.jsx)(n.a,{href:"#auto-configuration-internals",children:(0,s.jsx)(n.code,{children:"Auto-configuration"})})," feature you must define the ",(0,s.jsx)(n.a,{href:"#disable_autoconf",children:(0,s.jsx)(n.code,{children:"disable_autoconf"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_autoconf"}),") because from ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"})," is the ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature enabled by default."]}),"\n",(0,s.jsxs)(n.p,{children:["You can also remove all ",(0,s.jsx)(n.code,{children:".env"})," files or turn off the ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," feature using ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_dotenv"}),". You can use them all at once if you want, ",(0,s.jsx)(n.code,{children:".env"})," and also ",(0,s.jsx)(n.code,{children:"conf.pri"})," files."]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"conf.pri"})," files are nicely commented on, so you can see what needs to be modified."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cd ${(0,x.OZ)(y.b)}/TinyORM/TinyORM\n\ncp conf.pri.example conf.pri\ncp tests/conf.pri.example tests/conf.pri\ncp tests/testdata_tom/conf.pri.example tests/testdata_tom/conf.pri\ncp examples/tom/conf.pri.example examples/tom/conf.pri`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cd ${(0,x.OZ)(y.xj)}/TinyORM/TinyORM\n\ncp conf.pri.example conf.pri\ncp tests/conf.pri.example tests/conf.pri\ncp tests/testdata_tom/conf.pri.example tests/testdata_tom/conf.pri\ncp examples/tom/conf.pri.example examples/tom/conf.pri`})})]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"#manual-configuration-internals",children:(0,s.jsx)(n.code,{children:"Manual configuration"})})," internals are described at the end to make this section more clear."]})}),"\n",(0,s.jsx)(n.admonition,{type:"note",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Manual configuration"})," is still relevant if you have any non-standard installation of the ",(0,s.jsx)(n.code,{children:"vcpkg"})," or ",(0,s.jsx)(n.code,{children:"MySQL"})," and the ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature fails."]})}),"\n",(0,s.jsx)(n.h5,{id:"opening-tinyormpro-main-project-file",children:"Opening TinyORM.pro (main project file)"}),"\n",(0,s.jsxs)(n.p,{children:["Now you can open the ",(0,s.jsx)(n.code,{children:"TinyORM.pro"})," project in the ",(0,s.jsx)(n.code,{children:"QtCreator IDE"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["This will open the ",(0,s.jsx)(n.code,{children:"Configure Project"})," tab, select some kit and update build folder paths to meet our ",(0,s.jsx)(n.a,{href:"#folders-structure",children:"folders structure"})," or like you want."]}),"\n",(0,s.jsx)("img",{src:i(885).A,alt:"TinyORM - QtCreator - Configure Project",width:"760"}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can force the ",(0,s.jsx)(n.code,{children:"QtCreator"})," to generate a build folders structure as is described ",(0,s.jsx)(n.a,{href:"#qtcreator-default-build-directory",children:"above"}),"."]})}),"\n",(0,s.jsxs)(n.p,{children:["You are ready to configure build options, hit ",(0,s.jsx)("kbd",{children:"Ctrl"}),"+",(0,s.jsx)("kbd",{children:"5"})," to open ",(0,s.jsx)(n.code,{children:"Project Settings"})," tab and select ",(0,s.jsx)(n.code,{children:"Build"})," in the left sidebar to open the ",(0,s.jsx)(n.code,{children:"Build Settings"}),", it should look similar to the following picture."]}),"\n",(0,s.jsxs)(n.p,{children:["Disable ",(0,s.jsx)(n.code,{children:"QML debugging and profiling"})," and ",(0,s.jsx)(n.code,{children:"Qt Quick Compiler"}),", they are not used."]}),"\n",(0,s.jsx)("img",{src:i(7619).A,alt:"TinyORM - QtCreator - Build Settings",width:"760"}),"\n",(0,s.jsxs)(n.p,{children:["If you want to change some ",(0,s.jsx)(n.code,{children:"TinyORM"})," build options, you can pass them to the ",(0,s.jsx)(n.code,{children:"Build Steps"})," - ",(0,s.jsx)(n.code,{children:"qmake TinyORM.pro"})," - ",(0,s.jsx)(n.code,{children:"Additional arguments"})," input field. It can look like this."]}),"\n",(0,s.jsx)("img",{src:i(2721).A,alt:"TinyORM - QtCreator - Build Settings - Additional arguments",width:"660"}),"\n",(0,s.jsx)(n.h4,{id:"build-tinyorm-1",children:"Build TinyORM"}),"\n",(0,s.jsxs)(n.p,{children:["Everything is ready for build, you can press ",(0,s.jsx)("kbd",{children:"Ctrl"}),"+",(0,s.jsx)("kbd",{children:"b"})," to build the project."]}),"\n",(0,s.jsx)(n.h3,{id:"qmake-build-options",children:"qmake build options"}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsxs)(n.th,{children:[(0,s.jsx)(n.code,{children:"CONFIG"})," ",(0,s.jsx)("small",{children:"Option Name"})]}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_loadable_drivers"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started",children:(0,s.jsx)(n.code,{children:"TinyDrivers"})})," as a shared library and SQL database drivers (eg. ",(0,s.jsx)(n.code,{children:"TinyMySql"}),") as shared libraries (",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-loadable-sql-drivers-build",children:(0,s.jsx)(n.code,{children:"Loadable"})})," modules) that are loaded at runtime using ",(0,s.jsx)(n.code,{children:"LoadLibrary()"})," on Windows or ",(0,s.jsx)(n.code,{children:"dlopen()"})," on Linux."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_mysql_driver"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," MySQL database driver.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["It's enabled by default when ",(0,s.jsx)(n.code,{children:"build_shared_drivers"}),", ",(0,s.jsx)(n.code,{children:"build_loadable_drivers"}),", or ",(0,s.jsx)(n.code,{children:"build_static_drivers"})," is enabled.",(0,s.jsx)("br",{}),"Available when: ",(0,s.jsx)(n.code,{children:"build_shared_drivers"})," OR ",(0,s.jsx)(n.code,{children:"build_loadable_drivers"})," OR ",(0,s.jsx)(n.code,{children:"build_static_drivers"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_shared_drivers"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," as a ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-shared-library-build",children:(0,s.jsx)(n.code,{children:"Shared"})})," library."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_static_drivers"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," as a ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-static-build",children:(0,s.jsx)(n.code,{children:"Static"})})," library archive.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["The ",(0,s.jsx)(n.code,{children:"build_static_drivers"})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option will be select by default when the ",(0,s.jsx)(n.a,{href:"#qmake-static",children:(0,s.jsx)(n.code,{children:"CONFIG*=static"})})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_tests"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsx)(n.td,{children:"Build TinyORM unit tests."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ccache"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Enable compiler cache. ",(0,s.jsx)(n.a,{href:"https://ccache.dev/",children:"Homepage"}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["It works on Windows and Unix systems. This option overrides qmake's ",(0,s.jsx)(n.code,{children:"ccache"})," option. It internally calls qmake's ",(0,s.jsx)(n.a,{href:"#qmake-ccache",children:(0,s.jsx)(n.code,{children:"ccache"})})," option on Unix and ",(0,s.jsx)(n.a,{href:"#tiny_ccache_win32",children:(0,s.jsx)(n.code,{children:"tiny_ccache_win32"})})," on Windows.",(0,s.jsx)("br",{}),"Reason: It allows using the same option on both OS-es."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_autoconf"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Disable the ",(0,s.jsx)(n.a,{href:"#auto-configuration-internals",children:(0,s.jsx)(n.code,{children:"Auto-configuration"})})," feature ",(0,s.jsxs)("small",{children:["(auto-configuration is enabled by default from ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"}),")"]}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_dotenv"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Disable the ",(0,s.jsx)(n.a,{href:"#environment-files",children:(0,s.jsx)(n.code,{children:"tiny_dotenv"})})," feature ",(0,s.jsxs)("small",{children:["(environment files are enabled by default from ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"}),")"]}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_thread_local"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Remove all ",(0,s.jsx)(n.a,{href:"https://en.cppreference.com/w/c/language/storage_duration",children:(0,s.jsx)(n.code,{children:"thread_local"})})," storage duration specifiers, it disables multi-threading support."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_orm"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"ORM-related"})," source code, when this option is ",(0,s.jsx)(n.code,{children:"enabled"}),", then only the ",(0,s.jsx)(n.code,{children:"query builder"})," without ",(0,s.jsx)(n.code,{children:"ORM"})," is compiled. Also excludes ",(0,s.jsx)(n.code,{children:"ORM-related"})," unit tests."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_tom"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"Tom-related"})," source code, when this option is ",(0,s.jsx)(n.code,{children:"disabled"}),", then it also excludes ",(0,s.jsx)(n.code,{children:"Tom-related"})," unit tests."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"extern_constants"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Use ",(0,s.jsx)(n.code,{children:"extern"})," constants instead of ",(0,s.jsx)(n.code,{children:"inline"})," constants in the ",(0,s.jsx)(n.code,{children:"shared build"}),".",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"ON"})," is highly recommended for the ",(0,s.jsx)(n.code,{children:"shared build"})," ",(0,s.jsx)("small",{children:"(by default)"}),";",(0,s.jsx)("br",{}),"is always ",(0,s.jsx)(n.code,{children:"OFF"})," for the ",(0,s.jsx)(n.code,{children:"static build"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)("code",{children:"CONFIG(shared|dll):!inline_constants"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"inline_constants"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Use ",(0,s.jsx)(n.code,{children:"inline"})," constants instead of ",(0,s.jsx)(n.code,{children:"extern"})," constants in the ",(0,s.jsx)(n.code,{children:"shared build"}),".",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"OFF"})," is highly recommended for the ",(0,s.jsx)(n.code,{children:"shared build"}),";",(0,s.jsx)("br",{}),"is always ",(0,s.jsx)(n.code,{children:"ON"})," for the ",(0,s.jsx)(n.code,{children:"static build"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"link_pkgconfig_off"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Link against ",(0,s.jsx)(n.code,{children:"mysqlclient"})," or ",(0,s.jsx)(n.code,{children:"libmariadb"})," with ",(0,s.jsx)(n.code,{children:"PKGCONFIG"}),".",(0,s.jsx)("br",{}),"Used only in the ",(0,s.jsx)(n.code,{children:"Unix"})," and ",(0,s.jsx)(n.code,{children:"MinGW"})," ",(0,s.jsx)(n.strong,{children:"shared"})," build ",(0,s.jsxs)("small",{children:["(exactly ",(0,s.jsx)("code",{children:"win32-g++|win32-clang-g++"}),")"]})," and when ",(0,s.jsx)(n.code,{children:"mysql_ping"})," is also defined to link against ",(0,s.jsx)(n.code,{children:"mysqlclient"})," or ",(0,s.jsx)(n.code,{children:"libmariadb"}),", ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L132",children:"source code"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)(n.code,{children:"unix:mysql_ping"})," or ",(0,s.jsx)("code",{children:"(win32-g++|win32-clang-g++):mysql_ping:!static:!staticlib"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"mysql_ping"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Enable ",(0,s.jsx)(n.code,{children:"Orm::MySqlConnection::pingDatabase()"})," method."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"tiny_ccache_win32"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Enable compiler cache. ",(0,s.jsx)(n.a,{href:"https://ccache.dev/",children:"Homepage"}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["It works only on Windows systems. It works well with the MSYS2 ",(0,s.jsx)(n.code,{children:"g++"}),", ",(0,s.jsx)(n.code,{children:"clang++"}),", ",(0,s.jsx)(n.code,{children:"msvc"}),", and ",(0,s.jsx)(n.code,{children:"clang-cl"})," with ",(0,s.jsx)(n.code,{children:"msvc"}),". It disables ",(0,s.jsx)(n.code,{children:"precompile_header"})," as they are not supported on Windows and changes the ",(0,s.jsx)(n.code,{children:"-Zi"})," compiler option to the ",(0,s.jsx)(n.code,{children:"-Z7"})," for debug builds as the ",(0,s.jsx)(n.code,{children:"-Zi"})," compiler option is not supported (",(0,s.jsx)(n.a,{href:"https://github.com/ccache/ccache/issues/1040",children:"link"})," to the issue)."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"tom_example"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build the ",(0,s.jsx)("abbr",{title:"TinyORM Migrations",children:(0,s.jsx)(n.code,{children:"tom"})})," console application example."]})]})]})]})})}),"\n",(0,s.jsxs)(n.p,{children:["Advanced ",(0,s.jsx)(n.code,{children:"TinyORM"})," options."]}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Option Name"}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsx)(n.tbody,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ubsan"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Allows to enable ",(0,s.jsx)(n.a,{href:"https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html",children:"UBSan"})," sanitizer (Clang only)."]})]})})]})})}),"\n",(0,s.jsxs)(n.p,{children:["Important ",(0,s.jsx)(n.code,{children:"qmake"})," options."]}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{name:"qmake",children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsxs)(n.th,{children:[(0,s.jsx)(n.code,{children:"CONFIG"})," ",(0,s.jsx)("small",{children:"Option Name"})]}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ccache"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Enable compiler cache. ",(0,s.jsx)(n.a,{href:"https://ccache.dev/",children:"Homepage"}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["It works only on the Unix systems. It works well with ",(0,s.jsx)(n.code,{children:"g++"})," and ",(0,s.jsx)(n.code,{children:"clang++"})," and also supports precompiled headers."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"precompile_header"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Enable precompiled headers, you can disable them with:",(0,s.jsx)("br",{})," ",(0,s.jsx)(n.code,{children:"CONFIG-=precompile_header"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["The ",(0,s.jsx)(n.code,{children:"precompile_header"})," is enabled by default on ",(0,s.jsx)(n.code,{children:"msvc"}),", ",(0,s.jsx)(n.code,{children:"g++"}),", ",(0,s.jsx)(n.code,{children:"clang++"}),", ",(0,s.jsx)(n.code,{children:"clang-cl"})," on ",(0,s.jsx)(n.code,{children:"Windows"})," and disabled by default on ",(0,s.jsx)(n.code,{children:"linux"}),"."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsxs)(n.td,{children:[(0,s.jsx)(n.code,{children:"static"}),(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"staticlib"})]}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build as a ",(0,s.jsx)(n.code,{children:"static"})," library (lib only).",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["If you want to build all libraries in the ",(0,s.jsx)(n.code,{children:"TinyORM"})," project as static library archives and link against static libraries use the ",(0,s.jsx)(n.a,{href:"https://doc.qt.io/qt/qmake-variable-reference.html#config",children:(0,s.jsx)(n.code,{children:"CONFIG += static"})}),". Don't use the ",(0,s.jsx)(n.code,{children:"CONFIG += staticlib"}),".",(0,s.jsx)("br",{}),"See ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/NOTES.txt",children:"NOTES.txt"})," for more information (search ",(0,s.jsx)(n.code,{children:"static vs staticlib"}),")."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"static_runtime"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Link against the ",(0,s.jsx)(n.code,{children:"shared"})," (dynamic) or ",(0,s.jsx)(n.code,{children:"static"})," run-time library.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["The ",(0,s.jsx)(n.code,{children:"-MD"})," becomes ",(0,s.jsx)(n.code,{children:"-MT"})," and ",(0,s.jsx)(n.code,{children:"-MDd"})," becomes ",(0,s.jsx)(n.code,{children:"-MTd"}),". It works only on ",(0,s.jsx)(n.code,{children:"MSVC"})," and ",(0,s.jsx)(n.code,{children:"MinGW"})," or ",(0,s.jsx)(n.code,{children:"MSYS2"}),".",(0,s.jsx)("br",{}),"Please ",(0,s.jsx)("u",{children:"don't use"})," this option.",(0,s.jsx)("br",{}),"Available when: ",(0,s.jsx)(n.code,{children:"msvc"})," or ",(0,s.jsx)(n.code,{children:"mingw"})]})]})]})]})]})})}),"\n",(0,s.jsxs)(n.h3,{id:"consume-tinyorm-library-qmake",children:["Consume TinyOrm library ",(0,s.jsx)("small",{children:"(qmake)"})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/qmake/TinyOrm.pri",children:(0,s.jsx)(n.code,{children:"TinyOrm.pri"})})," file is available to simplify the integration of the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library into your application. It sets up and configures the ",(0,s.jsx)(n.code,{children:"CONFIG"})," and ",(0,s.jsx)(n.code,{children:"DEFINES"})," qmake variables, adds the ",(0,s.jsx)(n.code,{children:"TinyORM"}),", ",(0,s.jsx)("abbr",{title:"TinyORM Migrations",children:(0,s.jsx)(n.code,{children:"tom"})}),", and ",(0,s.jsx)(n.code,{children:"vcpkg"})," header files on the system ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," (cross-platform using the ",(0,s.jsx)(n.code,{children:"-isystem"})," or ",(0,s.jsx)(n.code,{children:"-imsvc"}),"), links against the TinyORM ",(0,s.jsx)(n.code,{children:"shared"})," or ",(0,s.jsx)(n.code,{children:"static"})," library using the ",(0,s.jsx)(n.code,{children:"LIBS"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["You can use it to configure the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library when you are linking against it. It does a very similar thing like the CMake's ",(0,s.jsx)(n.code,{children:"Find Modules"})," feature."]}),"\n",(0,s.jsx)(n.h4,{id:"requirements",children:"Requirements"}),"\n",(0,s.jsx)(n.p,{children:"It has a few requirements, you need to:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["specify path to the ",(0,s.jsx)(n.code,{children:"TinyORM"})," qmake features (",(0,s.jsx)(n.code,{children:".prf"})," files) using the ",(0,s.jsx)(n.code,{children:"QMAKEFEATURES"})," variable that can only be set in the ",(0,s.jsx)(n.code,{children:".qmake.conf"})," file"]}),"\n",(0,s.jsxs)(n.li,{children:["specify ",(0,s.jsx)(n.code,{children:"qmake"})," or ",(0,s.jsx)(n.code,{children:"environment"})," variables to find the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation ",(0,s.jsxs)("small",{children:["(",(0,s.jsx)(n.code,{children:"TINY_VCPKG_ROOT"})," and ",(0,s.jsx)(n.code,{children:"TINY_VCPKG_TRIPLET"}),")"]})]}),"\n",(0,s.jsxs)(n.li,{children:["specify path to the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build folder ",(0,s.jsxs)("small",{children:["(",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"}),")"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["you can specify it ",(0,s.jsx)(n.strong,{children:"manually"})]}),"\n",(0,s.jsxs)(n.li,{children:["or you can use ",(0,s.jsxs)(n.a,{href:"#partial-guessing-of-the-tinyorm_build_tree",children:["Partial guessing of the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})]})]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["build your application with the same ",(0,s.jsx)(n.code,{children:"CONFIG"})," ",(0,s.jsx)(n.code,{children:"qmake"})," variables that were used when building the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library"]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"Let's explain one by one."}),"\n",(0,s.jsx)(n.h5,{id:"qmakefeatures",children:(0,s.jsx)(n.code,{children:"QMAKEFEATURES"})}),"\n",(0,s.jsxs)(n.p,{children:["Create the ",(0,s.jsx)(n.code,{children:".qmake.conf"})," file in your application root folder with the following content."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"title='.qmake.conf'",children:"# Path to the PARENT folder of the TinyORM source folder\nTINY_MAIN_DIR = $$clean_path()\n# To find .env and .env.$$QMAKE_PLATFORM files in YOUR project\nTINY_DOTENV_ROOT = $$PWD\n\n# Path to the TinyORM build folder (specified manually)\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSVC2019_64bit-Debug/)\n# vcpkg - range-v3 and tabulate\nTINY_VCPKG_ROOT = $$quote(/vcpkg/)\n#TINY_VCPKG_TRIPLET = x64-windows\n\n# To find .prf files, needed by eg. CONFIG += tiny_system_headers inline/extern_constants\nQMAKEFEATURES *= $$quote($$TINY_MAIN_DIR/TinyORM/qmake/features)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["You can move all ",(0,s.jsx)(n.code,{children:"qmake"})," variables that are part of the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration process to the ",(0,s.jsx)(n.code,{children:".env"})," file if you want (recommended), this is possible because the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," enables the ",(0,s.jsx)(n.a,{href:"#environment-files",children:(0,s.jsx)(n.code,{children:"Environment files"})})," feature by default."]}),"\n",(0,s.jsxs)(n.p,{children:["You can look at the ",(0,s.jsx)(n.a,{href:"/building/hello-world#auto-configure-using-qmake_conf-and-env",children:"Auto-configure using .qmake.conf and .env"})," example for ",(0,s.jsx)(n.code,{children:"Hello world"})," project of what must stay in the ",(0,s.jsx)(n.code,{children:"qmake.conf"})," file and what can be moved to the ",(0,s.jsx)(n.code,{children:".env"})," files."]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsxs)(n.a,{href:"#partial-guessing-of-the-tinyorm_build_tree",children:["Partial guessing of the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})]})," if you don't like to specify it manually."]})}),"\n",(0,s.jsxs)(n.h5,{id:"variables-affecting-tinyormpri",children:["Variables affecting ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})]}),"\n",(0,s.jsxs)(n.p,{children:["You must define the following variables before the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," is included:"]}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build folder."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_ROOT"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation folder.",(0,s.jsx)("br",{}),"If not defined, then it tries to use the ",(0,s.jsx)(n.code,{children:"VCPKG_ROOT"})," environment variable."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_TRIPLET"})}),(0,s.jsxs)(n.td,{children:["The ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"triplet"})," to use ",(0,s.jsx)("small",{children:"(vcpkg/installed/$$TINY_VCPKG_TRIPLET/)"}),".",(0,s.jsx)("br",{}),"If not defined, then it tries to guess the ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"triplet"})," based on the current compiler and OS (based on the ",(0,s.jsx)(n.code,{children:"QMAKESPEC"}),"), and as the last thing, it tries to use the ",(0,s.jsx)(n.code,{children:"VCPKG_DEFAULT_TRIPLET"})," environment variable."]})]})]})]}),"\n",(0,s.jsx)(n.p,{children:"These variables will be set after the configuration is done:"}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_BUILD_SUBFOLDER"})}),(0,s.jsxs)(n.td,{children:["Folder by release type if ",(0,s.jsx)(n.code,{children:"CONFIG+=debug_and_release"})," is defined ",(0,s.jsx)("small",{children:"(/debug, /release, or an empty string)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_CCACHE_BUILD"})}),(0,s.jsxs)(n.td,{children:["To correctly link ",(0,s.jsx)(n.code,{children:"ccache"})," build against a ",(0,s.jsx)(n.code,{children:"ccache"})," build ",(0,s.jsx)("small",{children:"(_ccache or an empty string)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MSVC_VERSION"})}),(0,s.jsxs)(n.td,{children:["The ",(0,s.jsx)(n.code,{children:"msvc"})," compiler string ",(0,s.jsx)("small",{children:"(MSVC2022 or MSVC2019)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_QT_VERSION_UNDERSCORED"})}),(0,s.jsxs)(n.td,{children:["Underscored ",(0,s.jsx)(n.code,{children:"Qt"})," version ",(0,s.jsx)("small",{children:"(eg. 6_7_0)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_RELEASE_TYPE_CAMEL"})}),(0,s.jsxs)(n.td,{children:["Build type string ",(0,s.jsx)("small",{children:"(Debug, Profile, or Release)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_INCLUDE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"include"})," folder ",(0,s.jsx)("small",{children:"(vcpkg/installed//include/)"}),"."]})]})]})]}),"\n",(0,s.jsxs)(n.p,{children:["Then you simply include the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," in your project file."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"title='AnyProject.pro'",children:"include($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["And that is all, now you should be able to link against the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. \ud83d\udc4c"]}),"\n",(0,s.jsx)(n.h5,{id:"manual-configuration-examples",children:"Manual configuration examples"}),"\n",(0,s.jsxs)(n.p,{children:["Frankly, there is no reason to use the Manual configuration (define the variables described below before the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," inclusion), the only reason to use it is when you want more control over this process or want to define everything yourself. I'll leave this section here to show how things work."]}),"\n",(0,s.jsxs)(n.p,{children:["You will have to link against the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library manually if you don't set the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})," ",(0,s.jsx)(n.code,{children:"qmake"})," variable before the inclusion of the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," file. The ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," is auto-detected every time."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"{9}",children:"# Link against TinyORM library\n# ---\nTINY_MAIN_DIR = $$clean_path()\n\n# Configure TinyORM library\ninclude($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n\n# TinyORM library path\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake)\nLIBS += $$quote(-L$$TINYORM_BUILD_TREE/build-TinyORM-Desktop_Qt_6_7_0_MSVC2019_64bit-Debug/src$${TINY_BUILD_SUBFOLDER}/)\nLIBS += -lTinyOrm\n"})})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"{9}",children:"# Link against TinyORM library\n# ---\nTINY_MAIN_DIR = $$clean_path()\n\n# Configure TinyORM library\ninclude($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n\n# TinyORM library path\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake)\nLIBS += $$quote(-L$$TINYORM_BUILD_TREE/build-TinyORM-Desktop_Qt_6_7_0_GCC_64bit-Debug/src$${TINY_BUILD_SUBFOLDER}/)\nLIBS += -lTinyOrm\n"})})})]}),"\n",(0,s.jsxs)(n.p,{children:["The same is true for the ",(0,s.jsx)(n.code,{children:"vcpkg"})," include path. If you don't set the ",(0,s.jsx)(n.code,{children:"TINY_VCPKG_ROOT"})," or have not defined the ",(0,s.jsx)(n.code,{children:"VCPKG_ROOT"})," environment variable, then you need to set up the ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," for the ",(0,s.jsx)(n.code,{children:"vcpkg"})," that provides the ",(0,s.jsx)(n.code,{children:"range-v3"})," and ",(0,s.jsx)(n.code,{children:"tabulate"})," header files."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",children:"# vcpkg - range-v3 and tabulate\n# ---\nINCLUDEPATH += $$quote(/vcpkg/installed/x64-windows/include/)\n"})})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",children:"# vcpkg - range-v3 and tabulate\n# ---\nQMAKE_CXXFLAGS += -isystem $$shell_quote(/vcpkg/installed/x64-linux/include/)\n"})})})]}),"\n",(0,s.jsxs)(n.p,{children:["You can also use TinyORM's ",(0,s.jsx)(n.code,{children:"qmake"})," function ",(0,s.jsx)(n.code,{children:"tiny_add_system_includepath()"})," which handles ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," in a cross-platform way."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",children:"# vcpkg - range-v3 and tabulate\n# ---\nload(tiny_system_includepath)\ntiny_add_system_includepath(/vcpkg/installed/x64-linux/include/)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["Do not forget to add ",(0,s.jsx)(n.code,{children:"TinyOrm0.dll"})," on the path on Windows and on the ",(0,s.jsx)(n.code,{children:"LD_LIBRARY_PATH"})," on Linux, so your application can find it during execution."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,name:"tinyorm-on-path",children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`$env:Path = "${(0,x.OZ)(y.b,!1)}\\TinyORM\\TinyORM-builds-qmake\\build-debug;" + $env:Path`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`export LD_LIBRARY_PATH=${(0,x.OZ)(y.xj)}/TinyORM/TinyORM-builds-qmake/build-debug\${PATH:+:}$PATH`})})]}),"\n",(0,s.jsxs)(n.admonition,{type:"tip",children:[(0,s.jsxs)(n.p,{children:["On Linux ",(0,s.jsx)(n.code,{children:"-isystem"})," marks the directory as a system directory, it prevents warnings."]}),(0,s.jsxs)(n.p,{children:["On Windows you can use ",(0,s.jsx)(n.code,{children:"QMAKE_CXXFLAGS_WARN_ON = -external:anglebrackets -external:W0"}),", it applies a warning level 0 to the angel bracket includes; ",(0,s.jsx)(n.code,{children:"#include "}),"."]}),(0,s.jsxs)(n.p,{children:["With the ",(0,s.jsx)(n.code,{children:"clang-cl"})," with ",(0,s.jsx)(n.code,{children:"MSVC"})," you can use ",(0,s.jsx)(n.code,{children:"-imsvc"}),"."]})]}),"\n",(0,s.jsx)(n.h3,{id:"auto-configuration-internals",children:"Auto-configuration internals"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"qmake"})," build system does not support ",(0,s.jsx)(n.code,{children:"auto-configuration"})," of dependencies out of the box but ",(0,s.jsx)(n.code,{children:"TinyORM"})," from ",(0,s.jsx)(n.code,{children:"v0.34.0"})," added its own ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature along with the ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," qmake feature. These new features allow us to ",(0,s.jsx)(n.code,{children:"auto-configure"})," ",(0,s.jsx)(n.code,{children:"TinyORM"})," project, and with their help, the ",(0,s.jsx)(n.code,{children:"conf.pri"})," files can be ",(0,s.jsx)("u",{children:"skipped entirely"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["While it adds additional complexity to the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration process, the benefits are significant."]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature is designed to find the ",(0,s.jsx)(n.code,{children:"vcpkg"})," and ",(0,s.jsx)(n.code,{children:"MySQL"})," installations, and ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," to include the ",(0,s.jsx)(n.code,{children:".env"})," and ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw)"})," files in the project's root folder. These new features can be configured using ",(0,s.jsx)(n.code,{children:"qmake"})," and ",(0,s.jsx)(n.code,{children:"environment"})," variables, and they also contain some guessing logic if these variables are not defined."]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature can be turned off using the ",(0,s.jsx)(n.a,{href:"#disable_autoconf",children:(0,s.jsx)(n.code,{children:"disable_autoconf"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_autoconf"}),")."]}),"\n",(0,s.jsxs)(n.p,{children:["These are ",(0,s.jsx)("u",{children:(0,s.jsx)(n.code,{children:"qmake"})})," and ",(0,s.jsx)("u",{children:(0,s.jsx)(n.code,{children:"environment"})})," variables that affect the ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature:"]}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_ROOT"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation folder.",(0,s.jsx)("br",{}),"If not defined, then it tries to use the ",(0,s.jsx)(n.code,{children:"VCPKG_ROOT"})," environment variable."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_TRIPLET"})}),(0,s.jsxs)(n.td,{children:["The ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"triplet"})," to use ",(0,s.jsx)("small",{children:"(vcpkg/installed/$$TINY_VCPKG_TRIPLET/)"}),".",(0,s.jsx)("br",{}),"If not defined, then it tries to guess the ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"triplet"})," based on the current compiler and OS (based on the ",(0,s.jsx)(n.code,{children:"QMAKESPEC"}),"), and as the last thing, it tries to use the ",(0,s.jsx)(n.code,{children:"VCPKG_DEFAULT_TRIPLET"})," environment variable."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MYSQL_ROOT"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"MySQL"})," installation folder.",(0,s.jsx)("br",{}),"If not defined, then it tries to guess the ",(0,s.jsx)(n.code,{children:"MySQL"})," installation folder (",(0,s.jsx)(n.code,{children:"win32"})," only): ",(0,s.jsx)("code",{children:"$$(ProgramFiles)/MySQL/MySQL Server (8.3|8.2|8.1|8.0|5.7)/"})]})]})]})]}),"\n",(0,s.jsxs)(n.p,{children:["You can set these variables in the ",(0,s.jsx)(n.code,{children:".env"})," (recommended) or ",(0,s.jsx)(n.code,{children:"conf.pri"})," files, in the ",(0,s.jsx)(n.code,{children:".qmake.conf"})," file (or wherever you want), or as environment variables."]}),"\n",(0,s.jsxs)(n.p,{children:["These variables will be set after ",(0,s.jsx)(n.code,{children:"auto-configuration"})," is done:"]}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_INCLUDE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"include"})," folder ",(0,s.jsx)("small",{children:"(vcpkg/installed//include/)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MYSQL_INCLUDE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"MySQL"})," ",(0,s.jsx)(n.code,{children:"include"})," folder ",(0,s.jsx)("small",{children:"(MySQL Server 8.3/include/)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MYSQL_LIB"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"MySQL"})," ",(0,s.jsx)(n.code,{children:"lib"})," folder ",(0,s.jsx)("small",{children:"(MySQL Server 8.3/lib/)"}),"."]})]})]})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"TINY_MYSQL_INCLUDE"})," and ",(0,s.jsx)(n.code,{children:"TINY_MYSQL_LIB"})," are only set on ",(0,s.jsx)(n.code,{children:"win32"})," platform except ",(0,s.jsx)(n.code,{children:"mingw"}),"."]}),"\n",(0,s.jsx)(n.h4,{id:"environment-files",children:"Environment files"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," feature allows us to define the ",(0,s.jsx)(n.code,{children:".env"})," and ",(0,s.jsx)(n.code,{children:".env.$$TINY_DOTENV_PLATFORM"})," files in the project's root folder. These files are loaded as early as possible so you can affect the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration process. On the other hand, the ",(0,s.jsx)(n.code,{children:"conf.pri"})," files are loaded as late as possible, and they can be used to override the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration."]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:".env"})," file is included ",(0,s.jsx)("u",{children:"first"})," and is included on all platforms."]}),"\n",(0,s.jsxs)(n.p,{children:["There is only one requirement for this feature to work correctly, and that is to set the ",(0,s.jsx)(n.code,{children:"TINY_DOTENV_ROOT"})," ",(0,s.jsx)(n.code,{children:"qmake"})," variable to the project's root folder. This variable is ",(0,s.jsx)(n.strong,{children:"already"})," set in the ",(0,s.jsx)(n.code,{children:".qmake.conf"})," file for the ",(0,s.jsx)(n.code,{children:"TinyORM"})," project."]}),"\n",(0,s.jsx)(n.p,{children:"Then the following names are taken into account: .env, .env.win32, .env.unix, .env.mingw"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"title='.qmake.conf'",children:"# To find .env and .env.$$QMAKE_PLATFORM files\nTINY_DOTENV_ROOT = $$PWD\n"})}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," feature can be turned off using the ",(0,s.jsx)(n.a,{href:"#disable_dotenv",children:(0,s.jsx)(n.code,{children:"disable_dotenv"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_dotenv"}),")."]}),"\n",(0,s.jsx)(n.admonition,{type:"warning",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Environment files"})," don't work in the ",(0,s.jsx)(n.code,{children:"CMake"})," builds."]})}),"\n",(0,s.jsxs)(n.h4,{id:"partial-guessing-of-the-tinyorm_build_tree",children:["Partial guessing of the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})]}),"\n",(0,s.jsxs)(n.p,{children:["You don't have to manually define the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})," in ",(0,s.jsx)(n.code,{children:".env"})," or ",(0,s.jsx)(n.code,{children:".qmake.conf"})," files. The ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})," absolute path can be put together for you (this is happening inside the ",(0,s.jsx)(n.code,{children:"variables.pri"})," file) and ",(0,s.jsx)(n.code,{children:"TinyORM"})," build folder name can be guessed for you too."]}),"\n",(0,s.jsxs)(n.p,{children:["You must define the following variables before the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," will be included to make this real (set them in the ",(0,s.jsx)(n.code,{children:".qmake.conf"}),"):"]}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MAIN_DIR"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.strong,{children:"PARENT"})," folder of the ",(0,s.jsx)(n.code,{children:"TinyORM"})," source folder."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_BUILD_TREE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.strong,{children:"current"})," build tree - ",(0,s.jsx)(n.code,{children:"TINY_BUILD_TREE = $$shadowed($$PWD)"}),"."]})]})]})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"TINY_MAIN_DIR"})," is required for another features anyway (so it should already be set) and all that's left is to set the ",(0,s.jsx)(n.code,{children:"TINY_BUILD_TREE"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"title='.qmake.conf'",children:"# Path to the current build tree (used to guess the TinyORM build tree)\nTINY_BUILD_TREE = $$shadowed($$PWD)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If you will follow this pattern or logic then you can switch ",(0,s.jsx)(n.code,{children:"QtCreator Kits"})," and the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})," will be ",(0,s.jsx)(n.strong,{children:"auto-generated"})," correctly and will always point to the correct ",(0,s.jsx)(n.code,{children:"TinyORM"})," build tree."]}),"\n",(0,s.jsxs)(n.p,{children:["It works this way, all is happening inside the ",(0,s.jsx)(n.code,{children:"variables.pri"}),", it takes a build folder name for the ",(0,s.jsx)(n.strong,{children:"current"})," project eg. ",(0,s.jsx)(n.code,{children:"build-HelloWorld-Desktop_Qt_6_7_0_MSVC2022_64bit-Debug"}),", replaces the ",(0,s.jsx)(n.code,{children:"HelloWorld"})," with the ",(0,s.jsx)(n.code,{children:"TinyORM"})," and as we already know the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build folder location we can simply concatenate these paths like ",(0,s.jsx)(n.code,{children:"$$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSVC2022_64bit-Debug"}),"."]}),"\n",(0,s.jsx)(n.admonition,{type:"warning",children:(0,s.jsxs)(n.p,{children:["This will only work if you follow the recommended ",(0,s.jsx)(n.a,{href:"#folders-structure",children:(0,s.jsx)(n.code,{children:"Folders structure"})}),"."]})}),"\n",(0,s.jsx)(n.h3,{id:"manual-configuration-internals",children:"Manual configuration internals"}),"\n",(0,s.jsxs)(n.p,{children:["There is not much to say about the ",(0,s.jsx)(n.code,{children:"Manual configuration"})," feature. It uses ",(0,s.jsx)(n.code,{children:"conf.pri"})," files (there are four, one for every project or sub-project), and every project has prepared its own ",(0,s.jsx)(n.code,{children:"conf.pri.example"})," file for faster initial configuration."]}),"\n",(0,s.jsxs)(n.p,{children:["These ",(0,s.jsx)(n.code,{children:"conf.pri.example"})," files are nicely commented on, so you can see what needs to be modified. The ",(0,s.jsx)(n.code,{children:"conf.pri"})," files are loaded as late as possible, and they can be used to override the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration."]}),"\n",(0,s.jsxs)(n.p,{children:["If the ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature is disabled and there are no ",(0,s.jsx)(n.code,{children:"conf.pri"})," files, then the ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration or build will fail at 100%."]}),"\n",(0,s.jsxs)(n.p,{children:["These ",(0,s.jsx)(n.code,{children:"conf.pri"})," files are intended for configuring qmake's ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," and ",(0,s.jsx)(n.code,{children:"LIBS"}),", ",(0,s.jsx)(n.code,{children:"CONFIG"})," or eg. ",(0,s.jsx)(n.code,{children:"QMAKE_LFLAGS"}),", or any other ",(0,s.jsx)(n.code,{children:"qmake"})," options or variables."]}),"\n",(0,s.jsx)(n.h2,{id:"ccache-support",children:"Ccache support"}),"\n",(0,s.jsxs)(n.p,{children:["The TinyORM supports the ",(0,s.jsx)(n.a,{href:"https://ccache.dev/",children:(0,s.jsx)(n.code,{children:"ccache"})})," out of the box for all ",(0,s.jsx)(n.a,{href:"/supported-compilers",children:"supported compilers"}),". For ",(0,s.jsx)(n.code,{children:"qmake"})," you can enable it using the ",(0,s.jsx)(n.a,{href:"#ccache",children:(0,s.jsx)(n.code,{children:"CONFIG+=ccache"})})," and for ",(0,s.jsx)(n.code,{children:"CMake"})," you can set the ",(0,s.jsx)(n.a,{href:"#CMAKE_CXX_COMPILER_LAUNCHER",children:(0,s.jsx)(n.code,{children:"CMAKE_CXX_COMPILER_LAUNCHER=ccache"})}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["On ",(0,s.jsx)(n.code,{children:"Linux"})," it's clear, the ",(0,s.jsx)(n.code,{children:"ccache"})," is fully supported and works also with the ",(0,s.jsx)(n.code,{children:"precompiled headers"}),". But was necessary to add some workarounds to the ",(0,s.jsx)(n.code,{children:"qmake"}),"/",(0,s.jsx)(n.code,{children:"CMake"})," build systems to make out of the box support on ",(0,s.jsx)(n.code,{children:"Windows"}),". When you enable the ",(0,s.jsx)(n.code,{children:"ccache"})," on ",(0,s.jsx)(n.code,{children:"Windows"})," then the build system disables ",(0,s.jsx)(n.code,{children:"precompiled headers"})," and replaces the ",(0,s.jsx)(n.code,{children:"-Zi"})," compiler option with the ",(0,s.jsx)(n.code,{children:"-Z7"})," (link to the ",(0,s.jsx)(n.a,{href:"https://github.com/ccache/ccache/issues/1040",children:"issue"}),")."]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can install the ",(0,s.jsx)(n.code,{children:"ccache"})," using the ",(0,s.jsx)(n.code,{children:"scoop install ccache"})," command on Windows. See the ",(0,s.jsx)(n.a,{href:"/dependencies#linux-installation-ccache",children:"Dependencies"})," page for how to install ",(0,s.jsx)(n.code,{children:"ccache"})," on Linux."]})})]})}function I(e={}){const{wrapper:n}={...(0,d.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(M,{...e})}):M(e)}},9365:(e,n,i)=>{i.d(n,{A:()=>l});i(6540);var s=i(4164);const d={tabItem:"tabItem_Ymn6"};var r=i(4848);function l(e){let{children:n,hidden:i,className:l}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(d.tabItem,l),hidden:i,children:n})}},1470:(e,n,i)=>{i.d(n,{A:()=>_});var s=i(6540),d=i(4164),r=i(3104),l=i(6347),c=i(205),t=i(7485),o=i(1682),a=i(9466);function h(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function x(e){const{values:n,children:i}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return h(e).map((e=>{let{props:{value:n,label:i,attributes:s,default:d}}=e;return{value:n,label:i,attributes:s,default:d}}))}(i);return function(e){const n=(0,o.X)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,i])}function j(e){let{value:n,tabValues:i}=e;return i.some((e=>e.value===n))}function u(e){let{queryString:n=!1,groupId:i}=e;const d=(0,l.W6)(),r=function(e){let{queryString:n=!1,groupId:i}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!i)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return i??null}({queryString:n,groupId:i});return[(0,t.aZ)(r),(0,s.useCallback)((e=>{if(!r)return;const n=new URLSearchParams(d.location.search);n.set(r,e),d.replace({...d.location,search:n.toString()})}),[r,d])]}function p(e){const{defaultValue:n,queryString:i=!1,groupId:d}=e,r=x(e),[l,t]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:i}=e;if(0===i.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!j({value:n,tabValues:i}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${i.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=i.find((e=>e.default))??i[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:r}))),[o,h]=u({queryString:i,groupId:d}),[p,m]=function(e){let{groupId:n}=e;const i=function(e){return e?`docusaurus.tab.${e}`:null}(n),[d,r]=(0,a.Dv)(i);return[d,(0,s.useCallback)((e=>{i&&r.set(e)}),[i,r])]}({groupId:d}),b=(()=>{const e=o??p;return j({value:e,tabValues:r})?e:null})();(0,c.A)((()=>{b&&t(b)}),[b]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!j({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);t(e),h(e),m(e)}),[h,m,r]),tabValues:r}}var m=i(2303);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=i(4848);function g(e){let{className:n,block:i,selectedValue:s,selectValue:l,tabValues:c}=e;const t=[],{blockElementScrollPositionUntilNextRender:o}=(0,r.a_)(),a=e=>{const n=e.currentTarget,i=t.indexOf(n),d=c[i].value;d!==s&&(o(n),l(d))},h=e=>{let n=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const i=t.indexOf(e.currentTarget)+1;n=t[i]??t[0];break}case"ArrowLeft":{const i=t.indexOf(e.currentTarget)-1;n=t[i]??t[t.length-1];break}}n?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,d.A)("tabs",{"tabs--block":i},n),children:c.map((e=>{let{value:n,label:i,attributes:r}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>t.push(e),onKeyDown:h,onClick:a,...r,className:(0,d.A)("tabs__item",b.tabItem,r?.className,{"tabs__item--active":s===n}),children:i??n},n)}))})}function y(e){let{lazy:n,children:i,selectedValue:d}=e;const r=(Array.isArray(i)?i:[i]).filter(Boolean);if(n){const e=r.find((e=>e.props.value===d));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:r.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==d})))})}function T(e){const n=p(e);return(0,f.jsxs)("div",{className:(0,d.A)("tabs-container",b.tabList),children:[(0,f.jsx)(g,{...n,...e}),(0,f.jsx)(y,{...n,...e})]})}function _(e){const n=(0,m.A)();return(0,f.jsx)(T,{...e,children:h(e.children)},String(n))}},6684:(e,n,i)=>{i.d(n,{A:()=>a});var s=i(6540),d=i(3427),r=i(6347);const l={apiTable:"apiTable_flxF"};var c=i(4848);function t(e,n){let{name:i,children:l}=e;const t=function(e){let n=e;for(;(0,s.isValidElement)(n);)[n]=s.Children.toArray(n.props.children);if("string"!=typeof n)throw new Error(`Could not extract APITable row name from JSX tree:\n${JSON.stringify(e,null,2)}`);return n}(l),o=i?`${i}-${t}`:t,a=`#${o}`,h=(0,r.W6)();return(0,d.A)().collectAnchor(o),(0,c.jsx)("tr",{id:o,tabIndex:0,ref:h.location.hash===a?n:void 0,onClick:e=>{const n=e.target;[n,n.parentElement].some((e=>"A"===e?.tagName.toUpperCase()))||h.push(a)},onKeyDown:e=>{"Enter"===e.key&&h.push(a)},children:l.props.children})}const o=s.forwardRef(t);function a(e){let{children:n,name:i}=e;if("table"!==n.type)throw new Error("Bad usage of APITable component.\nIt is probably that your Markdown table is malformed.\nMake sure to double-check you have the appropriate number of columns for each table row.");const[d,r]=s.Children.toArray(n.props.children),t=(0,s.useRef)(null);(0,s.useEffect)((()=>{t.current?.focus()}),[t]);const a=s.Children.map(r.props.children,(e=>(0,c.jsx)(o,{name:i,ref:t,children:e})));return(0,c.jsxs)("table",{className:l.apiTable,children:[d,(0,c.jsx)("tbody",{children:a})]})}},7324:(e,n,i)=>{i.d(n,{$E:()=>m,A3:()=>f,CW:()=>b,Dx:()=>a,F4:()=>x,Fi:()=>o,J_:()=>_,LQ:()=>g,Lf:()=>v,OO:()=>d,Q7:()=>y,b:()=>c,cy:()=>t,gg:()=>u,kl:()=>j,os:()=>h,pW:()=>r,ux:()=>p,vf:()=>s,xj:()=>l,xt:()=>T});const s="shell",d="database",r="application",l="bash",c="pwsh",t="zsh",o="maria",a="mysql",h="postgres",x="sqlite",j="application",u="bash",p="pwsh",m="zsh",b="MariaDB",f="MySQL",g="PostgreSQL",y="SQLite",T="tinyorm.org",_="$HOME/Code/c/",v="$env:USERPROFILE\\Code\\c\\"},6362:(e,n,i)=>{i.d(n,{A:()=>r});var s=i(6540),d=i(1838);function r(){const e=(0,s.useContext)(d.A);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6694:(e,n,i)=>{i.d(n,{OZ:()=>t,Sn:()=>l,T3:()=>a,bw:()=>o,nC:()=>h,np:()=>c});var s=i(6362),d=i(2303),r=i(7324);const l=function(e,n){return void 0===n&&(n=!0),x((0,s.A)().rootFolder[e]??o(e),e,n)},c=()=>(0,s.A)().rootFolder[r.pW]??o(r.pW),t=function(e,n){if(void 0===n&&(n=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const i=n||e!==r.b?"/":"\\";return x(l(e)+i+c(),e,n)};function o(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,d.A)())return"";switch(e){case r.b:return r.Lf;case r.xj:return r.J_;case r.pW:return r.xt;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function a(e){return e===r.pW}function h(e,n){if(null==n||""===n)return n;const i="$ENV{$1}$2";switch(e){case r.b:return u(n).replace(/\$env:(.+?)(\/.*)/,i);case r.xj:return n.replace(/\$(.+?)(\/.*)/,i);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function x(e,n,i){if(void 0===i&&(i=!0),null==e||""===e)return e;if(n!==r.b)return j(e);const s=j(e);return i?u(s):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(s)}function j(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function u(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},2721:(e,n,i)=>{i.d(n,{A:()=>s});const s=i.p+"assets/images/qmake-additional_arguments-14d3b6b82ad6d28db5b999a462500a6a.png"},7619:(e,n,i)=>{i.d(n,{A:()=>s});const s=i.p+"assets/images/qmake-build_settings-7caa6d7c86232484b82acb24b5a3a6a7.png"},885:(e,n,i)=>{i.d(n,{A:()=>s});const s=i.p+"assets/images/qmake-configure_project-0b6821ea0523567dab9f21b3215055a3.png"}}]);
\ No newline at end of file
+"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[395],{993:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>O,contentTitle:()=>_,default:()=>I,frontMatter:()=>T,metadata:()=>v,toc:()=>R});var s=i(4848),d=i(8453),r=i(8774),l=i(6684),c=i(2364),t=i(9365),o=i(1470),a=i(5556),h=i.n(a),x=i(6694);function j(e){let{groupId:n}=e;return(0,s.jsx)("span",{children:(0,x.OZ)(n)})}j.propTypes={groupId:h().string.isRequired};const u=j;var p=i(4164),m=i(6362);const b={rootFolderInput:"rootFolderInput_ottS",input:"input_OR7e",application:"application_fjej"};function f(e){let{groupId:n,label:i}=e;const{rootFolder:d,setRootFolder:r}=(0,m.A)(),l=(0,x.T3)(n),c=l?"application":"root",t=l?"\nThis folder name is common for all shells (eg. pwsh, bash, ...)":"";return(0,s.jsx)("form",{name:"tinyorm-root-folder-form",className:(0,p.A)(b.rootFolderInput,b[n],n),onSubmit:e=>{e.preventDefault(),e.stopPropagation()},children:(0,s.jsx)("input",{name:"tinyorm-root-folder-input",className:(0,p.A)(b.input,b[n],n),placeholder:`Enter ${c} folder...`,title:`This ${c} folder will be used in all ${i} examples at tinyorm.org${t}`,onChange:e=>{r(n,e.target.value)},value:d[n]??(0,x.bw)(n)})})}f.propTypes={groupId:h().string.isRequired,label:h().string.isRequired};const g=f;var y=i(7324);const T={sidebar_position:0,sidebar_label:"TinyORM",hide_table_of_contents:!0,description:"How to compile the TinyORM C++ library on Windows and Linux.",keywords:["c++ orm","building","tinyorm"]},_="Building: TinyORM",v={id:"building/tinyorm",title:"Building: TinyORM",description:"How to compile the TinyORM C++ library on Windows and Linux.",source:"@site/docs/building/tinyorm.mdx",sourceDirName:"building",slug:"/building/tinyorm",permalink:"/building/tinyorm",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"TinyORM",hide_table_of_contents:!0,description:"How to compile the TinyORM C++ library on Windows and Linux.",keywords:["c++ orm","building","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Getting Started",permalink:"/tinydrivers/getting-started"},next:{title:"Hello world",permalink:"/building/hello-world"}},O={},R=[{value:"Introduction",id:"introduction",level:2},{value:"Common Prerequisites",id:"common-prerequisites",level:4},{value:"Windows Prerequisites",id:"windows-prerequisites",level:4},{value:"Build environment scripts",id:"build-environment-scripts",level:5},{value:"Allow symbolic links unprivileged",id:"allow-symbolic-links-unprivileged",level:5},{value:"Folders structure",id:"folders-structure",level:2},{value:"Getting started",id:"getting-started",level:2},{value:"vcpkg",id:"vcpkg",level:2},{value:"Set up vcpkg environment",id:"set-up-vcpkg-environment",level:4},{value:"C preprocessor macros",id:"c-preprocessor-macros",level:2},{value:"Building with CMake",id:"building-with-cmake",level:2},{value:"Configure & Build (cmake)",id:"configure-and-build-cmake",level:3},{value:"CMake STRICT_MODE option",id:"cmake-strict_mode-option",level:5},{value:"Build TinyORM",id:"build-tinyorm",level:4},{value:"CMake build options",id:"cmake-build-options",level:3},{value:"Consume TinyOrm library (cmake)",id:"consume-tinyorm-library-cmake",level:3},{value:"Building with qmake",id:"building-with-qmake",level:2},{value:"Install dependencies",id:"install-dependencies",level:3},{value:"Configure & Build (qmake)",id:"configure-and-build-qmake",level:3},{value:"Open QtCreator IDE",id:"open-qtcreator-ide",level:4},{value:"Configure TinyORM",id:"configure-tinyorm",level:4},{value:"Auto-configuration and tiny_dotenv",id:"auto-configuration-and-tiny_dotenv",level:5},{value:"Manual configuration (conf.pri)",id:"manual-configuration-confpri",level:5},{value:"Opening TinyORM.pro (main project file)",id:"opening-tinyormpro-main-project-file",level:5},{value:"Build TinyORM",id:"build-tinyorm-1",level:4},{value:"qmake build options",id:"qmake-build-options",level:3},{value:"Consume TinyOrm library (qmake)",id:"consume-tinyorm-library-qmake",level:3},{value:"Requirements",id:"requirements",level:4},{value:"QMAKEFEATURES",id:"qmakefeatures",level:5},{value:"Variables affecting TinyOrm.pri",id:"variables-affecting-tinyormpri",level:5},{value:"Manual configuration examples",id:"manual-configuration-examples",level:5},{value:"Auto-configuration internals",id:"auto-configuration-internals",level:3},{value:"Environment files",id:"environment-files",level:4},{value:"Partial guessing of the TINYORM_BUILD_TREE",id:"partial-guessing-of-the-tinyorm_build_tree",level:4},{value:"Manual configuration internals",id:"manual-configuration-internals",level:3},{value:"Ccache support",id:"ccache-support",level:2}];function M(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,d.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h1,{id:"building-tinyorm",children:"Building: TinyORM"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"#introduction",children:"Introduction"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#common-prerequisites",children:"Common Prerequisites"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#windows-prerequisites",children:"Windows Prerequisites"})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#folders-structure",children:"Folders structure"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#getting-started",children:"Getting started"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#vcpkg",children:"vcpkg"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#c-preprocessor-macros",children:"C preprocessor macros"})}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"#building-with-cmake",children:"Building with CMake"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#configure-and-build-cmake",children:"Configure & Build"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#cmake-build-options",children:"CMake build options"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#consume-tinyorm-library-cmake",children:"Consume TinyOrm library"})}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"#building-with-qmake",children:"Building with qmake"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#install-dependencies",children:"Install dependencies"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#configure-and-build-qmake",children:"Configure & Build"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#qmake-build-options",children:"qmake build options"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#consume-tinyorm-library-qmake",children:"Consume TinyOrm library"})}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.a,{href:"#auto-configuration-internals",children:"Auto-configuration internals"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#environment-files",children:"Environment files"})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#manual-configuration-internals",children:"Manual configuration internals"})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#ccache-support",children:"Ccache support"})}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsxs)(n.p,{children:["The build systems supported out of the box are ",(0,s.jsx)(n.code,{children:"CMake"})," and ",(0,s.jsx)(n.code,{children:"qmake"}),"."]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["All examples below assume that ",(0,s.jsx)(n.code,{children:"pwsh"})," runs on ",(0,s.jsx)(n.code,{children:"Windows"})," and ",(0,s.jsx)(n.code,{children:"bash"})," runs on ",(0,s.jsx)(n.code,{children:"Linux"}),"."]})}),"\n",(0,s.jsx)(n.h4,{id:"common-prerequisites",children:"Common Prerequisites"}),"\n",(0,s.jsxs)(n.p,{children:["Install the required ",(0,s.jsx)(n.a,{href:"/dependencies",children:"dependencies"})," before starting."]}),"\n",(0,s.jsx)(n.admonition,{type:"warning",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"QSqlDatabase"})," depends on ",(0,s.jsx)(n.code,{children:"QCoreApplication"})," from ",(0,s.jsx)(n.code,{children:"Qt v6.5.3"})," so you must create the ",(0,s.jsx)(n.code,{children:"QCoreApplication"})," instance before you will call anything from the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. \ud83e\udee4 The change was made ",(0,s.jsx)(n.a,{href:"https://github.com/qt/qtbase/commit/8d2bdc9cd5482eace12ba7e45304857bd24db0e6#diff-1d355c25c0b0eddec2be48253407780c4dc510d986739aec61e1ec892ccaf86e",children:"here"}),"."]})}),"\n",(0,s.jsx)(n.h4,{id:"windows-prerequisites",children:"Windows Prerequisites"}),"\n",(0,s.jsx)(n.h5,{id:"build-environment-scripts",children:"Build environment scripts"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Visual Studio"})," does not provide ",(0,s.jsx)(n.code,{children:"vcvars"})," scripts for ",(0,s.jsx)(n.code,{children:"pwsh"}),", you can use ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/tree/main/tools/vcvars64.ps1",children:(0,s.jsx)(n.code,{children:"vcvars64.ps1"})})," provided by ",(0,s.jsx)(n.code,{children:"TinyORM"})," in the ",(0,s.jsx)(n.code,{children:"tools/"})," folder. Place them on the ",(0,s.jsx)(n.code,{children:"$env:Path"})," user/system path and they will be available system-wide."]}),"\n",(0,s.jsxs)(n.p,{children:["The same is true for the ",(0,s.jsx)(n.code,{children:"Qt Framework"}),", it doesn't provide ",(0,s.jsx)(n.code,{children:"qtenv"})," scripts for ",(0,s.jsx)(n.code,{children:"pwsh"})," too. You can create your own script, place it on the ",(0,s.jsx)(n.code,{children:"$env:Path"})," user/system path and it will be available system-wide."]}),"\n",(0,s.jsxs)(n.p,{children:["Here is one simple example for ",(0,s.jsx)(n.code,{children:"pwsh"}),"."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:"qtenv6.ps1",label:"qtenv6.ps1",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"#!/usr/bin/env pwsh\n\nSet-StrictMode -Version 3.0\n\nWrite-Host 'Setting up environment for Qt 6.7.0 usage...' -ForegroundColor Magenta\nWrite-Host\n\n$Script:QtRoot = $env:TINY_QT_ROOT ?? 'C:\\Qt'\n\n$env:Path = \"$Script:QtRoot\\6.7.0\\msvc2019_64\\bin;\" + $env:Path\n\n. vcvars64.ps1\n"})})}),(0,s.jsx)(t.A,{value:"qtenv5.ps1",label:"qtenv5.ps1",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"#!/usr/bin/env pwsh\n\nSet-StrictMode -Version 3.0\n\nWrite-Host 'Setting up environment for Qt 5.15.2 usage...' -ForegroundColor Magenta\nWrite-Host\n\n$Script:QtRoot = $env:TINY_QT_ROOT ?? 'C:\\Qt'\n\n$env:Path = \"$Script:QtRoot\\5.15.2\\msvc2019_64\\bin;\" + $env:Path\n\n. vcvars64.ps1\n"})})})]}),"\n",(0,s.jsxs)(n.p,{children:["And here for ",(0,s.jsx)(n.code,{children:"Linux"}),"."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:"qtenv6",label:"qtenv6",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:'echo \'Setting up environment for Qt 6.7.0 usage...\'\n\nQtRoot="${TINY_QT_ROOT:-/opt/Qt}"\n\nexport PATH="$QtRoot/6.7.0/gcc_64/bin"${PATH:+:}$PATH\nexport LD_LIBRARY_PATH="$QtRoot/6.7.0/gcc_64/lib"${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH\n'})})}),(0,s.jsx)(t.A,{value:"qtenv5",label:"qtenv5",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:'echo \'Setting up environment for Qt 5.15.2 usage...\'\n\nQtRoot="${TINY_QT_ROOT:-/opt/Qt}"\n\nexport PATH="$QtRoot/5.15.2/gcc_64/bin"${PATH:+:}$PATH\nexport LD_LIBRARY_PATH="$QtRoot/5.15.2/gcc_64/lib"${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH\n'})})})]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["These scripts consider the ",(0,s.jsx)(n.code,{children:"TINY_QT_ROOT"})," environment variable that should point to the ",(0,s.jsx)(n.code,{children:"Qt"})," installation folder, you can define this environment variable globally in your OS."]})}),"\n",(0,s.jsx)(n.h5,{id:"allow-symbolic-links-unprivileged",children:"Allow symbolic links unprivileged"}),"\n",(0,s.jsxs)(n.p,{children:["Open ",(0,s.jsx)(n.code,{children:"Local Security Policy"}),", go to ",(0,s.jsx)(n.code,{children:"Local Policies - User Rights Assignment"}),", open ",(0,s.jsx)(n.code,{children:"Create symbolic links"})," and add your user account or user group, restart when it doesn't apply immediately."]}),"\n",(0,s.jsx)(n.h2,{id:"folders-structure",children:"Folders structure"}),"\n",(0,s.jsxs)(n.p,{children:["All ",(0,s.jsx)(n.code,{children:"tinyorm.org"})," examples are based on the following folders structure. The ",(0,s.jsx)(n.code,{children:"tom"})," folder will contain a ",(0,s.jsx)(n.a,{href:"/building/migrations",children:"migrations console application"}),"."]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can set the root and application folder paths in the form below and they will be used across the whole ",(0,s.jsx)(n.a,{href:"http://www.tinyorm.org",children:"www.tinyorm.org"})," website. \ud83e\udd73 The pwsh shell is supposed to use on Windows and the bash shell on Linux, but it is not a requirement."]})}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsxs)(t.A,{value:y.b,label:y.ux,className:"tiny-tree",children:[(0,s.jsx)("div",{className:"tiny-root-folder-info-wrapper",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)("span",{className:"tiny-root-folder-info-prefix",children:"Current pwsh path"}),"\xa0",(0,s.jsx)(u,{groupId:y.b})]})}),(0,s.jsx)(g,{groupId:y.b,label:y.ux}),(0,s.jsx)(g,{groupId:y.pW,label:y.kl}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-text",children:"\n\n\n\u251c\u2500\u2500\n\u2502 \u251c\u2500\u2500 HelloWorld/\n\u2502 | \u251c\u2500\u2500 HelloWorld/\n\u2502 | \u251c\u2500\u2500 HelloWorld-builds-cmake/\n\u2502 | | \u2514\u2500\u2500 build-debug/\n\u2502 | \u2514\u2500\u2500 HelloWorld-builds-qmake/\n\u2502 | \u2514\u2500\u2500 build-debug/\n\u2502 \u251c\u2500\u2500 TinyORM/\n\u2502 | \u251c\u2500\u2500 TinyORM/\n\u2502 | \u251c\u2500\u2500 TinyORM-builds-cmake/\n\u2502 | \u2502 \u251c\u2500\u2500 build-gcc-debug/\n\u2502 | \u2502 \u251c\u2500\u2500 build-gcc-release/\n\u2502 | \u2502 \u2514\u2500\u2500 build-clang-debug/\n\u2502 | \u2514\u2500\u2500 TinyORM-builds-qmake/\n\u2502 | \u251c\u2500\u2500 build-debug/\n\u2502 | \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/\n\u2502 | \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_2_MSYS2_UCRT64_64bit-Release/\n\u2502 \u2514\u2500\u2500 tom/\n\u2502 \u251c\u2500\u2500 tom/\n\u2502 \u2502 \u2514\u2500\u2500 database/\n\u2502 \u2502 \u251c\u2500\u2500 migrations/\n\u2502 \u2502 \u251c\u2500\u2500 seeders/\n\u2502 \u2502 \u251c\u2500\u2500 migrations.pri\n\u2502 \u2502 \u2514\u2500\u2500 seeders.pri\n\u2502 \u251c\u2500\u2500 tom-builds-cmake/\n\u2502 \u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_MSVC2019_64bit-Debug/\n\u2502 \u2514\u2500\u2500 tom-builds-qmake/\n\u2502 \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_3_MSYS2_UCRT64_64bit-Release/\n\u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_MSVC2019_64bit-Debug/\n\u251c\u2500\u2500 tmp/\n\u2514\u2500\u2500 vcpkg/\n"})})]}),(0,s.jsxs)(t.A,{value:y.xj,label:y.gg,className:"tiny-tree",children:[(0,s.jsx)("div",{className:"tiny-root-folder-info-wrapper",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)("span",{className:"tiny-root-folder-info-prefix",children:"Current bash path"}),"\xa0",(0,s.jsx)(u,{groupId:y.xj})]})}),(0,s.jsx)(g,{groupId:y.xj,label:y.gg}),(0,s.jsx)(g,{groupId:y.pW,label:y.pW}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-text",children:"\n\n\n\u251c\u2500\u2500\n\u2502 \u251c\u2500\u2500 HelloWorld/\n\u2502 | \u251c\u2500\u2500 HelloWorld/\n\u2502 | \u251c\u2500\u2500 HelloWorld-builds-cmake/\n\u2502 | | \u2514\u2500\u2500 build-debug/\n\u2502 | \u2514\u2500\u2500 HelloWorld-builds-qmake/\n\u2502 | \u2514\u2500\u2500 build-debug/\n\u2502 \u251c\u2500\u2500 TinyORM/\n\u2502 | \u251c\u2500\u2500 TinyORM/\n\u2502 | \u251c\u2500\u2500 TinyORM-builds-cmake/\n\u2502 | \u2502 \u251c\u2500\u2500 build-gcc-debug/\n\u2502 | \u2502 \u251c\u2500\u2500 build-gcc-release/\n\u2502 | \u2502 \u2514\u2500\u2500 build-clang-debug/\n\u2502 | \u2514\u2500\u2500 TinyORM-builds-qmake/\n\u2502 | \u251c\u2500\u2500 build-debug/\n\u2502 | \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_2_GCC_64bit-Debug/\n\u2502 | \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_5_15_2_clang13_64bit_ccache-Release/\n\u2502 \u2514\u2500\u2500 tom/\n\u2502 \u251c\u2500\u2500 tom/\n\u2502 \u2502 \u2514\u2500\u2500 database/\n\u2502 \u2502 \u251c\u2500\u2500 migrations/\n\u2502 \u2502 \u251c\u2500\u2500 seeders/\n\u2502 \u2502 \u251c\u2500\u2500 migrations.pri\n\u2502 \u2502 \u2514\u2500\u2500 seeders.pri\n\u2502 \u251c\u2500\u2500 tom-builds-cmake/\n\u2502 \u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_clang14_64bit_ccache-Debug/\n\u2502 \u2514\u2500\u2500 tom-builds-qmake/\n\u2502 \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_GCC_64bit-Debug/\n\u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_7_0_clang14_64bit_ccache-Release/\n\u251c\u2500\u2500 tmp/\n\u2514\u2500\u2500 vcpkg/\n"})})]})]}),"\n",(0,s.jsx)(n.admonition,{type:"danger",children:(0,s.jsxs)(n.p,{children:["Avoid paths with spaces with the ",(0,s.jsx)(n.code,{children:"qmake"})," build system, it will not compile."]})}),"\n",(0,s.jsx)(r.A,{id:"qtcreator-default-build-directory"}),"\n",(0,s.jsxs)(n.admonition,{type:"tip",children:[(0,s.jsxs)(n.p,{children:["You can force the ",(0,s.jsx)(n.code,{children:"QtCreator"})," to generate a build folders structure as is described above."]}),(0,s.jsxs)(n.p,{children:["To generate the required folders structure set the ",(0,s.jsx)(n.code,{children:"Settings"})," - ",(0,s.jsx)(n.code,{children:"Build & Run"})," - ",(0,s.jsx)(n.code,{children:"Default Build Properties"})," - ",(0,s.jsx)(n.code,{children:"Default build directory"})," to:",(0,s.jsx)("br",{}),"\n",(0,s.jsx)(n.code,{children:'../%{Project:Name}-builds-%{BuildSystem:Name}/%{JS: Util.asciify("build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name}")}'})]})]}),"\n",(0,s.jsx)(n.h2,{id:"getting-started",children:"Getting started"}),"\n",(0,s.jsxs)(n.p,{children:["Prepare compilation environment, we need to put the Qt Framework and Visual Studio MSVC compiler on the path on Windows. The compiler is already on the path on Linux and you can export ",(0,s.jsx)(n.code,{children:"PATH"})," and ",(0,s.jsx)(n.code,{children:"LD_LIBRARY_PATH"})," for Qt Framework, or use our ",(0,s.jsx)(n.code,{children:"qtenvX"})," scripts described above."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`mkdir ${(0,x.Sn)(y.b)}\ncd ${(0,x.Sn)(y.b)}\n$env:Path = 'C:\\Qt\\6.7.0\\msvc2019_64\\bin;' + $env:Path\nvcvars64.ps1`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`mkdir -p ${(0,x.Sn)(y.xj)}\ncd ${(0,x.Sn)(y.xj)}\nexport PATH=/opt/Qt/6.7.0/gcc_64/bin\${PATH:+:}$PATH\nexport LD_LIBRARY_PATH=/opt/Qt/6.7.0/gcc_64/lib\${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH`})})]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can also use the ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/tools/Add-FolderOnPath.ps1",children:(0,s.jsx)(n.code,{children:"tools/Add-FolderOnPath.ps1"})})," pwsh script to fastly prepend a path or ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"})," on the system ",(0,s.jsx)(n.code,{children:"PATH"}),"."]})}),"\n",(0,s.jsx)(n.h2,{id:"vcpkg",children:"vcpkg"}),"\n",(0,s.jsxs)(n.p,{children:["Installing the ",(0,s.jsx)(n.code,{children:"vcpkg"})," is highly recommended, it simplifies installation of the ",(0,s.jsx)(n.code,{children:"range-v3"})," and ",(0,s.jsx)(n.code,{children:"tabulate"})," dependencies."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"git clone git@github.com:microsoft/vcpkg.git\ncd vcpkg\n.\\bootstrap-vcpkg.bat\n"})})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"git clone git@github.com:microsoft/vcpkg.git\ncd vcpkg\n./bootstrap-vcpkg.sh\n"})})})]}),"\n",(0,s.jsxs)(n.p,{children:["Add ",(0,s.jsx)(n.code,{children:"vcpkg"})," on the system path, add the following to the ",(0,s.jsx)(n.code,{children:".bashrc"})," or ",(0,s.jsx)(n.code,{children:".zshrc"})," on Linux."]}),"\n",(0,s.jsx)(c.A,{className:"language-bash",children:`export PATH=${(0,x.Sn)(y.xj)}/vcpkg\${PATH:+:}$PATH`}),"\n",(0,s.jsxs)(n.p,{children:["On Windows, open the ",(0,s.jsx)(n.code,{children:"Environment variables"})," dialog and add ",(0,s.jsx)(n.code,{children:"vcpkg"})," on the user ",(0,s.jsx)(n.code,{children:"PATH"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"Or you can export it for the current session only."}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`$env:Path = "${(0,x.Sn)(y.b,!1)}\\vcpkg;" + $env:Path`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`export PATH=${(0,x.Sn)(y.xj)}/vcpkg\${PATH:+:}$PATH`})})]}),"\n",(0,s.jsxs)(n.h4,{id:"set-up-vcpkg-environment",children:["Set up ",(0,s.jsx)(n.code,{children:"vcpkg"})," environment"]}),"\n",(0,s.jsxs)(n.p,{children:["To export ",(0,s.jsx)(n.code,{children:"vcpkg"})," environment variables globally, add it to the ",(0,s.jsx)(n.code,{children:".bashrc"})," or ",(0,s.jsx)(n.code,{children:".zshrc"})," on Linux, and you can use the ",(0,s.jsx)(n.code,{children:"Environment variables"})," dialog on Windows."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",metastring:"title='Linux'",children:'export VCPKG_DEFAULT_TRIPLET=x64-linux\n#export VCPKG_DEFAULT_HOST_TRIPLET=x64-linux\nexport VCPKG_MAX_CONCURRENCY=11\nexport VCPKG_OVERLAY_PORTS="$HOME/.local/share/vcpkg/ports"\nexport VCPKG_OVERLAY_TRIPLETS="$HOME/.local/share/vcpkg/triplets"\nexport VCPKG_ROOT="$HOME/Code/c/vcpkg"\n'})}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["It is recommended to define these variables globally because the ",(0,s.jsx)(n.code,{children:"CMake"})," and ",(0,s.jsx)(n.code,{children:"qmake"})," build system are able to detect the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation from them so you don't have to configure them manually to detect the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation."]})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["On Windows, it's always better to create these types of variables as user variables instead of system variables in the ",(0,s.jsx)(n.code,{children:"Environment variables"})," dialog."]})}),"\n",(0,s.jsx)(n.h2,{id:"c-preprocessor-macros",children:"C preprocessor macros"}),"\n",(0,s.jsxs)(n.p,{children:["The following table summarizes all the C preprocessor macros defined in the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. These C macros are configured by ",(0,s.jsx)(n.code,{children:"CMake"})," or ",(0,s.jsx)(n.code,{children:"qmake"})," build systems. They are not sorted alphabetically, but they are sorted by how significant they are."]}),"\n",(0,s.jsxs)(n.p,{children:["In the ",(0,s.jsx)(n.code,{children:"CMake"})," build system, all the C macros are auto-detected / auto-configured or controlled by ",(0,s.jsx)(n.a,{href:"#cmake-build-options",children:(0,s.jsx)(n.code,{children:"CMake build options"})}),", so you don't have to care too much about them."]}),"\n",(0,s.jsxs)(n.p,{children:["In the ",(0,s.jsx)(n.code,{children:"qmake"})," build is important whether you are building ",(0,s.jsx)(n.code,{children:"TinyORM"})," library or you are building your application and linking against ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. When you are building the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library, all the C macros are auto-detected / auto-configured or controlled by ",(0,s.jsx)(n.a,{href:"#qmake-build-options",children:(0,s.jsx)(n.code,{children:"qmake build options"})}),", so you don't have to care too much about them."]}),"\n",(0,s.jsxs)(n.p,{children:["But a special situation is when you are building your application / library and you are linking against ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. In this particular case, you must configure all these C macros manually! For this reason, the ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/qmake/TinyOrm.pri",children:(0,s.jsx)(n.code,{children:"TinyOrm.pri"})})," has been created, so that's not a big deal either. Little more info ",(0,s.jsx)(n.a,{href:"#consume-tinyorm-library-qmake",children:"here"}),"."]}),"\n",(0,s.jsx)("div",{id:"apitable-c-macros",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"C Macro Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_LINKING_SHARED"})}),(0,s.jsxs)(n.td,{children:[(0,s.jsx)("u",{children:(0,s.jsx)(n.strong,{children:"Must"})})," be defined when you are linking against ",(0,s.jsx)(n.code,{children:"TinyORM"})," shared build (",(0,s.jsx)(n.code,{children:"dll"})," library), exported classes and functions will be tagged with ",(0,s.jsx)(n.code,{children:"__declspec(dllimport)"})," on ",(0,s.jsx)(n.code,{children:"msvc"})," and ",(0,s.jsx)(n.code,{children:'visibility("default")'})," on ",(0,s.jsx)(n.code,{children:"GCC >= 4"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_BUILDING_SHARED"})}),(0,s.jsxs)(n.td,{children:["Defined when ",(0,s.jsx)(n.code,{children:"TinyORM"})," is built as a ",(0,s.jsx)(n.code,{children:"dll"})," library (shared build)."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_DEBUG"})}),(0,s.jsx)(n.td,{children:"Defined in the debug build."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_NO_DEBUG"})}),(0,s.jsx)(n.td,{children:"Defined in the release build."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_DEBUG_SQL"})}),(0,s.jsx)(n.td,{children:"Defined in the debug build."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_NO_DEBUG_SQL"})}),(0,s.jsx)(n.td,{children:"Defined in the release build."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_MYSQL_PING"})}),(0,s.jsxs)(n.td,{children:["Enable ",(0,s.jsx)(n.code,{children:"Orm::MySqlConnection::pingDatabase()"})," method.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#mysql_ping",children:(0,s.jsx)(n.code,{children:"mysql_ping"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#MYSQL_PING",children:(0,s.jsx)(n.code,{children:"MYSQL_PING"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_DISABLE_ORM"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"ORM-related"})," source code, when this macro is ",(0,s.jsx)(n.code,{children:"defined"}),", then only the ",(0,s.jsx)(n.code,{children:"query builder"})," without ",(0,s.jsx)(n.code,{children:"ORM"})," is compiled. Also excludes ",(0,s.jsx)(n.code,{children:"ORM-related"})," unit tests.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#disable_orm",children:(0,s.jsx)(n.code,{children:"disable_orm"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#ORM",children:(0,s.jsx)(n.code,{children:"ORM"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled ",(0,s.jsx)("small",{children:"(qmake)"})," / disabled ",(0,s.jsx)("small",{children:"(cmake)"}),"."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_EXTERN_CONSTANTS"})}),(0,s.jsxs)(n.td,{children:["Defined when extern constants are used. Extern constants are enabled by default for shared builds and disabled for static builds.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Described at ",(0,s.jsx)(n.a,{href:"#extern_constants",children:(0,s.jsx)(n.code,{children:"qmake"})})," / ",(0,s.jsx)(n.a,{href:"#INLINE_CONSTANTS",children:(0,s.jsx)(n.code,{children:"CMake"})})," how it works."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_INLINE_CONSTANTS"})}),(0,s.jsxs)(n.td,{children:["Defined when global inline constants are used.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#inline_constants",children:(0,s.jsx)(n.code,{children:"inline_constants"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#INLINE_CONSTANTS",children:(0,s.jsx)(n.code,{children:"INLINE_CONSTANTS"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_TESTS_CODE"})}),(0,s.jsxs)(n.td,{children:["Enable code needed by unit tests, eg. connection overriding in the ",(0,s.jsx)(n.code,{children:"Orm::Tiny::Model"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#build_tests",children:(0,s.jsx)(n.code,{children:"build_tests"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#BUILD_TESTS",children:(0,s.jsx)(n.code,{children:"BUILD_TESTS"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_DISABLE_THREAD_LOCAL"})}),(0,s.jsxs)(n.td,{children:["Remove all ",(0,s.jsx)(n.a,{href:"https://en.cppreference.com/w/c/language/storage_duration",children:(0,s.jsx)(n.code,{children:"thread_local"})})," storage duration specifiers, it disables multi-threading support.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined when ",(0,s.jsx)(n.a,{href:"#disable_thread_local",children:(0,s.jsx)(n.code,{children:"disable_thread_local"})})," ",(0,s.jsx)("small",{children:"(qmake)"})," / ",(0,s.jsx)(n.a,{href:"#DISABLE_THREAD_LOCAL",children:(0,s.jsx)(n.code,{children:"DISABLE_THREAD_LOCAL"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration ",(0,s.jsx)(n.code,{children:"build option"})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYTOM_MIGRATIONS_DIR"})}),(0,s.jsxs)(n.td,{children:["Default migrations path for the ",(0,s.jsx)(n.code,{children:"make:migration"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/migrations"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined by ",(0,s.jsx)(n.a,{href:"#TOM_MIGRATIONS_DIR",children:(0,s.jsx)(n.code,{children:"TOM_MIGRATIONS_DIR"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration build option.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["(qmake note) You can use ",(0,s.jsx)(n.code,{children:'DEFINES += TINYTOM_MIGRATIONS_DIR="\\"database/migrations\\""'})," on the command-line or set it in the ",(0,s.jsx)(n.strong,{children:"main"})," ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L65-L70",children:(0,s.jsx)(n.code,{children:"conf.pri"})})," file."]})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYTOM_MODELS_DIR"})}),(0,s.jsxs)(n.td,{children:["Default models path for the ",(0,s.jsx)(n.code,{children:"make:model"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/models"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined by ",(0,s.jsx)(n.a,{href:"#TOM_MODELS_DIR",children:(0,s.jsx)(n.code,{children:"TOM_MODELS_DIR"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration build option.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["(qmake note) You can use ",(0,s.jsx)(n.code,{children:'DEFINES += TINYTOM_MODELS_DIR="\\"database/models\\""'})," on the command-line or set it in the ",(0,s.jsx)(n.strong,{children:"main"})," ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L72-L73",children:(0,s.jsx)(n.code,{children:"conf.pri"})})," file."]})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYTOM_SEEDERS_DIR"})}),(0,s.jsxs)(n.td,{children:["Default seeders path for the ",(0,s.jsx)(n.code,{children:"make:seeder"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/seeders"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Defined by ",(0,s.jsx)(n.a,{href:"#TOM_SEEDERS_DIR",children:(0,s.jsx)(n.code,{children:"TOM_SEEDERS_DIR"})})," ",(0,s.jsx)("small",{children:"(cmake)"})," configuration build option.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["(qmake note) You can use ",(0,s.jsx)(n.code,{children:'DEFINES += TINYTOM_SEEDERS_DIR="\\"database/seeders\\""'})," on the command-line or set it in the ",(0,s.jsx)(n.strong,{children:"main"})," ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L75-L76",children:(0,s.jsx)(n.code,{children:"conf.pri"})})," file."]})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_USING_PCH"})}),(0,s.jsxs)(n.td,{children:["Defined if building with precompiled headers.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Controlled by ",(0,s.jsx)(n.a,{href:"#qmake-precompile_header",children:(0,s.jsx)(n.code,{children:"qmake"})})," / ",(0,s.jsx)(n.a,{href:"#CMAKE_DISABLE_PRECOMPILE_HEADERS",children:(0,s.jsx)(n.code,{children:"CMake"})}),"."]})]})]})]})]})})}),"\n",(0,s.jsx)(n.h2,{id:"building-with-cmake",children:"Building with CMake"}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["If something is not clear, you can still look at GitHub Action ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/tree/main/.github/workflows",children:(0,s.jsx)(n.code,{children:"workflows"})})," how a building is done."]})}),"\n",(0,s.jsxs)(n.p,{children:["First, create a basic folder structure and then clone the ",(0,s.jsx)(n.code,{children:"TinyORM"})," project."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cd ${(0,x.Sn)(y.b)}\nmkdir ${(0,x.np)()}/TinyORM/TinyORM-builds-cmake/build-debug\n\ncd ${(0,x.np)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cd ${(0,x.Sn)(y.xj)}\nmkdir -p ${(0,x.np)()}/TinyORM/TinyORM-builds-cmake/build-debug\n\ncd ${(0,x.np)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`})})]}),"\n",(0,s.jsxs)(n.h3,{id:"configure-and-build-cmake",children:["Configure & Build ",(0,s.jsx)("small",{children:"(cmake)"})]}),"\n",(0,s.jsxs)(n.p,{children:["Now you are ready to configure the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"cd TinyORM-builds-cmake/build-debug\n"})}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cmake.exe \`\n-S "${(0,x.OZ)(y.b)}/TinyORM/TinyORM" \`\n-B "${(0,x.OZ)(y.b)}/TinyORM/TinyORM-builds-cmake/build-debug" \`\n-G 'Ninja' \`\n-D CMAKE_BUILD_TYPE:STRING='Debug' \`\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,x.Sn)(y.b)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \`\n-D CMAKE_CXX_SCAN_FOR_MODULES:BOOL=OFF \`\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,x.Sn)(y.b)}/tmp/TinyORM" \`\n-D BUILD_TESTS:BOOL=OFF \`\n-D MATCH_EQUAL_EXPORTED_BUILDTREE:BOOL=ON \`\n-D MYSQL_PING:BOOL=OFF \`\n-D TOM:BOOL=ON \`\n-D TOM_EXAMPLE:BOOL=OFF \`\n-D VERBOSE_CONFIGURE:BOOL=ON`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cmake \\\n-S "${(0,x.OZ)(y.xj)}/TinyORM/TinyORM" \\\n-B "${(0,x.OZ)(y.xj)}/TinyORM/TinyORM-builds-cmake/build-debug" \\\n-G 'Ninja' \\\n-D CMAKE_BUILD_TYPE:STRING='Debug' \\\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,x.Sn)(y.xj)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \\\n-D CMAKE_CXX_SCAN_FOR_MODULES:BOOL=OFF \\\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,x.Sn)(y.xj)}/tmp/TinyORM" \\\n-D VERBOSE_CONFIGURE:BOOL=ON \\\n-D BUILD_TESTS:BOOL=OFF \\\n-D MYSQL_PING:BOOL=OFF \\\n-D TOM:BOOL=ON \\\n-D TOM_EXAMPLE:BOOL=OFF \\\n-D MATCH_EQUAL_EXPORTED_BUILDTREE:BOOL=ON`})})]}),"\n",(0,s.jsxs)(n.h5,{id:"cmake-strict_mode-option",children:["CMake ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," option"]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," ",(0,s.jsx)(n.code,{children:"CMake"})," configuration option was added in ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.37.3"}),". This option was added to avoid the propagation of aggressive strict warning compiler/linker options and Qt definitions from the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library to user code through the ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/cmake/CommonModules/TinyCommon.cmake",children:(0,s.jsx)(n.code,{children:"TinyOrm::CommonConfig"})})," interface library."]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"TinyORM"})," uses the strictest warning level options, virtually anything that can be enabled is enabled to produce a better code. I highly recommend enabling this option to produce better code and to follow good practices. It also helps to follow the ",(0,s.jsx)(n.code,{children:"ISOCPP"})," ",(0,s.jsx)(n.a,{href:"https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines",children:"C++ Core Guidelines"})," standards."]}),"\n",(0,s.jsxs)(n.p,{children:["If you want to enable these strict warning options in your code, you can enable the ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," ",(0,s.jsx)(n.code,{children:"CMake"})," configuration option and they will be propagated to your code. You can also enabled it globally using the ",(0,s.jsx)(n.code,{children:"TINYORM_STRICT_MODE"})," environment variable, and the value of this environment variable will be picked up during initial CMake configuration as the default value for the ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," ",(0,s.jsx)(n.code,{children:"CMake"})," configuration option."]}),"\n",(0,s.jsxs)(n.p,{children:["You can achieve the same result by manually linking against the ",(0,s.jsx)(n.code,{children:"TinyOrm::CommonConfig"})," interface library when the ",(0,s.jsx)(n.code,{children:"STRICT_MODE"})," is set to ",(0,s.jsx)(n.code,{children:"OFF"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cmake",children:"target_link_libraries( PRIVATE TinyOrm::CommonConfig)\n"})}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["The recommended way is to set the ",(0,s.jsx)(n.code,{children:"TINYORM_STRICT_MODE"})," environment variable to ",(0,s.jsx)(n.code,{children:"1"})," or ",(0,s.jsx)(n.code,{children:"ON"}),"."]})}),"\n",(0,s.jsx)(n.h4,{id:"build-tinyorm",children:"Build TinyORM"}),"\n",(0,s.jsx)(n.p,{children:"And build. You don't have to install it, you can use the build tree directly if you want."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"cmake --build . --target all\ncmake --install .\n"})}),"\n",(0,s.jsx)(n.p,{children:"Or build and install in one step."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"cmake --build . --target install\n"})}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["CMake multi-config generators like ",(0,s.jsx)(n.code,{children:"Ninja Multi-Config"})," or ",(0,s.jsx)(n.code,{children:"Visual Studio 16 2019"})," are also supported."]})}),"\n",(0,s.jsx)(n.h3,{id:"cmake-build-options",children:"CMake build options"}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Option Name"}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_DRIVERS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started",children:"TinyDrivers"})," SQL database drivers (core/common code; replaces QtSql module)."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_MYSQL_DRIVER"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," MySQL database driver.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)(n.code,{children:"BUILD_DRIVERS"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_SHARED_LIBS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsx)(n.td,{children:"Build as a shared/static library."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_TESTS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsx)(n.td,{children:"Build TinyORM unit tests."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"BUILD_TREE_DEPLOY"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Copy ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," and ",(0,s.jsx)(n.code,{children:"TinyMySql"})," libraries to the root of the build tree."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"DRIVERS_TYPE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"Shared"})}),(0,s.jsxs)(n.td,{children:["How to build and link against ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," SQL database drivers.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["The ",(0,s.jsx)(n.code,{children:"Static"})," value will be select by default when the ",(0,s.jsx)(n.code,{children:"BUILD_SHARED_LIBS"})," is ",(0,s.jsx)(n.code,{children:"OFF"}),".",(0,s.jsx)("br",{}),"Supported values: ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-shared-library-build",children:(0,s.jsx)(n.code,{children:"Shared"})}),", ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-loadable-sql-drivers-build",children:(0,s.jsx)(n.code,{children:"Loadable"})}),", and ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-static-build",children:(0,s.jsx)(n.code,{children:"Static"})}),(0,s.jsx)("br",{}),"Available when: ",(0,s.jsx)(n.code,{children:"BUILD_DRIVERS AND BUILD_SHARED_LIBS"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"INLINE_CONSTANTS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Use inline constants instead of extern constants in the ",(0,s.jsx)(n.code,{children:"shared build"}),".",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"OFF"})," is highly recommended for the ",(0,s.jsx)(n.code,{children:"shared build"}),";",(0,s.jsx)("br",{}),"is always ",(0,s.jsx)(n.code,{children:"ON"})," for the ",(0,s.jsx)(n.code,{children:"static build"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)(n.code,{children:"BUILD_SHARED_LIBS"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"MSVC_RUNTIME_DYNAMIC"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Use MSVC dynamic runtime library (",(0,s.jsx)(n.code,{children:"-MD"}),") instead of static (",(0,s.jsx)(n.code,{children:"-MT"}),"), also considers a Debug configuration (",(0,s.jsx)(n.code,{children:"-MTd"}),", ",(0,s.jsx)(n.code,{children:"-MDd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)(n.code,{children:"MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"MYSQL_PING"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Enable ",(0,s.jsx)(n.code,{children:"Orm::MySqlConnection::pingDatabase()"})," method."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ORM"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"ORM-related"})," source code, when this option is ",(0,s.jsx)(n.code,{children:"disabled"}),", then only the ",(0,s.jsx)(n.code,{children:"query builder"})," without ",(0,s.jsx)(n.code,{children:"ORM"})," is compiled. Also excludes ",(0,s.jsx)(n.code,{children:"ORM-related"})," unit tests."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"STRICT_MODE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Controls propagation of strict compiler/linker options and Qt definitions using the ",(0,s.jsx)(n.code,{children:"TinyOrm::CommonConfig"})," interface library to the user code.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["(highly recommended; can also be set with the ",(0,s.jsx)(n.code,{children:"TINYORM_STRICT_MODE"})," environment variable; described ",(0,s.jsx)(n.a,{href:"#cmake-strict_mode-option",children:"here"}),")"]}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"Tom-related"})," source code, when this option is ",(0,s.jsx)(n.code,{children:"disabled"}),", then it also excludes ",(0,s.jsx)(n.code,{children:"Tom-related"})," unit tests."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM_EXAMPLE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build the ",(0,s.jsx)("abbr",{title:"TinyORM Migrations",children:(0,s.jsx)(n.code,{children:"tom"})})," console application example."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM_MIGRATIONS_DIR"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Default migrations path for the ",(0,s.jsx)(n.code,{children:"make:migration"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/migrations"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM_MODELS_DIR"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Default models path for the ",(0,s.jsx)(n.code,{children:"make:model"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/models"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TOM_SEEDERS_DIR"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Default seeders path for the ",(0,s.jsx)(n.code,{children:"make:seeder"})," command, can be an absolute or relative path (to the ",(0,s.jsx)("abbr",{title:"Current working directory",children:"pwd"}),").",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Default value: ",(0,s.jsx)(n.code,{children:"database/seeders"})," ",(0,s.jsx)("small",{children:"(relative to the pwd)"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"VERBOSE_CONFIGURE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Show information about ",(0,s.jsx)(n.code,{children:"PACKAGES_FOUND"})," / ",(0,s.jsx)(n.code,{children:"PACKAGES_NOT_FOUND"})," in the CMake configure output."]})]})]})]})})}),"\n",(0,s.jsxs)(n.p,{children:["Advanced ",(0,s.jsx)(n.code,{children:"TinyORM"})," options."]}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Option Name"}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"DISABLE_THREAD_LOCAL"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Remove all ",(0,s.jsx)(n.a,{href:"https://en.cppreference.com/w/c/language/storage_duration",children:(0,s.jsx)(n.code,{children:"thread_local"})})," storage duration specifiers, it disables multi-threading support."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)("small",{children:(0,s.jsx)(n.code,{children:"MATCH_EQUAL_EXPORTED_BUILDTREE"})})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Exported package configuration from the build tree is considered to match only when ",(0,s.jsx)(n.code,{children:"the build type"})," of application/library that is linking against the TinyORM library ",(0,s.jsx)(n.strong,{children:"is equal"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when:",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"CMAKE_EXPORT_PACKAGE_REGISTRY AND NOT TINY_IS_MULTI_CONFIG"})]})]})]})]})]})})}),"\n",(0,s.jsxs)(n.p,{children:["Important ",(0,s.jsx)(n.code,{children:"CMake"})," options."]}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Option Name"}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_DISABLE_PRECOMPILE_HEADERS"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsx)(n.td,{children:"Disable precompiled headers."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_CXX_COMPILER"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"auto"})}),(0,s.jsxs)(n.td,{children:["The full path to the ",(0,s.jsx)(n.code,{children:"C++"})," compiler."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_CXX_COMPILER_LAUNCHER"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Default compiler launcher to use for the ",(0,s.jsx)(n.code,{children:"C++"})," compiler.",(0,s.jsx)("br",{}),"Can be used to enable ",(0,s.jsx)(n.code,{children:"ccache"}),", eg. ",(0,s.jsx)(n.code,{children:"ccache.exe"})," on ",(0,s.jsx)(n.code,{children:"MinGW"})," or ",(0,s.jsx)(n.code,{children:"/usr/bin/ccache"})," on ",(0,s.jsx)(n.code,{children:"Linux"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_EXPORT_PACKAGE_REGISTRY"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Enable the ",(0,s.jsx)(n.code,{children:"export(TinyOrm)"})," command.",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"TinyORM"})," doesn't set this variable by default. Its initial value is taken from the ",(0,s.jsx)(n.code,{children:"TINYORM_EXPORT_PACKAGE_REGISTRY"})," environment variable if not already defined."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"CMAKE_VERBOSE_MAKEFILE"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsx)(n.td,{children:"Enable verbose output from Makefile builds."})]})]})]})})}),"\n",(0,s.jsxs)(n.h3,{id:"consume-tinyorm-library-cmake",children:["Consume TinyOrm library ",(0,s.jsx)("small",{children:"(cmake)"})]}),"\n",(0,s.jsxs)(n.p,{children:["In your application or library ",(0,s.jsx)(n.code,{children:"CMakeLists.txt"})," file add following ",(0,s.jsx)(n.code,{children:"find_package()"})," call."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cmake",metastring:"title='CMakeLists.txt'",children:"find_package(TinyOrm 0.37.3 CONFIG REQUIRED)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build tree is not exported to the CMake's ",(0,s.jsx)(n.a,{href:"https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#user-package-registry",children:(0,s.jsx)(n.code,{children:"User Package Registry"})})," then also add the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build tree or ",(0,s.jsx)(n.code,{children:"CMAKE_INSTALL_PREFIX"})," folder to the ",(0,s.jsx)(n.code,{children:"CMAKE_PREFIX_PATH"}),", so CMake can find TinyORM's package configuration file during ",(0,s.jsx)(n.code,{children:"find_package(TinyOrm)"})," call."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:`cmake (${y.b})`,children:(0,s.jsx)(c.A,{className:"language-cmake",children:`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,x.nC)(y.b,(0,x.OZ)(y.b))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\n# installation folder - CMAKE_INSTALL_PREFIX\nlist(APPEND CMAKE_PREFIX_PATH "${(0,x.nC)(y.b,(0,x.Sn)(y.b))}/tmp/TinyORM")`})}),(0,s.jsx)(t.A,{value:y.xj,label:`cmake (${y.xj})`,children:(0,s.jsx)(c.A,{className:"language-cmake",children:`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,x.nC)(y.xj,(0,x.OZ)(y.xj))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\n# installation folder - CMAKE_INSTALL_PREFIX\nlist(APPEND CMAKE_PREFIX_PATH "${(0,x.nC)(y.xj,(0,x.Sn)(y.xj))}/tmp/TinyORM")`})})]}),"\n",(0,s.jsxs)(n.p,{children:["Or as an alternative, you can set ",(0,s.jsx)(n.code,{children:"CMAKE_PREFIX_PATH"})," environment variable."]}),"\n",(0,s.jsx)(r.A,{id:"tinyorm-on-path-cmake"}),"\n",(0,s.jsxs)(n.p,{children:["As the last thing, do not forget to add ",(0,s.jsx)(n.code,{children:"TinyOrm0d.dll"})," on the path on Windows and on the ",(0,s.jsx)(n.code,{children:"LD_LIBRARY_PATH"})," on Linux, so your application can find it during execution."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,name:"tinyorm-on-path",children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`$env:Path = "${(0,x.OZ)(y.b,!1)}\\TinyORM\\TinyORM-builds-cmake\\build-debug;" + $env:Path`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`export LD_LIBRARY_PATH=${(0,x.OZ)(y.xj)}/TinyORM/TinyORM-builds-cmake/build-debug\${PATH:+:}$PATH`})})]}),"\n",(0,s.jsxs)(n.p,{children:["Now you can try the ",(0,s.jsx)(n.a,{href:"/building/hello-world#hello-world-with-cmake",children:(0,s.jsx)(n.code,{children:"HelloWorld CMake"})})," example."]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["You can also try the ",(0,s.jsx)(n.a,{href:"/building/hello-world#fetchcontent",children:(0,s.jsx)(n.code,{children:"FetchContent"})})," method to fastly link against the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library."]})}),"\n",(0,s.jsx)(n.h2,{id:"building-with-qmake",children:"Building with qmake"}),"\n",(0,s.jsxs)(n.p,{children:["First, create a basic folder structure and then clone the ",(0,s.jsx)(n.code,{children:"TinyORM"})," project."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cd ${(0,x.Sn)(y.b)}\nmkdir ${(0,x.np)()}/TinyORM/TinyORM-builds-qmake\n\ncd ${(0,x.np)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cd ${(0,x.Sn)(y.xj)}\nmkdir -p ${(0,x.np)()}/TinyORM/TinyORM-builds-qmake\n\ncd ${(0,x.np)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`})})]}),"\n",(0,s.jsx)(n.h3,{id:"install-dependencies",children:"Install dependencies"}),"\n",(0,s.jsxs)(n.p,{children:["With the ",(0,s.jsx)(n.code,{children:"qmake"})," build system, you have to install ",(0,s.jsx)(n.code,{children:"TinyORM"})," dependencies manually. We will use the ",(0,s.jsx)(n.code,{children:"vcpkg"})," package manager."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"cd ../../vcpkg\n\nvcpkg search range-v3\nvcpkg search tabulate\nvcpkg install range-v3 tabulate\nvcpkg list\n"})}),"\n",(0,s.jsxs)(n.p,{children:["On ",(0,s.jsx)(n.code,{children:"Linux"}),", you can install the ",(0,s.jsx)(n.code,{children:"range-v3"})," library and some other ",(0,s.jsx)(n.a,{href:"/dependencies#install-dependencies",children:"dependencies"})," with the package manager."]}),"\n",(0,s.jsxs)(n.h3,{id:"configure-and-build-qmake",children:["Configure & Build ",(0,s.jsx)("small",{children:"(qmake)"})]}),"\n",(0,s.jsx)(n.h4,{id:"open-qtcreator-ide",children:"Open QtCreator IDE"}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["I recommend creating a new ",(0,s.jsx)(n.a,{href:"https://doc.qt.io/qtcreator/creator-project-managing-sessions.html",children:(0,s.jsx)(n.code,{children:"Session"})})," in the ",(0,s.jsx)(n.code,{children:"QtCreator"}),", this way you will have all the examples in one place and as a bonus, everything will be in the same place when you close and reopen ",(0,s.jsx)(n.code,{children:"QtCreator IDE"}),". You can name it ",(0,s.jsx)(n.code,{children:"tinyorm.org"})," or ",(0,s.jsx)(n.code,{children:"TinyORM examples"}),", it is up to you."]})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["If you are using sessions, you can use a single ",(0,s.jsx)(n.code,{children:"clangd"})," instance for all projects in this session in the ",(0,s.jsx)(n.code,{children:"QtCreator IDE"}),". One significant advantage of this method is that the ",(0,s.jsx)(n.code,{children:".qtc_clangd/"})," folder will not be created in the build folder, but will be stored globally in the Roaming profile. You can enable it in the ",(0,s.jsx)(n.code,{children:"Settings"})," - ",(0,s.jsx)(n.code,{children:"C++"})," - ",(0,s.jsx)(n.code,{children:"Clangd"})," - ",(0,s.jsx)(n.code,{children:"Sessions with a single clangd instance"}),"."]})}),"\n",(0,s.jsx)(n.h4,{id:"configure-tinyorm",children:"Configure TinyORM"}),"\n",(0,s.jsxs)(n.p,{children:["Now you are ready to configure the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. There are two ways how to configure the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library and it's the new ",(0,s.jsx)(n.code,{children:"Auto-configure"})," feature added in ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"})," using the ",(0,s.jsx)(n.code,{children:".env"})," files and the old way using the ",(0,s.jsx)(n.code,{children:"conf.pri"})," files."]}),"\n",(0,s.jsx)(n.h5,{id:"auto-configuration-and-tiny_dotenv",children:"Auto-configuration and tiny_dotenv"}),"\n",(0,s.jsxs)(n.p,{children:["This is the new recommended method to auto-configure TinyORM's ",(0,s.jsx)(n.code,{children:"qmake"})," build system and also the dependencies, it was added in ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"}),". You need to copy the prepared ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw).example"})," file to the ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw)"}),". One ",(0,s.jsx)(n.code,{children:".env"})," example file is prepared for each supported platform."]}),"\n",(0,s.jsxs)(n.p,{children:["All prepared ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw).example"})," files are simple and clear. You can also create a common ",(0,s.jsx)(n.code,{children:".env"})," file that is included before the platform-specific ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw)"})," files."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cd ${(0,x.OZ)(y.b)}/TinyORM/TinyORM\n\ncp .env.win32.example .env.win32`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cd ${(0,x.OZ)(y.xj)}/TinyORM/TinyORM\n\ncp .env.unix.example .env.unix`})})]}),"\n",(0,s.jsxs)(n.p,{children:["And that is all, if you have correctly set all ",(0,s.jsx)(n.code,{children:"qmake"})," variables in this ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw)"})," file or you have correctly set environment variables, then the ",(0,s.jsx)(n.code,{children:"qmake"})," build system should be able to ",(0,s.jsx)(n.code,{children:"auto-detect"})," all dependencies . \ud83d\udd25"]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"#auto-configuration-internals",children:(0,s.jsx)(n.code,{children:"Auto-configuration"})})," and ",(0,s.jsx)(n.a,{href:"#environment-files",children:(0,s.jsx)(n.code,{children:"Environment files"})})," internals are described at the end to make this section more clear."]})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature can be turned off using the ",(0,s.jsx)(n.a,{href:"#disable_autoconf",children:(0,s.jsx)(n.code,{children:"disable_autoconf"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_autoconf"}),")."]})}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," feature can be turned off using the ",(0,s.jsx)(n.a,{href:"#disable_dotenv",children:(0,s.jsx)(n.code,{children:"disable_dotenv"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_dotenv"}),")."]})}),"\n",(0,s.jsx)(n.h5,{id:"manual-configuration-confpri",children:"Manual configuration (conf.pri)"}),"\n",(0,s.jsxs)(n.p,{children:["This is the old method used before ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"}),". You need to copy the ",(0,s.jsx)(n.code,{children:"conf.pri.example"})," files to ",(0,s.jsx)(n.code,{children:"conf.pri"})," (there are four, one for every project or sub-project) and manually update the ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," and ",(0,s.jsx)(n.code,{children:"LIBS"})," to configure TinyORM's ",(0,s.jsx)(n.code,{children:"qmake"})," build dependencies. This way you can override any ",(0,s.jsx)(n.code,{children:"qmake"})," build options or variables."]}),"\n",(0,s.jsxs)(n.p,{children:["To disable the ",(0,s.jsx)(n.a,{href:"#auto-configuration-internals",children:(0,s.jsx)(n.code,{children:"Auto-configuration"})})," feature you must define the ",(0,s.jsx)(n.a,{href:"#disable_autoconf",children:(0,s.jsx)(n.code,{children:"disable_autoconf"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_autoconf"}),") because from ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"})," is the ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature enabled by default."]}),"\n",(0,s.jsxs)(n.p,{children:["You can also remove all ",(0,s.jsx)(n.code,{children:".env"})," files or turn off the ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," feature using ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_dotenv"}),". You can use them all at once if you want, ",(0,s.jsx)(n.code,{children:".env"})," and also ",(0,s.jsx)(n.code,{children:"conf.pri"})," files."]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"conf.pri"})," files are nicely commented on, so you can see what needs to be modified."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`cd ${(0,x.OZ)(y.b)}/TinyORM/TinyORM\n\ncp conf.pri.example conf.pri\ncp tests/conf.pri.example tests/conf.pri\ncp tests/testdata_tom/conf.pri.example tests/testdata_tom/conf.pri\ncp examples/tom/conf.pri.example examples/tom/conf.pri`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`cd ${(0,x.OZ)(y.xj)}/TinyORM/TinyORM\n\ncp conf.pri.example conf.pri\ncp tests/conf.pri.example tests/conf.pri\ncp tests/testdata_tom/conf.pri.example tests/testdata_tom/conf.pri\ncp examples/tom/conf.pri.example examples/tom/conf.pri`})})]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"#manual-configuration-internals",children:(0,s.jsx)(n.code,{children:"Manual configuration"})})," internals are described at the end to make this section more clear."]})}),"\n",(0,s.jsx)(n.admonition,{type:"note",children:(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Manual configuration"})," is still relevant if you have any non-standard installation of the ",(0,s.jsx)(n.code,{children:"vcpkg"})," or ",(0,s.jsx)(n.code,{children:"MySQL"})," and the ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature fails."]})}),"\n",(0,s.jsx)(n.h5,{id:"opening-tinyormpro-main-project-file",children:"Opening TinyORM.pro (main project file)"}),"\n",(0,s.jsxs)(n.p,{children:["Now you can open the ",(0,s.jsx)(n.code,{children:"TinyORM.pro"})," project in the ",(0,s.jsx)(n.code,{children:"QtCreator IDE"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["This will open the ",(0,s.jsx)(n.code,{children:"Configure Project"})," tab, select some kit and update build folder paths to meet our ",(0,s.jsx)(n.a,{href:"#folders-structure",children:"folders structure"})," or like you want."]}),"\n",(0,s.jsx)("img",{src:i(885).A,alt:"TinyORM - QtCreator - Configure Project",width:"760"}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can force the ",(0,s.jsx)(n.code,{children:"QtCreator"})," to generate a build folders structure as is described ",(0,s.jsx)(n.a,{href:"#qtcreator-default-build-directory",children:"above"}),"."]})}),"\n",(0,s.jsxs)(n.p,{children:["You are ready to configure build options, hit ",(0,s.jsx)("kbd",{children:"Ctrl"}),"+",(0,s.jsx)("kbd",{children:"5"})," to open ",(0,s.jsx)(n.code,{children:"Project Settings"})," tab and select ",(0,s.jsx)(n.code,{children:"Build"})," in the left sidebar to open the ",(0,s.jsx)(n.code,{children:"Build Settings"}),", it should look similar to the following picture."]}),"\n",(0,s.jsxs)(n.p,{children:["Disable ",(0,s.jsx)(n.code,{children:"QML debugging and profiling"})," and ",(0,s.jsx)(n.code,{children:"Qt Quick Compiler"}),", they are not used."]}),"\n",(0,s.jsx)("img",{src:i(7619).A,alt:"TinyORM - QtCreator - Build Settings",width:"760"}),"\n",(0,s.jsxs)(n.p,{children:["If you want to change some ",(0,s.jsx)(n.code,{children:"TinyORM"})," build options, you can pass them to the ",(0,s.jsx)(n.code,{children:"Build Steps"})," - ",(0,s.jsx)(n.code,{children:"qmake TinyORM.pro"})," - ",(0,s.jsx)(n.code,{children:"Additional arguments"})," input field. It can look like this."]}),"\n",(0,s.jsx)("img",{src:i(2721).A,alt:"TinyORM - QtCreator - Build Settings - Additional arguments",width:"660"}),"\n",(0,s.jsx)(n.h4,{id:"build-tinyorm-1",children:"Build TinyORM"}),"\n",(0,s.jsxs)(n.p,{children:["Everything is ready for build, you can press ",(0,s.jsx)("kbd",{children:"Ctrl"}),"+",(0,s.jsx)("kbd",{children:"b"})," to build the project."]}),"\n",(0,s.jsx)(n.h3,{id:"qmake-build-options",children:"qmake build options"}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsxs)(n.th,{children:[(0,s.jsx)(n.code,{children:"CONFIG"})," ",(0,s.jsx)("small",{children:"Option Name"})]}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_loadable_drivers"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started",children:(0,s.jsx)(n.code,{children:"TinyDrivers"})})," as a shared library and SQL database drivers (eg. ",(0,s.jsx)(n.code,{children:"TinyMySql"}),") as shared libraries (",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-loadable-sql-drivers-build",children:(0,s.jsx)(n.code,{children:"Loadable"})})," modules) that are loaded at runtime using ",(0,s.jsx)(n.code,{children:"LoadLibrary()"})," on Windows or ",(0,s.jsx)(n.code,{children:"dlopen()"})," on Linux."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_mysql_driver"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," MySQL database driver.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["It's enabled by default when ",(0,s.jsx)(n.code,{children:"build_shared_drivers"}),", ",(0,s.jsx)(n.code,{children:"build_loadable_drivers"}),", or ",(0,s.jsx)(n.code,{children:"build_static_drivers"})," is enabled.",(0,s.jsx)("br",{}),"Available when: ",(0,s.jsx)(n.code,{children:"build_shared_drivers"})," OR ",(0,s.jsx)(n.code,{children:"build_loadable_drivers"})," OR ",(0,s.jsx)(n.code,{children:"build_static_drivers"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_shared_drivers"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," as a ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-shared-library-build",children:(0,s.jsx)(n.code,{children:"Shared"})})," library."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_static_drivers"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build ",(0,s.jsx)(n.code,{children:"TinyDrivers"})," as a ",(0,s.jsx)(n.a,{href:"/tinydrivers/getting-started#the-static-build",children:(0,s.jsx)(n.code,{children:"Static"})})," library archive.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["The ",(0,s.jsx)(n.code,{children:"build_static_drivers"})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option will be select by default when the ",(0,s.jsx)(n.a,{href:"#qmake-static",children:(0,s.jsx)(n.code,{children:"CONFIG*=static"})})," is enabled."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"build_tests"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsx)(n.td,{children:"Build TinyORM unit tests."})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ccache"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Enable compiler cache. ",(0,s.jsx)(n.a,{href:"https://ccache.dev/",children:"Homepage"}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["It works on Windows and Unix systems. This option overrides qmake's ",(0,s.jsx)(n.code,{children:"ccache"})," option. It internally calls qmake's ",(0,s.jsx)(n.a,{href:"#qmake-ccache",children:(0,s.jsx)(n.code,{children:"ccache"})})," option on Unix and ",(0,s.jsx)(n.a,{href:"#tiny_ccache_win32",children:(0,s.jsx)(n.code,{children:"tiny_ccache_win32"})})," on Windows.",(0,s.jsx)("br",{}),"Reason: It allows using the same option on both OS-es."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_autoconf"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Disable the ",(0,s.jsx)(n.a,{href:"#auto-configuration-internals",children:(0,s.jsx)(n.code,{children:"Auto-configuration"})})," feature ",(0,s.jsxs)("small",{children:["(auto-configuration is enabled by default from ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"}),")"]}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_dotenv"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Disable the ",(0,s.jsx)(n.a,{href:"#environment-files",children:(0,s.jsx)(n.code,{children:"tiny_dotenv"})})," feature ",(0,s.jsxs)("small",{children:["(environment files are enabled by default from ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"v0.34.0"}),")"]}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_thread_local"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Remove all ",(0,s.jsx)(n.a,{href:"https://en.cppreference.com/w/c/language/storage_duration",children:(0,s.jsx)(n.code,{children:"thread_local"})})," storage duration specifiers, it disables multi-threading support."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_orm"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"ORM-related"})," source code, when this option is ",(0,s.jsx)(n.code,{children:"enabled"}),", then only the ",(0,s.jsx)(n.code,{children:"query builder"})," without ",(0,s.jsx)(n.code,{children:"ORM"})," is compiled. Also excludes ",(0,s.jsx)(n.code,{children:"ORM-related"})," unit tests."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"disable_tom"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Controls the compilation of all ",(0,s.jsx)(n.code,{children:"Tom-related"})," source code, when this option is ",(0,s.jsx)(n.code,{children:"disabled"}),", then it also excludes ",(0,s.jsx)(n.code,{children:"Tom-related"})," unit tests."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"extern_constants"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Use ",(0,s.jsx)(n.code,{children:"extern"})," constants instead of ",(0,s.jsx)(n.code,{children:"inline"})," constants in the ",(0,s.jsx)(n.code,{children:"shared build"}),".",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"ON"})," is highly recommended for the ",(0,s.jsx)(n.code,{children:"shared build"})," ",(0,s.jsx)("small",{children:"(by default)"}),";",(0,s.jsx)("br",{}),"is always ",(0,s.jsx)(n.code,{children:"OFF"})," for the ",(0,s.jsx)(n.code,{children:"static build"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)("code",{children:"CONFIG(shared|dll):!inline_constants"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"inline_constants"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Use ",(0,s.jsx)(n.code,{children:"inline"})," constants instead of ",(0,s.jsx)(n.code,{children:"extern"})," constants in the ",(0,s.jsx)(n.code,{children:"shared build"}),".",(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"OFF"})," is highly recommended for the ",(0,s.jsx)(n.code,{children:"shared build"}),";",(0,s.jsx)("br",{}),"is always ",(0,s.jsx)(n.code,{children:"ON"})," for the ",(0,s.jsx)(n.code,{children:"static build"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"link_pkgconfig_off"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Link against ",(0,s.jsx)(n.code,{children:"mysqlclient"})," or ",(0,s.jsx)(n.code,{children:"libmariadb"})," with ",(0,s.jsx)(n.code,{children:"PKGCONFIG"}),".",(0,s.jsx)("br",{}),"Used only in the ",(0,s.jsx)(n.code,{children:"Unix"})," and ",(0,s.jsx)(n.code,{children:"MinGW"})," ",(0,s.jsx)(n.strong,{children:"shared"})," build ",(0,s.jsxs)("small",{children:["(exactly ",(0,s.jsx)("code",{children:"win32-g++|win32-clang-g++"}),")"]})," and when ",(0,s.jsx)(n.code,{children:"mysql_ping"})," is also defined to link against ",(0,s.jsx)(n.code,{children:"mysqlclient"})," or ",(0,s.jsx)(n.code,{children:"libmariadb"}),", ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L132",children:"source code"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["Available when: ",(0,s.jsx)(n.code,{children:"unix:mysql_ping"})," or ",(0,s.jsx)("code",{children:"(win32-g++|win32-clang-g++):mysql_ping:!static:!staticlib"})]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"mysql_ping"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Enable ",(0,s.jsx)(n.code,{children:"Orm::MySqlConnection::pingDatabase()"})," method."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"tiny_ccache_win32"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ON"})}),(0,s.jsxs)(n.td,{children:["Enable compiler cache. ",(0,s.jsx)(n.a,{href:"https://ccache.dev/",children:"Homepage"}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["It works only on Windows systems. It works well with the MSYS2 ",(0,s.jsx)(n.code,{children:"g++"}),", ",(0,s.jsx)(n.code,{children:"clang++"}),", ",(0,s.jsx)(n.code,{children:"msvc"}),", and ",(0,s.jsx)(n.code,{children:"clang-cl"})," with ",(0,s.jsx)(n.code,{children:"msvc"}),". It disables ",(0,s.jsx)(n.code,{children:"precompile_header"})," as they are not supported on Windows and changes the ",(0,s.jsx)(n.code,{children:"-Zi"})," compiler option to the ",(0,s.jsx)(n.code,{children:"-Z7"})," for debug builds as the ",(0,s.jsx)(n.code,{children:"-Zi"})," compiler option is not supported (",(0,s.jsx)(n.a,{href:"https://github.com/ccache/ccache/issues/1040",children:"link"})," to the issue)."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"tom_example"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build the ",(0,s.jsx)("abbr",{title:"TinyORM Migrations",children:(0,s.jsx)(n.code,{children:"tom"})})," console application example."]})]})]})]})})}),"\n",(0,s.jsxs)(n.p,{children:["Advanced ",(0,s.jsx)(n.code,{children:"TinyORM"})," options."]}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Option Name"}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsx)(n.tbody,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ubsan"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Allows to enable ",(0,s.jsx)(n.a,{href:"https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html",children:"UBSan"})," sanitizer (Clang only)."]})]})})]})})}),"\n",(0,s.jsxs)(n.p,{children:["Important ",(0,s.jsx)(n.code,{children:"qmake"})," options."]}),"\n",(0,s.jsx)("div",{className:"apitable-build-options",children:(0,s.jsx)(l.A,{name:"qmake",children:(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsxs)(n.th,{children:[(0,s.jsx)(n.code,{children:"CONFIG"})," ",(0,s.jsx)("small",{children:"Option Name"})]}),(0,s.jsx)(n.th,{children:"Default"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"ccache"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Enable compiler cache. ",(0,s.jsx)(n.a,{href:"https://ccache.dev/",children:"Homepage"}),(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["It works only on the Unix systems. It works well with ",(0,s.jsx)(n.code,{children:"g++"})," and ",(0,s.jsx)(n.code,{children:"clang++"})," and also supports precompiled headers."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"precompile_header"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"-"})}),(0,s.jsxs)(n.td,{children:["Enable precompiled headers, you can disable them with:",(0,s.jsx)("br",{})," ",(0,s.jsx)(n.code,{children:"CONFIG-=precompile_header"}),".",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["The ",(0,s.jsx)(n.code,{children:"precompile_header"})," is enabled by default on ",(0,s.jsx)(n.code,{children:"msvc"}),", ",(0,s.jsx)(n.code,{children:"g++"}),", ",(0,s.jsx)(n.code,{children:"clang++"}),", ",(0,s.jsx)(n.code,{children:"clang-cl"})," on ",(0,s.jsx)(n.code,{children:"Windows"})," and disabled by default on ",(0,s.jsx)(n.code,{children:"linux"}),"."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsxs)(n.td,{children:[(0,s.jsx)(n.code,{children:"static"}),(0,s.jsx)("br",{}),(0,s.jsx)(n.code,{children:"staticlib"})]}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Build as a ",(0,s.jsx)(n.code,{children:"static"})," library (lib only).",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["If you want to build all libraries in the ",(0,s.jsx)(n.code,{children:"TinyORM"})," project as static library archives and link against static libraries use the ",(0,s.jsx)(n.a,{href:"https://doc.qt.io/qt/qmake-variable-reference.html#config",children:(0,s.jsx)(n.code,{children:"CONFIG += static"})}),". Don't use the ",(0,s.jsx)(n.code,{children:"CONFIG += staticlib"}),".",(0,s.jsx)("br",{}),"See ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/NOTES.txt",children:"NOTES.txt"})," for more information (search ",(0,s.jsx)(n.code,{children:"static vs staticlib"}),")."]})]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"static_runtime"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"OFF"})}),(0,s.jsxs)(n.td,{children:["Link against the ",(0,s.jsx)(n.code,{children:"shared"})," (dynamic) or ",(0,s.jsx)(n.code,{children:"static"})," run-time library.",(0,s.jsx)("br",{}),(0,s.jsxs)("small",{children:["The ",(0,s.jsx)(n.code,{children:"-MD"})," becomes ",(0,s.jsx)(n.code,{children:"-MT"})," and ",(0,s.jsx)(n.code,{children:"-MDd"})," becomes ",(0,s.jsx)(n.code,{children:"-MTd"}),". It works only on ",(0,s.jsx)(n.code,{children:"MSVC"})," and ",(0,s.jsx)(n.code,{children:"MinGW"})," or ",(0,s.jsx)(n.code,{children:"MSYS2"}),".",(0,s.jsx)("br",{}),"Please ",(0,s.jsx)("u",{children:"don't use"})," this option.",(0,s.jsx)("br",{}),"Available when: ",(0,s.jsx)(n.code,{children:"msvc"})," or ",(0,s.jsx)(n.code,{children:"mingw"})]})]})]})]})]})})}),"\n",(0,s.jsxs)(n.h3,{id:"consume-tinyorm-library-qmake",children:["Consume TinyOrm library ",(0,s.jsx)("small",{children:"(qmake)"})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/qmake/TinyOrm.pri",children:(0,s.jsx)(n.code,{children:"TinyOrm.pri"})})," file is available to simplify the integration of the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library into your application. It sets up and configures the ",(0,s.jsx)(n.code,{children:"CONFIG"})," and ",(0,s.jsx)(n.code,{children:"DEFINES"})," qmake variables, adds the ",(0,s.jsx)(n.code,{children:"TinyORM"}),", ",(0,s.jsx)("abbr",{title:"TinyORM Migrations",children:(0,s.jsx)(n.code,{children:"tom"})}),", and ",(0,s.jsx)(n.code,{children:"vcpkg"})," header files on the system ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," (cross-platform using the ",(0,s.jsx)(n.code,{children:"-isystem"})," or ",(0,s.jsx)(n.code,{children:"-imsvc"}),"), links against the TinyORM ",(0,s.jsx)(n.code,{children:"shared"})," or ",(0,s.jsx)(n.code,{children:"static"})," library using the ",(0,s.jsx)(n.code,{children:"LIBS"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["You can use it to configure the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library when you are linking against it. It does a very similar thing like the CMake's ",(0,s.jsx)(n.code,{children:"Find Modules"})," feature."]}),"\n",(0,s.jsx)(n.h4,{id:"requirements",children:"Requirements"}),"\n",(0,s.jsx)(n.p,{children:"It has a few requirements, you need to:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["specify path to the ",(0,s.jsx)(n.code,{children:"TinyORM"})," qmake features (",(0,s.jsx)(n.code,{children:".prf"})," files) using the ",(0,s.jsx)(n.code,{children:"QMAKEFEATURES"})," variable that can only be set in the ",(0,s.jsx)(n.code,{children:".qmake.conf"})," file"]}),"\n",(0,s.jsxs)(n.li,{children:["specify ",(0,s.jsx)(n.code,{children:"qmake"})," or ",(0,s.jsx)(n.code,{children:"environment"})," variables to find the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation ",(0,s.jsxs)("small",{children:["(",(0,s.jsx)(n.code,{children:"TINY_VCPKG_ROOT"})," and ",(0,s.jsx)(n.code,{children:"TINY_VCPKG_TRIPLET"}),")"]})]}),"\n",(0,s.jsxs)(n.li,{children:["specify path to the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build folder ",(0,s.jsxs)("small",{children:["(",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"}),")"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["you can specify it ",(0,s.jsx)(n.strong,{children:"manually"})]}),"\n",(0,s.jsxs)(n.li,{children:["or you can use ",(0,s.jsxs)(n.a,{href:"#partial-guessing-of-the-tinyorm_build_tree",children:["Partial guessing of the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})]})]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["build your application with the same ",(0,s.jsx)(n.code,{children:"CONFIG"})," ",(0,s.jsx)(n.code,{children:"qmake"})," variables that were used when building the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library"]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"Let's explain one by one."}),"\n",(0,s.jsx)(n.h5,{id:"qmakefeatures",children:(0,s.jsx)(n.code,{children:"QMAKEFEATURES"})}),"\n",(0,s.jsxs)(n.p,{children:["Create the ",(0,s.jsx)(n.code,{children:".qmake.conf"})," file in your application root folder with the following content."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"title='.qmake.conf'",children:"# Path to the PARENT folder of the TinyORM source folder\nTINY_MAIN_DIR = $$clean_path()\n# To find .env and .env.$$QMAKE_PLATFORM files in YOUR project\nTINY_DOTENV_ROOT = $$PWD\n\n# Path to the TinyORM build folder (specified manually)\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSVC2019_64bit-Debug/)\n# vcpkg - range-v3 and tabulate\nTINY_VCPKG_ROOT = $$quote(/vcpkg/)\n#TINY_VCPKG_TRIPLET = x64-windows\n\n# To find .prf files, needed by eg. CONFIG += tiny_system_headers inline/extern_constants\nQMAKEFEATURES *= $$quote($$TINY_MAIN_DIR/TinyORM/qmake/features)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["You can move all ",(0,s.jsx)(n.code,{children:"qmake"})," variables that are part of the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration process to the ",(0,s.jsx)(n.code,{children:".env"})," file if you want (recommended), this is possible because the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," enables the ",(0,s.jsx)(n.a,{href:"#environment-files",children:(0,s.jsx)(n.code,{children:"Environment files"})})," feature by default."]}),"\n",(0,s.jsxs)(n.p,{children:["You can look at the ",(0,s.jsx)(n.a,{href:"/building/hello-world#auto-configure-using-qmake_conf-and-env",children:"Auto-configure using .qmake.conf and .env"})," example for ",(0,s.jsx)(n.code,{children:"Hello world"})," project of what must stay in the ",(0,s.jsx)(n.code,{children:"qmake.conf"})," file and what can be moved to the ",(0,s.jsx)(n.code,{children:".env"})," files."]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can use the ",(0,s.jsxs)(n.a,{href:"#partial-guessing-of-the-tinyorm_build_tree",children:["Partial guessing of the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})]})," if you don't like to specify it manually."]})}),"\n",(0,s.jsxs)(n.h5,{id:"variables-affecting-tinyormpri",children:["Variables affecting ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})]}),"\n",(0,s.jsxs)(n.p,{children:["You must define the following variables before the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," is included:"]}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build folder."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_ROOT"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation folder.",(0,s.jsx)("br",{}),"If not defined, then it tries to use the ",(0,s.jsx)(n.code,{children:"VCPKG_ROOT"})," environment variable."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_TRIPLET"})}),(0,s.jsxs)(n.td,{children:["The ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"triplet"})," to use ",(0,s.jsx)("small",{children:"(vcpkg/installed/$$TINY_VCPKG_TRIPLET/)"}),".",(0,s.jsx)("br",{}),"If not defined, then it tries to guess the ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"triplet"})," based on the current compiler and OS (based on the ",(0,s.jsx)(n.code,{children:"QMAKESPEC"}),"), and as the last thing, it tries to use the ",(0,s.jsx)(n.code,{children:"VCPKG_DEFAULT_TRIPLET"})," environment variable."]})]})]})]}),"\n",(0,s.jsx)(n.p,{children:"These variables will be set after the configuration is done:"}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_BUILD_SUBFOLDER"})}),(0,s.jsxs)(n.td,{children:["Folder by release type if ",(0,s.jsx)(n.code,{children:"CONFIG+=debug_and_release"})," is defined ",(0,s.jsx)("small",{children:"(/debug, /release, or an empty string)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_CCACHE_BUILD"})}),(0,s.jsxs)(n.td,{children:["To correctly link ",(0,s.jsx)(n.code,{children:"ccache"})," build against a ",(0,s.jsx)(n.code,{children:"ccache"})," build ",(0,s.jsx)("small",{children:"(_ccache or an empty string)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MSVC_VERSION"})}),(0,s.jsxs)(n.td,{children:["The ",(0,s.jsx)(n.code,{children:"msvc"})," compiler string ",(0,s.jsx)("small",{children:"(MSVC2022 or MSVC2019)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_QT_VERSION_UNDERSCORED"})}),(0,s.jsxs)(n.td,{children:["Underscored ",(0,s.jsx)(n.code,{children:"Qt"})," version ",(0,s.jsx)("small",{children:"(eg. 6_7_0)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_RELEASE_TYPE_CAMEL"})}),(0,s.jsxs)(n.td,{children:["Build type string ",(0,s.jsx)("small",{children:"(Debug, Profile, or Release)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_INCLUDE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"include"})," folder ",(0,s.jsx)("small",{children:"(vcpkg/installed//include/)"}),"."]})]})]})]}),"\n",(0,s.jsxs)(n.p,{children:["Then you simply include the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," in your project file."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"title='AnyProject.pro'",children:"include($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["And that is all, now you should be able to link against the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library. \ud83d\udc4c"]}),"\n",(0,s.jsx)(n.h5,{id:"manual-configuration-examples",children:"Manual configuration examples"}),"\n",(0,s.jsxs)(n.p,{children:["Frankly, there is no reason to use the Manual configuration (define the variables described below before the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," inclusion), the only reason to use it is when you want more control over this process or want to define everything yourself. I'll leave this section here to show how things work."]}),"\n",(0,s.jsxs)(n.p,{children:["You will have to link against the ",(0,s.jsx)(n.code,{children:"TinyORM"})," library manually if you don't set the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})," ",(0,s.jsx)(n.code,{children:"qmake"})," variable before the inclusion of the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," file. The ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," is auto-detected every time."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"{9}",children:"# Link against TinyORM library\n# ---\nTINY_MAIN_DIR = $$clean_path()\n\n# Configure TinyORM library\ninclude($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n\n# TinyORM library path\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake)\nLIBS += $$quote(-L$$TINYORM_BUILD_TREE/build-TinyORM-Desktop_Qt_6_7_0_MSVC2019_64bit-Debug/src$${TINY_BUILD_SUBFOLDER}/)\nLIBS += -lTinyOrm\n"})})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"{9}",children:"# Link against TinyORM library\n# ---\nTINY_MAIN_DIR = $$clean_path()\n\n# Configure TinyORM library\ninclude($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n\n# TinyORM library path\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake)\nLIBS += $$quote(-L$$TINYORM_BUILD_TREE/build-TinyORM-Desktop_Qt_6_7_0_GCC_64bit-Debug/src$${TINY_BUILD_SUBFOLDER}/)\nLIBS += -lTinyOrm\n"})})})]}),"\n",(0,s.jsxs)(n.p,{children:["The same is true for the ",(0,s.jsx)(n.code,{children:"vcpkg"})," include path. If you don't set the ",(0,s.jsx)(n.code,{children:"TINY_VCPKG_ROOT"})," or have not defined the ",(0,s.jsx)(n.code,{children:"VCPKG_ROOT"})," environment variable, then you need to set up the ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," for the ",(0,s.jsx)(n.code,{children:"vcpkg"})," that provides the ",(0,s.jsx)(n.code,{children:"range-v3"})," and ",(0,s.jsx)(n.code,{children:"tabulate"})," header files."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",children:"# vcpkg - range-v3 and tabulate\n# ---\nINCLUDEPATH += $$quote(/vcpkg/installed/x64-windows/include/)\n"})})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",children:"# vcpkg - range-v3 and tabulate\n# ---\nQMAKE_CXXFLAGS += -isystem $$shell_quote(/vcpkg/installed/x64-linux/include/)\n"})})})]}),"\n",(0,s.jsxs)(n.p,{children:["You can also use TinyORM's ",(0,s.jsx)(n.code,{children:"qmake"})," function ",(0,s.jsx)(n.code,{children:"tiny_add_system_includepath()"})," which handles ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," in a cross-platform way."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",children:"# vcpkg - range-v3 and tabulate\n# ---\nload(tiny_system_includepath)\ntiny_add_system_includepath(/vcpkg/installed/x64-linux/include/)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["Do not forget to add ",(0,s.jsx)(n.code,{children:"TinyOrm0.dll"})," on the path on Windows and on the ",(0,s.jsx)(n.code,{children:"LD_LIBRARY_PATH"})," on Linux, so your application can find it during execution."]}),"\n",(0,s.jsxs)(o.A,{groupId:y.vf,name:"tinyorm-on-path",children:[(0,s.jsx)(t.A,{value:y.b,label:y.ux,children:(0,s.jsx)(c.A,{className:"language-powershell",children:`$env:Path = "${(0,x.OZ)(y.b,!1)}\\TinyORM\\TinyORM-builds-qmake\\build-debug;" + $env:Path`})}),(0,s.jsx)(t.A,{value:y.xj,label:y.gg,children:(0,s.jsx)(c.A,{className:"language-bash",children:`export LD_LIBRARY_PATH=${(0,x.OZ)(y.xj)}/TinyORM/TinyORM-builds-qmake/build-debug\${PATH:+:}$PATH`})})]}),"\n",(0,s.jsxs)(n.admonition,{type:"tip",children:[(0,s.jsxs)(n.p,{children:["On Linux ",(0,s.jsx)(n.code,{children:"-isystem"})," marks the directory as a system directory, it prevents warnings."]}),(0,s.jsxs)(n.p,{children:["On Windows you can use ",(0,s.jsx)(n.code,{children:"QMAKE_CXXFLAGS_WARN_ON = -external:anglebrackets -external:W0"}),", it applies a warning level 0 to the angel bracket includes; ",(0,s.jsx)(n.code,{children:"#include "}),"."]}),(0,s.jsxs)(n.p,{children:["With the ",(0,s.jsx)(n.code,{children:"clang-cl"})," with ",(0,s.jsx)(n.code,{children:"MSVC"})," you can use ",(0,s.jsx)(n.code,{children:"-imsvc"}),"."]})]}),"\n",(0,s.jsx)(n.h3,{id:"auto-configuration-internals",children:"Auto-configuration internals"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"qmake"})," build system does not support ",(0,s.jsx)(n.code,{children:"auto-configuration"})," of dependencies out of the box but ",(0,s.jsx)(n.code,{children:"TinyORM"})," from ",(0,s.jsx)(n.code,{children:"v0.34.0"})," added its own ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature along with the ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," qmake feature. These new features allow us to ",(0,s.jsx)(n.code,{children:"auto-configure"})," ",(0,s.jsx)(n.code,{children:"TinyORM"})," project, and with their help, the ",(0,s.jsx)(n.code,{children:"conf.pri"})," files can be ",(0,s.jsx)("u",{children:"skipped entirely"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["While it adds additional complexity to the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration process, the benefits are significant."]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature is designed to find the ",(0,s.jsx)(n.code,{children:"vcpkg"})," and ",(0,s.jsx)(n.code,{children:"MySQL"})," installations, and ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," to include the ",(0,s.jsx)(n.code,{children:".env"})," and ",(0,s.jsx)(n.code,{children:".env.(win32|unix|mingw)"})," files in the project's root folder. These new features can be configured using ",(0,s.jsx)(n.code,{children:"qmake"})," and ",(0,s.jsx)(n.code,{children:"environment"})," variables, and they also contain some guessing logic if these variables are not defined."]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature can be turned off using the ",(0,s.jsx)(n.a,{href:"#disable_autoconf",children:(0,s.jsx)(n.code,{children:"disable_autoconf"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_autoconf"}),")."]}),"\n",(0,s.jsxs)(n.p,{children:["These are ",(0,s.jsx)("u",{children:(0,s.jsx)(n.code,{children:"qmake"})})," and ",(0,s.jsx)("u",{children:(0,s.jsx)(n.code,{children:"environment"})})," variables that affect the ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature:"]}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_ROOT"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"vcpkg"})," installation folder.",(0,s.jsx)("br",{}),"If not defined, then it tries to use the ",(0,s.jsx)(n.code,{children:"VCPKG_ROOT"})," environment variable."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_TRIPLET"})}),(0,s.jsxs)(n.td,{children:["The ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"triplet"})," to use ",(0,s.jsx)("small",{children:"(vcpkg/installed/$$TINY_VCPKG_TRIPLET/)"}),".",(0,s.jsx)("br",{}),"If not defined, then it tries to guess the ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"triplet"})," based on the current compiler and OS (based on the ",(0,s.jsx)(n.code,{children:"QMAKESPEC"}),"), and as the last thing, it tries to use the ",(0,s.jsx)(n.code,{children:"VCPKG_DEFAULT_TRIPLET"})," environment variable."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MYSQL_ROOT"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"MySQL"})," installation folder.",(0,s.jsx)("br",{}),"If not defined, then it tries to guess the ",(0,s.jsx)(n.code,{children:"MySQL"})," installation folder (",(0,s.jsx)(n.code,{children:"win32"})," only): ",(0,s.jsx)("code",{children:"$$(ProgramFiles)/MySQL/MySQL Server (8.4|8.3|8.2|8.1|8.0|5.7)/"})]})]})]})]}),"\n",(0,s.jsxs)(n.p,{children:["You can set these variables in the ",(0,s.jsx)(n.code,{children:".env"})," (recommended) or ",(0,s.jsx)(n.code,{children:"conf.pri"})," files, in the ",(0,s.jsx)(n.code,{children:".qmake.conf"})," file (or wherever you want), or as environment variables."]}),"\n",(0,s.jsxs)(n.p,{children:["These variables will be set after ",(0,s.jsx)(n.code,{children:"auto-configuration"})," is done:"]}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_VCPKG_INCLUDE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"vcpkg"})," ",(0,s.jsx)(n.code,{children:"include"})," folder ",(0,s.jsx)("small",{children:"(vcpkg/installed//include/)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MYSQL_INCLUDE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"MySQL"})," ",(0,s.jsx)(n.code,{children:"include"})," folder ",(0,s.jsx)("small",{children:"(MySQL Server 8.4/include/)"}),"."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MYSQL_LIB"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.code,{children:"MySQL"})," ",(0,s.jsx)(n.code,{children:"lib"})," folder ",(0,s.jsx)("small",{children:"(MySQL Server 8.4/lib/)"}),"."]})]})]})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"TINY_MYSQL_INCLUDE"})," and ",(0,s.jsx)(n.code,{children:"TINY_MYSQL_LIB"})," are only set on ",(0,s.jsx)(n.code,{children:"win32"})," platform except ",(0,s.jsx)(n.code,{children:"mingw"}),"."]}),"\n",(0,s.jsx)(n.h4,{id:"environment-files",children:"Environment files"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," feature allows us to define the ",(0,s.jsx)(n.code,{children:".env"})," and ",(0,s.jsx)(n.code,{children:".env.$$TINY_DOTENV_PLATFORM"})," files in the project's root folder. These files are loaded as early as possible so you can affect the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration process. On the other hand, the ",(0,s.jsx)(n.code,{children:"conf.pri"})," files are loaded as late as possible, and they can be used to override the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration."]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:".env"})," file is included ",(0,s.jsx)("u",{children:"first"})," and is included on all platforms."]}),"\n",(0,s.jsxs)(n.p,{children:["There is only one requirement for this feature to work correctly, and that is to set the ",(0,s.jsx)(n.code,{children:"TINY_DOTENV_ROOT"})," ",(0,s.jsx)(n.code,{children:"qmake"})," variable to the project's root folder. This variable is ",(0,s.jsx)(n.strong,{children:"already"})," set in the ",(0,s.jsx)(n.code,{children:".qmake.conf"})," file for the ",(0,s.jsx)(n.code,{children:"TinyORM"})," project."]}),"\n",(0,s.jsx)(n.p,{children:"Then the following names are taken into account: .env, .env.win32, .env.unix, .env.mingw"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"title='.qmake.conf'",children:"# To find .env and .env.$$QMAKE_PLATFORM files\nTINY_DOTENV_ROOT = $$PWD\n"})}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"tiny_dotenv"})," feature can be turned off using the ",(0,s.jsx)(n.a,{href:"#disable_dotenv",children:(0,s.jsx)(n.code,{children:"disable_dotenv"})})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration option (eg. ",(0,s.jsx)(n.code,{children:"CONFIG*=disable_dotenv"}),")."]}),"\n",(0,s.jsx)(n.admonition,{type:"warning",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Environment files"})," don't work in the ",(0,s.jsx)(n.code,{children:"CMake"})," builds."]})}),"\n",(0,s.jsxs)(n.h4,{id:"partial-guessing-of-the-tinyorm_build_tree",children:["Partial guessing of the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})]}),"\n",(0,s.jsxs)(n.p,{children:["You don't have to manually define the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})," in ",(0,s.jsx)(n.code,{children:".env"})," or ",(0,s.jsx)(n.code,{children:".qmake.conf"})," files. The ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})," absolute path can be put together for you (this is happening inside the ",(0,s.jsx)(n.code,{children:"variables.pri"})," file) and ",(0,s.jsx)(n.code,{children:"TinyORM"})," build folder name can be guessed for you too."]}),"\n",(0,s.jsxs)(n.p,{children:["You must define the following variables before the ",(0,s.jsx)(n.code,{children:"TinyOrm.pri"})," will be included to make this real (set them in the ",(0,s.jsx)(n.code,{children:".qmake.conf"}),"):"]}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Variable Name"}),(0,s.jsx)(n.th,{children:"Description"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_MAIN_DIR"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.strong,{children:"PARENT"})," folder of the ",(0,s.jsx)(n.code,{children:"TinyORM"})," source folder."]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"TINY_BUILD_TREE"})}),(0,s.jsxs)(n.td,{children:["Path to the ",(0,s.jsx)(n.strong,{children:"current"})," build tree - ",(0,s.jsx)(n.code,{children:"TINY_BUILD_TREE = $$shadowed($$PWD)"}),"."]})]})]})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"TINY_MAIN_DIR"})," is required for another features anyway (so it should already be set) and all that's left is to set the ",(0,s.jsx)(n.code,{children:"TINY_BUILD_TREE"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-qmake",metastring:"title='.qmake.conf'",children:"# Path to the current build tree (used to guess the TinyORM build tree)\nTINY_BUILD_TREE = $$shadowed($$PWD)\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If you will follow this pattern or logic then you can switch ",(0,s.jsx)(n.code,{children:"QtCreator Kits"})," and the ",(0,s.jsx)(n.code,{children:"TINYORM_BUILD_TREE"})," will be ",(0,s.jsx)(n.strong,{children:"auto-generated"})," correctly and will always point to the correct ",(0,s.jsx)(n.code,{children:"TinyORM"})," build tree."]}),"\n",(0,s.jsxs)(n.p,{children:["It works this way, all is happening inside the ",(0,s.jsx)(n.code,{children:"variables.pri"}),", it takes a build folder name for the ",(0,s.jsx)(n.strong,{children:"current"})," project eg. ",(0,s.jsx)(n.code,{children:"build-HelloWorld-Desktop_Qt_6_7_0_MSVC2022_64bit-Debug"}),", replaces the ",(0,s.jsx)(n.code,{children:"HelloWorld"})," with the ",(0,s.jsx)(n.code,{children:"TinyORM"})," and as we already know the ",(0,s.jsx)(n.code,{children:"TinyORM"})," build folder location we can simply concatenate these paths like ",(0,s.jsx)(n.code,{children:"$$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSVC2022_64bit-Debug"}),"."]}),"\n",(0,s.jsx)(n.admonition,{type:"warning",children:(0,s.jsxs)(n.p,{children:["This will only work if you follow the recommended ",(0,s.jsx)(n.a,{href:"#folders-structure",children:(0,s.jsx)(n.code,{children:"Folders structure"})}),"."]})}),"\n",(0,s.jsx)(n.h3,{id:"manual-configuration-internals",children:"Manual configuration internals"}),"\n",(0,s.jsxs)(n.p,{children:["There is not much to say about the ",(0,s.jsx)(n.code,{children:"Manual configuration"})," feature. It uses ",(0,s.jsx)(n.code,{children:"conf.pri"})," files (there are four, one for every project or sub-project), and every project has prepared its own ",(0,s.jsx)(n.code,{children:"conf.pri.example"})," file for faster initial configuration."]}),"\n",(0,s.jsxs)(n.p,{children:["These ",(0,s.jsx)(n.code,{children:"conf.pri.example"})," files are nicely commented on, so you can see what needs to be modified. The ",(0,s.jsx)(n.code,{children:"conf.pri"})," files are loaded as late as possible, and they can be used to override the ",(0,s.jsx)(n.code,{children:"qmake"})," configuration."]}),"\n",(0,s.jsxs)(n.p,{children:["If the ",(0,s.jsx)(n.code,{children:"Auto-configuration"})," feature is disabled and there are no ",(0,s.jsx)(n.code,{children:"conf.pri"})," files, then the ",(0,s.jsx)(n.code,{children:"TinyORM"})," ",(0,s.jsx)(n.code,{children:"qmake"})," configuration or build will fail at 100%."]}),"\n",(0,s.jsxs)(n.p,{children:["These ",(0,s.jsx)(n.code,{children:"conf.pri"})," files are intended for configuring qmake's ",(0,s.jsx)(n.code,{children:"INCLUDEPATH"})," and ",(0,s.jsx)(n.code,{children:"LIBS"}),", ",(0,s.jsx)(n.code,{children:"CONFIG"})," or eg. ",(0,s.jsx)(n.code,{children:"QMAKE_LFLAGS"}),", or any other ",(0,s.jsx)(n.code,{children:"qmake"})," options or variables."]}),"\n",(0,s.jsx)(n.h2,{id:"ccache-support",children:"Ccache support"}),"\n",(0,s.jsxs)(n.p,{children:["The TinyORM supports the ",(0,s.jsx)(n.a,{href:"https://ccache.dev/",children:(0,s.jsx)(n.code,{children:"ccache"})})," out of the box for all ",(0,s.jsx)(n.a,{href:"/supported-compilers",children:"supported compilers"}),". For ",(0,s.jsx)(n.code,{children:"qmake"})," you can enable it using the ",(0,s.jsx)(n.a,{href:"#ccache",children:(0,s.jsx)(n.code,{children:"CONFIG+=ccache"})})," and for ",(0,s.jsx)(n.code,{children:"CMake"})," you can set the ",(0,s.jsx)(n.a,{href:"#CMAKE_CXX_COMPILER_LAUNCHER",children:(0,s.jsx)(n.code,{children:"CMAKE_CXX_COMPILER_LAUNCHER=ccache"})}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["On ",(0,s.jsx)(n.code,{children:"Linux"})," it's clear, the ",(0,s.jsx)(n.code,{children:"ccache"})," is fully supported and works also with the ",(0,s.jsx)(n.code,{children:"precompiled headers"}),". But was necessary to add some workarounds to the ",(0,s.jsx)(n.code,{children:"qmake"}),"/",(0,s.jsx)(n.code,{children:"CMake"})," build systems to make out of the box support on ",(0,s.jsx)(n.code,{children:"Windows"}),". When you enable the ",(0,s.jsx)(n.code,{children:"ccache"})," on ",(0,s.jsx)(n.code,{children:"Windows"})," then the build system disables ",(0,s.jsx)(n.code,{children:"precompiled headers"})," and replaces the ",(0,s.jsx)(n.code,{children:"-Zi"})," compiler option with the ",(0,s.jsx)(n.code,{children:"-Z7"})," (link to the ",(0,s.jsx)(n.a,{href:"https://github.com/ccache/ccache/issues/1040",children:"issue"}),")."]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsxs)(n.p,{children:["You can install the ",(0,s.jsx)(n.code,{children:"ccache"})," using the ",(0,s.jsx)(n.code,{children:"scoop install ccache"})," command on Windows. See the ",(0,s.jsx)(n.a,{href:"/dependencies#linux-installation-ccache",children:"Dependencies"})," page for how to install ",(0,s.jsx)(n.code,{children:"ccache"})," on Linux."]})})]})}function I(e={}){const{wrapper:n}={...(0,d.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(M,{...e})}):M(e)}},9365:(e,n,i)=>{i.d(n,{A:()=>l});i(6540);var s=i(4164);const d={tabItem:"tabItem_Ymn6"};var r=i(4848);function l(e){let{children:n,hidden:i,className:l}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)(d.tabItem,l),hidden:i,children:n})}},1470:(e,n,i)=>{i.d(n,{A:()=>_});var s=i(6540),d=i(4164),r=i(3104),l=i(6347),c=i(205),t=i(7485),o=i(1682),a=i(9466);function h(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function x(e){const{values:n,children:i}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return h(e).map((e=>{let{props:{value:n,label:i,attributes:s,default:d}}=e;return{value:n,label:i,attributes:s,default:d}}))}(i);return function(e){const n=(0,o.X)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,i])}function j(e){let{value:n,tabValues:i}=e;return i.some((e=>e.value===n))}function u(e){let{queryString:n=!1,groupId:i}=e;const d=(0,l.W6)(),r=function(e){let{queryString:n=!1,groupId:i}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!i)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return i??null}({queryString:n,groupId:i});return[(0,t.aZ)(r),(0,s.useCallback)((e=>{if(!r)return;const n=new URLSearchParams(d.location.search);n.set(r,e),d.replace({...d.location,search:n.toString()})}),[r,d])]}function p(e){const{defaultValue:n,queryString:i=!1,groupId:d}=e,r=x(e),[l,t]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:i}=e;if(0===i.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!j({value:n,tabValues:i}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${i.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=i.find((e=>e.default))??i[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:r}))),[o,h]=u({queryString:i,groupId:d}),[p,m]=function(e){let{groupId:n}=e;const i=function(e){return e?`docusaurus.tab.${e}`:null}(n),[d,r]=(0,a.Dv)(i);return[d,(0,s.useCallback)((e=>{i&&r.set(e)}),[i,r])]}({groupId:d}),b=(()=>{const e=o??p;return j({value:e,tabValues:r})?e:null})();(0,c.A)((()=>{b&&t(b)}),[b]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!j({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);t(e),h(e),m(e)}),[h,m,r]),tabValues:r}}var m=i(2303);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=i(4848);function g(e){let{className:n,block:i,selectedValue:s,selectValue:l,tabValues:c}=e;const t=[],{blockElementScrollPositionUntilNextRender:o}=(0,r.a_)(),a=e=>{const n=e.currentTarget,i=t.indexOf(n),d=c[i].value;d!==s&&(o(n),l(d))},h=e=>{let n=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const i=t.indexOf(e.currentTarget)+1;n=t[i]??t[0];break}case"ArrowLeft":{const i=t.indexOf(e.currentTarget)-1;n=t[i]??t[t.length-1];break}}n?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,d.A)("tabs",{"tabs--block":i},n),children:c.map((e=>{let{value:n,label:i,attributes:r}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>t.push(e),onKeyDown:h,onClick:a,...r,className:(0,d.A)("tabs__item",b.tabItem,r?.className,{"tabs__item--active":s===n}),children:i??n},n)}))})}function y(e){let{lazy:n,children:i,selectedValue:d}=e;const r=(Array.isArray(i)?i:[i]).filter(Boolean);if(n){const e=r.find((e=>e.props.value===d));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:r.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==d})))})}function T(e){const n=p(e);return(0,f.jsxs)("div",{className:(0,d.A)("tabs-container",b.tabList),children:[(0,f.jsx)(g,{...n,...e}),(0,f.jsx)(y,{...n,...e})]})}function _(e){const n=(0,m.A)();return(0,f.jsx)(T,{...e,children:h(e.children)},String(n))}},6684:(e,n,i)=>{i.d(n,{A:()=>a});var s=i(6540),d=i(3427),r=i(6347);const l={apiTable:"apiTable_flxF"};var c=i(4848);function t(e,n){let{name:i,children:l}=e;const t=function(e){let n=e;for(;(0,s.isValidElement)(n);)[n]=s.Children.toArray(n.props.children);if("string"!=typeof n)throw new Error(`Could not extract APITable row name from JSX tree:\n${JSON.stringify(e,null,2)}`);return n}(l),o=i?`${i}-${t}`:t,a=`#${o}`,h=(0,r.W6)();return(0,d.A)().collectAnchor(o),(0,c.jsx)("tr",{id:o,tabIndex:0,ref:h.location.hash===a?n:void 0,onClick:e=>{const n=e.target;[n,n.parentElement].some((e=>"A"===e?.tagName.toUpperCase()))||h.push(a)},onKeyDown:e=>{"Enter"===e.key&&h.push(a)},children:l.props.children})}const o=s.forwardRef(t);function a(e){let{children:n,name:i}=e;if("table"!==n.type)throw new Error("Bad usage of APITable component.\nIt is probably that your Markdown table is malformed.\nMake sure to double-check you have the appropriate number of columns for each table row.");const[d,r]=s.Children.toArray(n.props.children),t=(0,s.useRef)(null);(0,s.useEffect)((()=>{t.current?.focus()}),[t]);const a=s.Children.map(r.props.children,(e=>(0,c.jsx)(o,{name:i,ref:t,children:e})));return(0,c.jsxs)("table",{className:l.apiTable,children:[d,(0,c.jsx)("tbody",{children:a})]})}},7324:(e,n,i)=>{i.d(n,{$E:()=>m,A3:()=>f,CW:()=>b,Dx:()=>a,F4:()=>x,Fi:()=>o,J_:()=>_,LQ:()=>g,Lf:()=>v,OO:()=>d,Q7:()=>y,b:()=>c,cy:()=>t,gg:()=>u,kl:()=>j,os:()=>h,pW:()=>r,ux:()=>p,vf:()=>s,xj:()=>l,xt:()=>T});const s="shell",d="database",r="application",l="bash",c="pwsh",t="zsh",o="maria",a="mysql",h="postgres",x="sqlite",j="application",u="bash",p="pwsh",m="zsh",b="MariaDB",f="MySQL",g="PostgreSQL",y="SQLite",T="tinyorm.org",_="$HOME/Code/c/",v="$env:USERPROFILE\\Code\\c\\"},6362:(e,n,i)=>{i.d(n,{A:()=>r});var s=i(6540),d=i(1838);function r(){const e=(0,s.useContext)(d.A);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6694:(e,n,i)=>{i.d(n,{OZ:()=>t,Sn:()=>l,T3:()=>a,bw:()=>o,nC:()=>h,np:()=>c});var s=i(6362),d=i(2303),r=i(7324);const l=function(e,n){return void 0===n&&(n=!0),x((0,s.A)().rootFolder[e]??o(e),e,n)},c=()=>(0,s.A)().rootFolder[r.pW]??o(r.pW),t=function(e,n){if(void 0===n&&(n=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const i=n||e!==r.b?"/":"\\";return x(l(e)+i+c(),e,n)};function o(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,d.A)())return"";switch(e){case r.b:return r.Lf;case r.xj:return r.J_;case r.pW:return r.xt;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function a(e){return e===r.pW}function h(e,n){if(null==n||""===n)return n;const i="$ENV{$1}$2";switch(e){case r.b:return u(n).replace(/\$env:(.+?)(\/.*)/,i);case r.xj:return n.replace(/\$(.+?)(\/.*)/,i);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function x(e,n,i){if(void 0===i&&(i=!0),null==e||""===e)return e;if(n!==r.b)return j(e);const s=j(e);return i?u(s):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(s)}function j(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function u(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},2721:(e,n,i)=>{i.d(n,{A:()=>s});const s=i.p+"assets/images/qmake-additional_arguments-14d3b6b82ad6d28db5b999a462500a6a.png"},7619:(e,n,i)=>{i.d(n,{A:()=>s});const s=i.p+"assets/images/qmake-build_settings-7caa6d7c86232484b82acb24b5a3a6a7.png"},885:(e,n,i)=>{i.d(n,{A:()=>s});const s=i.p+"assets/images/qmake-configure_project-0b6821ea0523567dab9f21b3215055a3.png"}}]);
\ No newline at end of file
diff --git a/assets/js/5b254f70.1b55ed2b.js b/assets/js/5b254f70.dec04c5b.js
similarity index 99%
rename from assets/js/5b254f70.1b55ed2b.js
rename to assets/js/5b254f70.dec04c5b.js
index 15b7d5954..b2c9034c4 100644
--- a/assets/js/5b254f70.1b55ed2b.js
+++ b/assets/js/5b254f70.dec04c5b.js
@@ -1 +1 @@
-"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[82],{5105:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>o,contentTitle:()=>d,default:()=>m,frontMatter:()=>l,metadata:()=>r,toc:()=>c});var i=t(4848),s=t(8453),a=t(8774);const l={sidebar_position:0,sidebar_label:"Getting Started",description:'TinyORM is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using TinyORM, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, TinyORM models allow you to insert, update, and delete records from the table as well.',keywords:["c++ orm","orm","getting started","tinyorm"]},d="TinyORM: Getting Started",r={id:"tinyorm/getting-started",title:"TinyORM: Getting Started",description:'TinyORM is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using TinyORM, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, TinyORM models allow you to insert, update, and delete records from the table as well.',source:"@site/docs/tinyorm/getting-started.mdx",sourceDirName:"tinyorm",slug:"/tinyorm/getting-started",permalink:"/tinyorm/getting-started",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"Getting Started",description:'TinyORM is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using TinyORM, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, TinyORM models allow you to insert, update, and delete records from the table as well.',keywords:["c++ orm","orm","getting started","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Seeding",permalink:"/database/seeding"},next:{title:"Relationships",permalink:"/tinyorm/relationships"}},o={},c=[{value:"Introduction",id:"introduction",level:2},{value:"Generating Model Classes",id:"generating-model-classes",level:2},{value:"TinyORM Model Conventions",id:"tinyorm-model-conventions",level:2},{value:"Table Names",id:"table-names",level:3},{value:"Primary Keys",id:"primary-keys",level:3},{value:""Composite" Primary Keys",id:"composite-primary-keys",level:4},{value:"Timestamps",id:"timestamps",level:3},{value:"Unix timestamps",id:"unix-timestamps",level:5},{value:"Custom timestamp column names",id:"custom-timestamp-column-names",level:5},{value:"Touching timestamps",id:"touching-timestamps",level:4},{value:"Database Connections",id:"database-connections",level:3},{value:"Default Attribute Values",id:"default-attribute-values",level:2},{value:"QDateTime and connection name problem",id:"qdatetime-and-connection-name-problem",level:5},{value:"Retrieving Models",id:"retrieving-models",level:2},{value:"Building Queries",id:"building-queries",level:4},{value:"Refreshing Models",id:"refreshing-models",level:4},{value:"Containers",id:"containers",level:3},{value:"Chunking Results",id:"chunking-results",level:3},{value:"Advanced Subqueries",id:"advanced-subqueries",level:3},{value:"Subquery Selects",id:"subquery-selects",level:4},{value:"Subquery Ordering",id:"subquery-ordering",level:4},{value:"Retrieving Single Models / Aggregates",id:"retrieving-single-models-and-aggregates",level:2},{value:"Not Found Exceptions",id:"not-found-exceptions",level:4},{value:"Retrieving Or Creating Models",id:"retrieving-or-creating-models",level:3},{value:"Retrieving Aggregates",id:"retrieving-aggregates",level:3},{value:"Inserting & Updating Models",id:"inserting-and-updating-models",level:2},{value:"Inserts",id:"inserts",level:3},{value:"Updates",id:"updates",level:3},{value:"Mass Updates",id:"mass-updates",level:4},{value:"Examining Attribute Changes",id:"examining-attribute-changes",level:4},{value:"Mass Assignment",id:"mass-assignment",level:3},{value:"Allowing Mass Assignment",id:"allowing-mass-assignment",level:4},{value:"Upserts",id:"upserts",level:3},{value:"Deleting Models",id:"deleting-models",level:2},{value:"Deleting An Existing Model By Its Primary Key",id:"deleting-an-existing-model-by-its-primary-key",level:4},{value:"Deleting Models Using Queries",id:"deleting-models-using-queries",level:4},{value:"Soft Deleting",id:"soft-deleting",level:3},{value:"Restoring Soft Deleted Models",id:"restoring-soft-deleted-models",level:4},{value:"Permanently Deleting Models",id:"permanently-deleting-models",level:4},{value:"Querying Soft Deleted Models",id:"querying-soft-deleted-models",level:3},{value:"Including Soft Deleted Models",id:"including-soft-deleted-models",level:4},{value:"Retrieving Only Soft Deleted Models",id:"retrieving-only-soft-deleted-models",level:4},{value:"Excluding Soft Deleted Models",id:"excluding-soft-deleted-models",level:4},{value:"Truncate Table",id:"truncate-table",level:3},{value:"Replicating Models",id:"replicating-models",level:2},{value:"Comparing Models",id:"comparing-models",level:2},{value:"Equality comparison",id:"equality-comparison",level:5}];function h(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h1,{id:"tinyorm-getting-started",children:"TinyORM: Getting Started"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#introduction",children:"Introduction"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#generating-model-classes",children:"Generating Model Classes"})}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#tinyorm-model-conventions",children:"TinyORM Model Conventions"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#table-names",children:"Table Names"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#primary-keys",children:"Primary Keys"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#timestamps",children:"Timestamps"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#database-connections",children:"Database Connections"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#default-attribute-values",children:"Default Attribute Values"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#retrieving-models",children:"Retrieving Models"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#containers",children:"Containers"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#chunking-results",children:"Chunking Results"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#advanced-subqueries",children:"Advanced Subqueries"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#retrieving-single-models-and-aggregates",children:"Retrieving Single Models / Aggregates"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#retrieving-or-creating-models",children:"Retrieving Or Creating Models"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#retrieving-aggregates",children:"Retrieving Aggregates"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#inserting-and-updating-models",children:"Inserting & Updating Models"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#inserts",children:"Inserts"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#updates",children:"Updates"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#mass-assignment",children:"Mass Assignment"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#upserts",children:"Upserts"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#deleting-models",children:"Deleting Models"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#soft-deleting",children:"Soft Deleting"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#querying-soft-deleted-models",children:"Querying Soft Deleted Models"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#truncate-table",children:"Truncate Table"})}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#replicating-models",children:"Replicating Models"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#comparing-models",children:"Comparing Models"})}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsx)(n.p,{children:'TinyORM is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using TinyORM, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, TinyORM models allow you to insert, update, and delete records from the table as well.'}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["Before getting started, be sure to configure a database connection in your application. For more information on configuring your database, check out the ",(0,i.jsx)(n.a,{href:"/database/getting-started#configuration",children:"database configuration documentation"}),"."]})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["If you want to see a model in which are used all possible TinyORM features you can look at the ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/tests/models/models/torrent.hpp",children:(0,i.jsx)(n.code,{children:"torrent.hpp"})})," in the TinyORM's tests, this ",(0,i.jsx)(n.code,{children:"Models::Torrent"})," class serves also as a showcase, so all possible features are defined in it."]})}),"\n",(0,i.jsx)(n.h2,{id:"generating-model-classes",children:"Generating Model Classes"}),"\n",(0,i.jsxs)(n.p,{children:["To get started, let's create the simplest TinyORM model. Models typically live in the ",(0,i.jsx)(n.code,{children:"database\\models"})," directory and extend the ",(0,i.jsx)(n.code,{children:"Orm::Tiny::Model"})," class. You may use the ",(0,i.jsx)(n.code,{children:"make:model"})," command to generate a new model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"tom make:model User\n"})}),"\n",(0,i.jsxs)(n.p,{children:["If you would like to generate a database ",(0,i.jsx)(n.a,{href:"/database/migrations",children:"migration"})," or ",(0,i.jsx)(n.a,{href:"/database/seeding",children:"seeder"})," when you generate the model, you may use the ",(0,i.jsx)(n.code,{children:"--migration"}),"/",(0,i.jsx)(n.code,{children:"-m"})," or ",(0,i.jsx)(n.code,{children:"--seeder"}),"/",(0,i.jsx)(n.code,{children:"-s"})," options:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"tom make:model User --migration --seeder\n"})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"--force"})," option forces overwriting of existing files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"tom make:model User --migration --seeder --force\n"})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"make:model"})," is king \ud83d\udc51 among scaffolding commands that you can use to generate complete TinyORM model classes, it supports all features that TinyORM models offer. All advanced features are described in the ",(0,i.jsx)(n.code,{children:"make:model"})," help command:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"tom make:model --help\n"})}),"\n",(0,i.jsx)(n.p,{children:"Few examples:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"# Setting some model attributes\ntom make:model User --table=users --fillable=name,email,banned_at `\n --guarded=password --dates=banned_at\n\n# Generate relationship methods\ntom make:model User --one-to-one=Passport `\n --one-to-many=Post --foreign-key=post_id `\n --one-to-many=Car\n\n# Generate a basic many-to-many relationship\ntom make:model User --belongs-to-many=Tag --with-timestamps\n\n# Generate a many-to-many relationship\ntom make:model User --belongs-to-many=Tag --foreign-key=tag_id `\n --pivot-table=user_tag --as=tagged `\n --with-pivot=active,soft --with-timestamps `\n --pivot=Tagged\n\n# Generate a pivot model\ntom make:model Tagged --pivot-model\ntom make:model Tagged --pivot-model --incrementing\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Writing a ",(0,i.jsx)(n.code,{children:"make:model"})," commands is superb with the ",(0,i.jsx)(n.a,{href:"/database/migrations#tab-completion",children:"tab completion"}),"."]})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"--path"})," and ",(0,i.jsx)(n.code,{children:"--realpath"})," options work the same as for the ",(0,i.jsx)(n.a,{href:"/database/migrations#generating-migrations",children:(0,i.jsx)(n.code,{children:"make:migration"})})," command."]})}),"\n",(0,i.jsx)(n.h2,{id:"tinyorm-model-conventions",children:"TinyORM Model Conventions"}),"\n",(0,i.jsx)(n.p,{children:"Let's examine a basic model class and discuss some of TinyORM's key conventions:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#pragma once\n#ifndef FLIGHT_HPP\n#define FLIGHT_HPP\n\n#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n\n using Model::Model;\n};\n\n#endif // FLIGHT_HPP\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"TinyORM"})," source tree contains the ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/tests/models/models/torrent.hpp#L43",children:(0,i.jsx)(n.code,{children:"Torrent"})})," example model that also acts as the full-fledged example model. It has defined and also nicely commented all possible features that model classes can use or define."]})}),"\n",(0,i.jsx)(n.h3,{id:"table-names",children:"Table Names"}),"\n",(0,i.jsxs)(n.p,{children:["After glancing at the example above, you may have noticed that we did not tell TinyORM which database table corresponds to our ",(0,i.jsx)(n.code,{children:"Flight"}),' model. By convention, the "snake_case", plural name of the class will be used as the table name unless another name is explicitly specified. So, in this case, TinyORM will assume the ',(0,i.jsx)(n.code,{children:"Flight"})," model stores records in the ",(0,i.jsx)(n.code,{children:"flights"})," table, while an ",(0,i.jsx)(n.code,{children:"AirTrafficController"})," model would store records in an ",(0,i.jsx)(n.code,{children:"air_traffic_controllers"})," table."]}),"\n",(0,i.jsxs)(n.p,{children:["If your model's corresponding database table does not fit this convention, you may manually specify the model's table name by defining the private ",(0,i.jsx)(n.code,{children:"u_table"})," data member on the model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The table associated with the model. */\n QString u_table {"flights"};\n};\n'})}),"\n",(0,i.jsx)(n.h3,{id:"primary-keys",children:"Primary Keys"}),"\n",(0,i.jsxs)(n.p,{children:["TinyORM will also assume that each model's corresponding database table has a primary key column named ",(0,i.jsx)(n.code,{children:"id"}),". If necessary, you may define a private ",(0,i.jsx)(n.code,{children:"u_primaryKey"})," data member on your model to specify a different column that serves as your model's primary key:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The primary key associated with the table. */\n QString u_primaryKey {"id"};\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["In addition, TinyORM assumes that the primary key is an incrementing integer value. If you wish to use a non-incrementing or a non-numeric primary key you must define a private ",(0,i.jsx)(n.code,{children:"u_incrementing"})," data member on your model that is set to ",(0,i.jsx)(n.code,{children:"false"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! Indicates if the model's ID is auto-incrementing. */\n bool u_incrementing = false;\n};\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsxs)(n.p,{children:["Non-numeric primary keys are not currently implemented, ",(0,i.jsx)(n.code,{children:"u_incrementing"})," code logic is fully implemented, but it is only one part to make it fully work."]})}),"\n",(0,i.jsx)(n.h4,{id:"composite-primary-keys",children:'"Composite" Primary Keys'}),"\n",(0,i.jsx)(n.p,{children:'TinyORM requires each model to have at least one uniquely identifying "ID" that can serve as its primary key. "Composite" primary keys are not supported by TinyORM models. However, you are free to add additional multi-column unique indexes to your database tables, in addition to the table\'s uniquely identifying primary key.'}),"\n",(0,i.jsx)(n.h3,{id:"timestamps",children:"Timestamps"}),"\n",(0,i.jsxs)(n.p,{children:["By default, TinyORM expects ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," columns to exist on your model's corresponding database table. TinyORM will automatically set these column's values when models are created or updated. If you do not want these columns to be automatically managed by TinyORM, you should define a private ",(0,i.jsx)(n.code,{children:"u_timestamps"})," data member on your model with a value of ",(0,i.jsx)(n.code,{children:"false"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! Indicates if the model should be timestamped. */\n bool u_timestamps = false;\n};\n"})}),"\n",(0,i.jsx)(a.A,{id:"timestamps-u_dates"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"u_dates"})," static data member controls the casting of timestamp attributes. The ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," columns are automatically added to the ",(0,i.jsx)(n.code,{children:"u_dates"})," string list when the ",(0,i.jsx)(n.code,{children:"u_timestamps"})," is ",(0,i.jsx)(n.code,{children:"true"}),". Also, the ",(0,i.jsx)(n.a,{href:"#soft-deleting",children:(0,i.jsx)(n.code,{children:"Soft Deleting"})})," feature adds the ",(0,i.jsx)(n.code,{children:"deleted_at"})," column to the ",(0,i.jsx)(n.code,{children:"u_dates"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:["You may add additional columns to the ",(0,i.jsx)(n.code,{children:"u_dates"})," list. After that, these columns will be automatically formatted using the format in the ",(0,i.jsx)(n.code,{children:"u_dateFormat"})," data member during the ",(0,i.jsx)(n.code,{children:"setAttribute"})," method call:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'class Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The attributes that should be mutated to dates. */\n inline static const QStringList u_dates {"departure_at"};\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If you need to customize the format of your model's timestamps, set the private ",(0,i.jsx)(n.code,{children:"u_dateFormat"})," data member on your model. This data member determines how date attributes are stored in the database, supported formats are described in the ",(0,i.jsx)(n.code,{children:"QDateTime"})," documentation:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The storage format of the model\'s date columns. */\n QString u_dateFormat {"yyyy-MM-dd HH:mm:ss"};\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If you need to customize the format of your model's time columns, set the private ",(0,i.jsx)(n.code,{children:"u_timeFormat"})," data member on your model. This data member determines how time attributes are stored in the database, supported formats are described in the ",(0,i.jsx)(n.code,{children:"QTime"})," documentation. The default value for ",(0,i.jsx)(n.code,{children:"u_timeFormat"})," is ",(0,i.jsx)(n.code,{children:"HH:mm:ss"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'/*! The storage format of the model\'s time columns. */\nQString u_timeFormat {"HH:mm:ss.zzz"};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The default value for datetime or timestamp columns is ",(0,i.jsx)(n.code,{children:"yyyy-MM-dd HH:mm:ss"})," and for time columns is ",(0,i.jsx)(n.code,{children:"HH:mm:ss"}),"."]}),"\n",(0,i.jsx)(n.h5,{id:"unix-timestamps",children:"Unix timestamps"}),"\n",(0,i.jsxs)(n.p,{children:["You can set the ",(0,i.jsx)(n.code,{children:"u_dateFormat"})," to ",(0,i.jsx)(n.code,{children:"U"})," if you want to store dates in the database as unix timestamps:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"QString u_dateFormat {QLatin1Char('U')};\n"})}),"\n",(0,i.jsxs)(n.p,{children:["In this case ",(0,i.jsx)(n.strong,{children:"all"})," date attributes set in the ",(0,i.jsx)(n.code,{children:"u_dates"})," will be handled as unix timestamps, so also the ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," timestamp attributes."]}),"\n",(0,i.jsxs)(n.p,{children:["To create unix timestamp columns using the ",(0,i.jsx)(n.a,{href:"/database/migrations",children:"tom migrations"})," you should use ",(0,i.jsx)(n.code,{children:"integer"})," types:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Schema::table("flights", [](Blueprint &table)\n{\n table.bigInteger("created_at").nullable();\n table.bigInteger("updated_at").nullable();\n});\n'})}),"\n",(0,i.jsx)(n.h5,{id:"custom-timestamp-column-names",children:"Custom timestamp column names"}),"\n",(0,i.jsxs)(n.p,{children:["If you need to customize the names of the columns used to store the timestamps, you may define ",(0,i.jsx)(n.code,{children:"CREATED_AT"})," and ",(0,i.jsx)(n.code,{children:"UPDATED_AT"})," private static getter methods on your model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The name of the "created at" column. */\n static QString CREATED_AT() { return QStringLiteral("creation_date"); }\n /*! The name of the "updated at" column. */\n static QString UPDATED_AT() { return QStringLiteral("updated_date"); }\n};\n'})}),"\n",(0,i.jsx)(n.h4,{id:"touching-timestamps",children:"Touching timestamps"}),"\n",(0,i.jsxs)(n.p,{children:["You can explicitly touch timestamps using the ",(0,i.jsx)(n.code,{children:"touch"})," method defined on the Model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::find(1);\n\nflight->touch();\nflight->touch("added_on"); // Custom column name\n'})}),"\n",(0,i.jsxs)(n.p,{children:["You can also touch multiple rows at once using the ",(0,i.jsx)(n.code,{children:"touch"})," method defined on the TinyBuilder:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto [affected, query] = Flight::whereEq("status", "new")->touch();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"touch"})," method may also be called when building a ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'flight->history()->touch();\nflight->history()->whereEq("status", "new").touch();\n'})}),"\n",(0,i.jsx)(n.h3,{id:"database-connections",children:"Database Connections"}),"\n",(0,i.jsxs)(n.p,{children:["By default, all TinyORM models will use the default database connection that is configured for your application. If you would like to specify a different connection that should be used when interacting with a particular model, you should define a ",(0,i.jsx)(n.code,{children:"u_connection"})," private data member on the model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The database connection that should be used by the model. */\n QString u_connection {"sqlite"};\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["In special cases, when you want to query the database through a different connection, you can use ",(0,i.jsx)(n.code,{children:"Model::on"})," method, which takes the connection name as the first argument:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto user = User::on("sqlite")->find(1);\n'})}),"\n",(0,i.jsx)(n.h2,{id:"default-attribute-values",children:"Default Attribute Values"}),"\n",(0,i.jsxs)(n.p,{children:["By default, a newly instantiated model instance will not contain any attribute values. If you would like to define the default values for some of your model's attributes, you may define an ",(0,i.jsx)(n.code,{children:"u_attributes"})," data member on your model, it has to be ",(0,i.jsx)(n.strong,{children:"static"})," and can be ",(0,i.jsx)(n.strong,{children:"const"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The model\'s default values for attributes. */\n inline static const QVector u_attributes {\n {"delayed", false},\n {"progress", 0},\n {"added_on", QDateTime::currentDateTimeUtc()},\n };\n};\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsxs)(n.p,{children:["Use the ",(0,i.jsx)(n.code,{children:"Model::instance"})," or ",(0,i.jsx)(n.code,{children:"Model::instanceHeap"})," related methods to instantiate a model that contains a ",(0,i.jsx)(n.code,{children:"QDateTime"})," in Default Attribute Values, or if attributes you want to pass to the model's constructor contain a ",(0,i.jsx)(n.code,{children:"QDateTime"})," instance ",(0,i.jsx)("small",{children:"(problem is described below)"}),"."]})}),"\n",(0,i.jsx)(n.h5,{id:"qdatetime-and-connection-name-problem",children:"QDateTime and connection name problem"}),"\n",(0,i.jsxs)(n.p,{children:["If your Default Attribute Values or attributes that you can pass to the ",(0,i.jsx)(n.code,{children:"Model"})," constructor contain the ",(0,i.jsx)(n.code,{children:"QDateTime"})," instance, then ",(0,i.jsx)(n.code,{children:"TinyORM"})," throws an exception. You have to use the ",(0,i.jsx)(n.code,{children:"Model::instance"})," related methods to create such a Model."]}),"\n",(0,i.jsxs)(n.p,{children:["Virtually everything important is covered in the thrown exception, but let me summarize it. The problem is that the ",(0,i.jsx)(n.code,{children:"QDateTime"})," instance is converted to a string based on the ",(0,i.jsx)(n.code,{children:"Model::u_dateFormat"}),", or if not defined, the date format from ",(0,i.jsx)(n.code,{children:"Orm::Query::Grammars::Grammar"})," will be used. This ",(0,i.jsx)(n.code,{children:"QueryGrammar"})," is obtained from ",(0,i.jsx)(n.code,{children:"Orm::DatabaseConnection"})," and because of that TinyORM needs to know the ",(0,i.jsx)(n.strong,{children:"connection name"})," and that's the crux of this problem. You can define your connection name using the ",(0,i.jsx)(n.code,{children:"Model::u_connection"})," in your derived model class, but this derived model ",(0,i.jsx)(n.strong,{children:"is not yet initialized"}),", so the ",(0,i.jsx)(n.code,{children:"Model::u_connection"})," is also not initialized."]}),"\n",(0,i.jsxs)(n.p,{children:["So if the ",(0,i.jsx)(n.code,{children:"Model::u_connection"})," is not yet initialized, ",(0,i.jsx)(n.code,{children:"TinyORM"})," can't obtain the ",(0,i.jsx)(n.code,{children:"Orm::DatabaseConnection"})," -> ",(0,i.jsx)(n.code,{children:"QueryGrammar"})," -> ",(0,i.jsx)(n.code,{children:"dateFormat"}),"."]}),"\n",(0,i.jsx)(n.h2,{id:"retrieving-models",children:"Retrieving Models"}),"\n",(0,i.jsxs)(n.p,{children:["Once you have created a model and its associated database table, you are ready to start retrieving data from your database. You can think of each TinyORM model as a powerful ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"})," allowing you to fluently query the database table associated with the model. The model's ",(0,i.jsx)(n.code,{children:"all"})," method will retrieve all of the records from the model's associated database table:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include "models/flight.hpp"\n\nfor (const auto &flight : Flight::all())\n qDebug() << flight["name"].toString();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"building-queries",children:"Building Queries"}),"\n",(0,i.jsxs)(n.p,{children:["The TinyORM ",(0,i.jsx)(n.code,{children:"all"})," method will return all of the results in the model's table. However, since each TinyORM model serves as a ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"}),", you may add additional constraints to queries and then invoke the ",(0,i.jsx)(n.code,{children:"get"})," method to retrieve the results:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flights = Flight::whereEq("active", 1)\n ->orderBy("name")\n .take(10)\n .get();\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Since TinyORM models are query builders, you should review all of the methods provided by TinyORM's ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"}),". You may use any of these methods when writing your TinyORM queries."]})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["All the static methods defined on the ",(0,i.jsx)(n.code,{children:"Orm::Tiny::Model"})," class, which start building queries like ",(0,i.jsx)(n.code,{children:"where"}),", ",(0,i.jsx)(n.code,{children:"latest"}),", ",(0,i.jsx)(n.code,{children:"oldest"}),", ",(0,i.jsx)(n.code,{children:"with"}),", ... return ",(0,i.jsx)(n.code,{children:"std::unique_ptr>"}),", ",(0,i.jsx)(n.code,{children:"TinyBuilder = Orm::Tiny::Builder"})," and ",(0,i.jsx)(n.code,{children:"Model"})," template argument is queried model class."]})}),"\n",(0,i.jsx)(n.h4,{id:"refreshing-models",children:"Refreshing Models"}),"\n",(0,i.jsxs)(n.p,{children:['If you already have an instance of the TinyORM model that was retrieved from the database, you can "refresh" the model using the ',(0,i.jsx)(n.code,{children:"fresh"})," and ",(0,i.jsx)(n.code,{children:"refresh"})," methods. The ",(0,i.jsx)(n.code,{children:"fresh"})," method will re-retrieve the model from the database. The existing model instance will not be affected:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::whereEq("number", "FR 900")->first();\n\nauto freshFlight = flight->fresh();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"refresh"})," method will re-hydrate the existing model using fresh data from the database. In addition, all of its loaded relationships will be refreshed as well:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::whereEq("number", "FR 900")->first();\n\nflight->setAttribute("number", "FR 456");\n\nflight->refresh();\n\nflight->getAttribute("number"); // "FR 900"\n'})}),"\n",(0,i.jsx)(n.h3,{id:"containers",children:"Containers"}),"\n",(0,i.jsxs)(n.p,{children:["As we have seen, TinyORM methods like ",(0,i.jsx)(n.code,{children:"all"})," and ",(0,i.jsx)(n.code,{children:"get"})," retrieve multiple records from the database. Since these methods return a ",(0,i.jsx)(n.code,{children:"QVector"}),", you can iterate it like any other container with the ",(0,i.jsx)(n.a,{href:"https://en.cppreference.com/w/cpp/language/range-for",children:"Range-based for loop"}),", ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/containers.html#stl-style-iterators",children:"STL-Style Iterators"}),", ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/containers.html#java-style-iterators",children:"Java-Style Iterators"})," or ",(0,i.jsx)(n.a,{href:"https://www.walletfox.com/course/quickref_range_v3.php",children:"Ranges"}),"."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include "models/flight.hpp"\n\nfor (const auto &flight : Flight::all())\n qDebug() << flight["name"].toString();\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["An ",(0,i.jsx)(n.code,{children:"all"})," method is defined on the ",(0,i.jsx)(n.code,{children:"Orm::Tiny::Model"})," class and ",(0,i.jsx)(n.code,{children:"get"})," method is defined on the ",(0,i.jsx)(n.code,{children:"Orm::Tiny::Builder"}),", may be also referred as ",(0,i.jsx)(n.code,{children:"TinyBuilder"}),", and on the ",(0,i.jsx)(n.code,{children:"Orm::Query::Builder"})," alias ",(0,i.jsx)(n.code,{children:"QueryBuilder"}),"."]})}),"\n",(0,i.jsx)(n.h3,{id:"chunking-results",children:"Chunking Results"}),"\n",(0,i.jsxs)(n.p,{children:["Your application may run out of memory if you attempt to load tens of thousands of TinyORM records via the ",(0,i.jsx)(n.code,{children:"all"})," or ",(0,i.jsx)(n.code,{children:"get"})," methods. Instead of using these methods, the ",(0,i.jsx)(n.code,{children:"chunk"})," method may be used to process large numbers of models more efficiently."]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"chunk"})," method will retrieve a subset of TinyORM models, passing them to a lambda expression for processing. Since only the current chunk of TinyORM models is retrieved at a time, the ",(0,i.jsx)(n.code,{children:"chunk"})," method will provide significantly reduced memory usage when working with a large number of models:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"Flight::chunk(200, [](QVector &&flights, const int /*unused*/)\n{\n for (auto &&flight : flights) {\n //\n }\n\n return true;\n});\n"})}),"\n",(0,i.jsxs)(n.p,{children:["The first argument passed to the ",(0,i.jsx)(n.code,{children:"chunk"}),' method is the number of records you wish to receive per "chunk". The lambda expression passed as the second argument will be invoked for each chunk that is retrieved from the database. A database query will be executed to retrieve each chunk of records passed to the lambda expression.']}),"\n",(0,i.jsxs)(n.p,{children:["If you are filtering the results of the ",(0,i.jsx)(n.code,{children:"chunk"})," method based on a column that you will also be updating while iterating over the results, you should use the ",(0,i.jsx)(n.code,{children:"chunkById"})," method. Using the ",(0,i.jsx)(n.code,{children:"chunk"})," method in these scenarios could lead to unexpected and inconsistent results. Internally, the ",(0,i.jsx)(n.code,{children:"chunkById"})," method will always retrieve models with an ",(0,i.jsx)(n.code,{children:"id"})," column greater than the last model in the previous chunk:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Flight::whereEq("departed", true)\n ->chunkById(200, [](QVector &&flights, const int /*unused*/)\n {\n for (auto &&flight : flights)\n flight.update({{"departed", false}});\n\n return true;\n });\n'})}),"\n",(0,i.jsx)(n.h3,{id:"advanced-subqueries",children:"Advanced Subqueries"}),"\n",(0,i.jsx)(n.h4,{id:"subquery-selects",children:"Subquery Selects"}),"\n",(0,i.jsxs)(n.p,{children:["TinyORM also offers advanced subquery support, which allows you to pull information from related tables in a single query. For example, let's imagine that we have a table of flight ",(0,i.jsx)(n.code,{children:"destinations"})," and a table of ",(0,i.jsx)(n.code,{children:"flights"})," to destinations. The ",(0,i.jsx)(n.code,{children:"flights"})," table contains an ",(0,i.jsx)(n.code,{children:"arrived_at"})," column which indicates when the flight arrived at the destination."]}),"\n",(0,i.jsxs)(n.p,{children:["Using the subquery functionality available to the query builder's ",(0,i.jsx)(n.code,{children:"select"})," and ",(0,i.jsx)(n.code,{children:"addSelect"})," methods, we can select all of the ",(0,i.jsx)(n.code,{children:"destinations"})," and the name of the flight that most recently arrived at that destination using a single query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/destination.hpp"\n#include "models/flight.hpp"\n\nreturn Destination::addSelect(\n Flight::select("name")\n ->whereColumnEq("destination_id", "destinations.id")\n .orderByDesc("arrived_at")\n .limit(1)\n .toBase(),\n "last_flight")\n ->get();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"subquery-ordering",children:"Subquery Ordering"}),"\n",(0,i.jsxs)(n.p,{children:["In addition, the query builder's ",(0,i.jsx)(n.code,{children:"orderBy"})," function supports subqueries. Continuing to use our flight example, we may use this functionality to sort all destinations based on when the last flight arrived at that destination. Again, this may be done while executing a single database query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'return Destination::orderByDesc(\n Flight::select("arrived_at")\n ->whereColumnEq("destination_id", "destinations.id")\n .orderByDesc("arrived_at")\n .limit(1)\n .toBase())\n ->get();\n'})}),"\n",(0,i.jsx)(n.h2,{id:"retrieving-single-models-and-aggregates",children:"Retrieving Single Models / Aggregates"}),"\n",(0,i.jsxs)(n.p,{children:["In addition to retrieving all of the records matching a given query, you may also retrieve single records using the ",(0,i.jsx)(n.code,{children:"find"}),", ",(0,i.jsx)(n.code,{children:"first"}),", ",(0,i.jsx)(n.code,{children:"firstWhere"}),", or ",(0,i.jsx)(n.code,{children:"firstWhereEq"})," methods. Instead of returning a vector of models, these methods return a single model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\n// Retrieve a model by its primary key...\nauto flight = Flight::find(1);\n\n// Retrieve the first model matching the query constraints...\nauto flight = Flight::whereEq("active", 1)->first();\n\n// Alternative to retrieving the first model matching the query constraints...\nauto flight = Flight::firstWhere("active", "=", 1);\n\n// Alternative firstWhere method syntax\nauto flight = Flight::firstWhereEq("active", 1);\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes you may wish to perform some other action if no results are found. The ",(0,i.jsx)(n.code,{children:"findOr"})," methods will return a single model instance or, if no results are found, execute the given lambda expression. The value returned by the lambda will be considered the result of the method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"auto flight = Flight::findOr(1, [] {\n // ...\n});\n\nauto flight = Flight::findOr(1, [] {\n // ...\n return 10;\n});\n\nauto flight = Flight::findOr>(1, [] {\n // ...\n return Flight::find(10);\n});\n"})}),"\n",(0,i.jsxs)(n.p,{children:["To obtain only a subset of the model's attributes you may use the ",(0,i.jsx)(n.code,{children:"Model::only"})," method, it returns the ",(0,i.jsx)(n.code,{children:"QVector"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nusing Orm::Constants::ID;\nusing Orm::Constants::NAME;\n\nauto flight = Flight::find(1);\n\nauto attributes = flight->only({ID, NAME});\n'})}),"\n",(0,i.jsx)(n.h4,{id:"not-found-exceptions",children:"Not Found Exceptions"}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes you may wish to throw an exception if a model is not found. The ",(0,i.jsx)(n.code,{children:"findOrFail"})," and ",(0,i.jsx)(n.code,{children:"firstOrFail"})," methods will retrieve the first result of the query; however, if no result is found, an ",(0,i.jsx)(n.code,{children:"Orm::Tiny::ModelNotFoundError"})," will be thrown:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::findOrFail(1);\n\nauto flight = Flight::where("legs", ">", 3)->firstOrFail();\n'})}),"\n",(0,i.jsx)(n.h3,{id:"retrieving-or-creating-models",children:"Retrieving Or Creating Models"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"firstOrCreate"})," method will attempt to locate a database record using the given column / value pairs. If the model can not be found in the database, a record will be inserted with the attributes resulting from merging the first ",(0,i.jsx)(n.code,{children:"QVector"})," argument with the optional second ",(0,i.jsx)(n.code,{children:"QVector"})," argument:"]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"firstOrNew"})," method, like ",(0,i.jsx)(n.code,{children:"firstOrCreate"}),", will attempt to locate a record in the database matching the given attributes. However, if a model is not found, a new model instance will be returned. Note that the model returned by ",(0,i.jsx)(n.code,{children:"firstOrNew"})," has not yet been persisted to the database. You will need to manually call the ",(0,i.jsx)(n.code,{children:"save"})," method to persist it:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\n// Retrieve flight by name or create it if it doesn\'t exist...\nauto flight = Flight::firstOrCreate({\n {"name", "London to Paris"}\n});\n\n// Retrieve flight by name or create it with the name, delayed, and arrival_time attributes...\nauto flight = Flight::firstOrCreate(\n {{"name", "London to Paris"}},\n {{"delayed", 1}, {"arrival_time", "11:30"}}\n);\n\n// Retrieve flight by name or instantiate a new Flight instance...\nauto flight = Flight::firstOrNew({\n {"name", "London to Paris"}\n});\n\n// Retrieve flight by name or instantiate with the name, delayed, and arrival_time attributes...\nauto flight = Flight::firstOrNew(\n {{"name", "Tokyo to Sydney"}},\n {{"delayed", 1}, {"arrival_time", "11:30"}}\n);\n'})}),"\n",(0,i.jsx)(n.h3,{id:"retrieving-aggregates",children:"Retrieving Aggregates"}),"\n",(0,i.jsxs)(n.p,{children:["When interacting with TinyORM models, you may also use the ",(0,i.jsx)(n.code,{children:"count"}),", ",(0,i.jsx)(n.code,{children:"sum"}),", ",(0,i.jsx)(n.code,{children:"max"}),", and other ",(0,i.jsx)(n.a,{href:"/database/query-builder#aggregates",children:"aggregate methods"})," provided by the ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"}),". As you might expect, these methods return a scalar value instead of a TinyORM model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto count = Flight::whereEq("active", 1)->count();\n\nauto max = Flight::whereEq("active", 1)->max("price");\n'})}),"\n",(0,i.jsx)(n.h2,{id:"inserting-and-updating-models",children:"Inserting & Updating Models"}),"\n",(0,i.jsx)(n.h3,{id:"inserts",children:"Inserts"}),"\n",(0,i.jsxs)(n.p,{children:["Of course, when using TinyORM, we don't only need to retrieve models from the database. We also need to insert new records. Thankfully, TinyORM makes it simple. To insert a new record into the database, you should instantiate a new model instance and set attributes on the model. Then, call the ",(0,i.jsx)(n.code,{children:"save"})," method on the model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\n// Store a new flight in the database\nFlight flight;\nflight.setAttribute("name", "Slovakia to Czech");\nflight.save();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["In this example, we assign the ",(0,i.jsx)(n.code,{children:"name"})," attribute of the ",(0,i.jsx)(n.code,{children:"Flight"})," model instance. When we call the ",(0,i.jsx)(n.code,{children:"save"})," method, a record will be inserted into the database. The model's ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," timestamps will automatically be set when the ",(0,i.jsx)(n.code,{children:"save"})," method is called, so there is no need to set them manually."]}),"\n",(0,i.jsxs)(n.p,{children:["Alternatively, you may use the ",(0,i.jsx)(n.code,{children:"create"}),' method to "save" a new model using a single C++ statement. The inserted model instance will be returned to you by the ',(0,i.jsx)(n.code,{children:"create"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nauto flight = Flight::create({\n {"name", "London to Paris"},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["However, before using the ",(0,i.jsx)(n.code,{children:"create"})," method, you will need to specify either a ",(0,i.jsx)(n.code,{children:"u_fillable"})," or ",(0,i.jsx)(n.code,{children:"u_guarded"})," static data member on your model class. These static data members are required because all TinyORM models are protected against mass assignment vulnerabilities by default. To learn more about mass assignment, please consult the ",(0,i.jsx)(n.a,{href:"#mass-assignment",children:"mass assignment documentation"}),"."]}),"\n",(0,i.jsx)(n.h3,{id:"updates",children:"Updates"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"save"})," method may also be used to update models that already exist in the database. To update a model, you should retrieve it and set any attributes you wish to update. Then, you should call the model's ",(0,i.jsx)(n.code,{children:"save"})," method. Again, the ",(0,i.jsx)(n.code,{children:"updated_at"})," timestamp will automatically be updated, so there is no need to manually set its value:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nauto flight = Flight::find(1);\n\nflight->setAttribute("name", "Paris to London");\n\nflight->save();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"mass-updates",children:"Mass Updates"}),"\n",(0,i.jsxs)(n.p,{children:["Updates can also be performed against models that match a given query. In this example, all flights that are ",(0,i.jsx)(n.code,{children:"active"})," and have a ",(0,i.jsx)(n.code,{children:"destination"})," of ",(0,i.jsx)(n.code,{children:"San Diego"})," will be marked as delayed:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Flight::whereEq("active", 1)\n ->whereEq("destination", "San Diego")\n .update({{"delayed", 1}});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"update"})," method expects the ",(0,i.jsx)(n.code,{children:"QVector"})," of column and value pairs representing the columns that should be updated."]}),"\n",(0,i.jsx)(n.h4,{id:"examining-attribute-changes",children:"Examining Attribute Changes"}),"\n",(0,i.jsxs)(n.p,{children:["TinyORM provides the ",(0,i.jsx)(n.code,{children:"isDirty"}),", ",(0,i.jsx)(n.code,{children:"isClean"}),", and ",(0,i.jsx)(n.code,{children:"wasChanged"})," methods to examine the internal state of your model and determine how its attributes have changed from when the model was originally retrieved."]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"isDirty"})," method determines if any of the model's attributes have been changed since the model was retrieved. You may pass a specific attribute name to the ",(0,i.jsx)(n.code,{children:"isDirty"})," method to determine if a particular attribute is dirty. The ",(0,i.jsx)(n.code,{children:"isClean"})," will determine if an attribute has remained unchanged since the model was retrieved. This method also accepts an optional attribute argument:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/user.hpp"\n\nauto user = User::create({\n {"first_name", "Silver"},\n {"last_name", "Zachara"},\n {"title", "Developer"},\n});\n\nuser.setAttribute("title", "Painter");\n\nuser.isDirty(); // true\nuser.isDirty("title"); // true\nuser.isDirty("first_name"); // false\n\nuser.isClean(); // false\nuser.isClean("title"); // false\nuser.isClean("first_name"); // true\n\nuser.save();\n\nuser.isDirty(); // false\nuser.isClean(); // true\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"wasChanged"})," method determines if any attributes were changed after the model was last saved into the database. If needed, you may pass an attribute name to see if a particular attribute was changed:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto user = User::create({\n {"first_name", "Silver"},\n {"last_name", "Zachara"},\n {"title", "Developer"},\n});\n\nuser.setAttribute("title", "Painter");\n\nuser.wasChanged(); // false\n\nuser.save();\n\nuser.wasChanged(); // true\nuser.wasChanged("title"); // true\nuser.wasChanged("first_name"); // false\n'})}),"\n",(0,i.jsx)(n.h3,{id:"mass-assignment",children:"Mass Assignment"}),"\n",(0,i.jsxs)(n.p,{children:["You may use the ",(0,i.jsx)(n.code,{children:"create"}),' method to "save" a new model using a single C++ statement. The inserted model instance will be returned to you by the method:']}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nauto flight = Flight::create({\n {"name", "London to Paris"},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["However, before using the ",(0,i.jsx)(n.code,{children:"create"})," method, you will need to specify either a ",(0,i.jsx)(n.code,{children:"u_fillable"})," or ",(0,i.jsx)(n.code,{children:"u_guarded"})," static data member on your model class. These data members are required because all TinyORM models are protected against mass assignment vulnerabilities by default."]}),"\n",(0,i.jsxs)(n.p,{children:["A mass assignment vulnerability occurs when a user passes an unexpected HTTP request field and that field changes a column in your database that you did not expect. For example, a malicious user might send an ",(0,i.jsx)(n.code,{children:"is_admin"})," parameter through an HTTP request, which is then passed to your model's ",(0,i.jsx)(n.code,{children:"create"})," method, allowing the user to escalate themselves to an administrator."]}),"\n",(0,i.jsxs)(n.p,{children:["So, to get started, you should define which model attributes you want to make mass assignable. You may do this using the ",(0,i.jsx)(n.code,{children:"u_fillable"})," static data member on the model. For example, let's make the ",(0,i.jsx)(n.code,{children:"name"})," attribute of our ",(0,i.jsx)(n.code,{children:"Flight"})," model mass assignable:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n\n using Model::Model;\n\n /*! The attributes that are mass assignable. */\n inline static QStringList u_fillable {\n "name",\n };\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Once you have specified which attributes are mass assignable, you may use the ",(0,i.jsx)(n.code,{children:"create"})," method to insert a new record in the database. The ",(0,i.jsx)(n.code,{children:"create"})," method returns the newly created model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::create({{"name", "London to Paris"}});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If you already have a model instance, you may use the ",(0,i.jsx)(n.code,{children:"fill"})," method to populate it with the vector of attributes:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'flight.fill({{"name", "Amsterdam to Frankfurt"}});\n'})}),"\n",(0,i.jsx)(n.h4,{id:"allowing-mass-assignment",children:"Allowing Mass Assignment"}),"\n",(0,i.jsxs)(n.p,{children:["If you would like to make all of your attributes mass assignable, you may define your model's ",(0,i.jsx)(n.code,{children:"u_guarded"})," static data member as an empty vector. If you choose to unguard your model, you should take special care to always hand-craft the vectors passed to TinyORM's ",(0,i.jsx)(n.code,{children:"fill"}),", ",(0,i.jsx)(n.code,{children:"create"}),", and ",(0,i.jsx)(n.code,{children:"update"})," methods:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n\n using Model::Model;\n\n /*! The attributes that aren't mass assignable. */\n inline static QStringList u_guarded {};\n};\n"})}),"\n",(0,i.jsx)(n.h3,{id:"upserts",children:"Upserts"}),"\n",(0,i.jsx)(n.p,{children:"Occasionally, you may need to update an existing model or create a new model if no matching model exists."}),"\n",(0,i.jsxs)(n.p,{children:["In the example below, if a flight exists with a ",(0,i.jsx)(n.code,{children:"departure"})," location of ",(0,i.jsx)(n.code,{children:"Oakland"})," and a ",(0,i.jsx)(n.code,{children:"destination"})," location of ",(0,i.jsx)(n.code,{children:"San Diego"}),", its ",(0,i.jsx)(n.code,{children:"price"})," and ",(0,i.jsx)(n.code,{children:"discounted"})," columns will be updated. If no such flight exists, a new flight will be created which has the attributes resulting from merging the first argument vector with the second argument vector:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::updateOrCreate(\n {{"departure", "Oakland"}, {"destination", "San Diego"}},\n {{"price", 99}, {"discounted", 1}}\n);\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"firstOrCreate"})," and ",(0,i.jsx)(n.code,{children:"updateOrCreate"})," methods persist the model, so there's no need to manually call the ",(0,i.jsx)(n.code,{children:"save"})," method."]})}),"\n",(0,i.jsxs)(n.p,{children:['If you would like to perform multiple "upserts" in a single query, then you should use the ',(0,i.jsx)(n.code,{children:"upsert"})," method instead. The method's first argument consists of the values to insert or update, while the second argument lists the column(s) that uniquely identify records within the associated table. The method's third and final argument is the vector of the columns that should be updated if a matching record already exists in the database. The ",(0,i.jsx)(n.code,{children:"upsert"})," method will automatically set the ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," timestamps if timestamps are enabled on the model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Flight::upsert(\n {{{"departure", "Oakland"}, {"destination", "San Diego"}, {"price", 99}},\n {{"departure", "Chicago"}, {"destination", "New York"}, {"price", 150}}},\n {"departure", "destination"},\n {"price"}\n);\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsxs)(n.p,{children:["All databases except SQL Server require the columns in the second argument of the ",(0,i.jsx)(n.code,{children:"upsert"}),' method to have a "primary" or "unique" index. In addition, the MySQL database driver ignores the second argument of the ',(0,i.jsx)(n.code,{children:"upsert"}),' method and always uses the "primary" and "unique" indexes of the table to detect existing records.']})}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["Row and column aliases will be used with the MySQL server >=8.0.19 instead of the VALUES() function as is described in the MySQL ",(0,i.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.3/en/insert-on-duplicate.html",children:"documentation"}),". The MySQL server version is auto-detected and can be overridden in the ",(0,i.jsx)(n.a,{href:"/database/getting-started#configuration",children:"configuration"}),"."]})}),"\n",(0,i.jsx)(n.h2,{id:"deleting-models",children:"Deleting Models"}),"\n",(0,i.jsxs)(n.p,{children:["To delete a model, you may call the ",(0,i.jsx)(n.code,{children:"remove"}),", or an alias ",(0,i.jsx)(n.code,{children:"deleteRow"})," method on the model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nauto flight = Flight::find(1);\n\nflight->remove();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"deleting-an-existing-model-by-its-primary-key",children:"Deleting An Existing Model By Its Primary Key"}),"\n",(0,i.jsxs)(n.p,{children:["In the example above, we are retrieving the model from the database before calling the ",(0,i.jsx)(n.code,{children:"remove"})," method. However, if you know the primary key of the model, you may delete the model without explicitly retrieving it by calling the ",(0,i.jsx)(n.code,{children:"destroy"})," method. In addition to accepting the single primary key, the ",(0,i.jsx)(n.code,{children:"destroy"})," method can accept multiple primary keys:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"Flight::destroy(1);\n\nFlight::destroy({1, 2, 3});\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"destroy"})," method loads models from the database and calls the ",(0,i.jsx)(n.code,{children:"remove"})," method on each model individually, the reason for this is future compatibility with events."]})}),"\n",(0,i.jsx)(n.h4,{id:"deleting-models-using-queries",children:"Deleting Models Using Queries"}),"\n",(0,i.jsx)(n.p,{children:"Of course, you may build the query to delete all models matching your query's criteria. In this example, we will delete all flights that are marked as inactive:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto deletedRows = Flight::whereEq("active", 0)->remove();\n'})}),"\n",(0,i.jsx)(n.h3,{id:"soft-deleting",children:"Soft Deleting"}),"\n",(0,i.jsxs)(n.p,{children:['In addition to actually removing records from your database, TinyORM can also "soft delete" models. When models are soft deleted, they are not actually removed from your database. Instead, a ',(0,i.jsx)(n.code,{children:"deleted_at"}),' attribute is set on the model indicating the date and time at which the model was "deleted". To enable soft deletes for a model, add the ',(0,i.jsx)(n.code,{children:"Orm::Tiny::SoftDeletes"})," base class to the model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::Tiny::Model;\nusing Orm::Tiny::SoftDeletes;\n\nclass Flight final : public Model,\n public SoftDeletes\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The table associated with the model. */\n QString u_table {"flights"};\n};\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"SoftDeletes"})," base class will automatically cast the ",(0,i.jsx)(n.code,{children:"deleted_at"})," attribute to the ",(0,i.jsx)(n.code,{children:"QDateTime"})," instance for you (it adds the ",(0,i.jsx)(n.code,{children:"deleted_at"})," column to the model's ",(0,i.jsx)(n.a,{href:"#timestamps-u_dates",children:(0,i.jsx)(n.code,{children:"u_dates"})})," list)."]})}),"\n",(0,i.jsxs)(n.p,{children:["You should also add the ",(0,i.jsx)(n.code,{children:"deleted_at"})," column to your database table. The TinyORM ",(0,i.jsx)(n.a,{href:"/database/migrations",children:"schema builder"})," contains a helper method to create this column:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Schema::table("flights", [](Blueprint &table)\n{\n table.softDeletes();\n});\n\nSchema::table("flights", [](Blueprint &table)\n{\n table.dropSoftDeletes();\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Now, when you call the ",(0,i.jsx)(n.code,{children:"remove"})," or ",(0,i.jsx)(n.code,{children:"deleteModel"})," method on the model, the ",(0,i.jsx)(n.code,{children:"deleted_at"})," column will be set to the current date and time. However, the model's database record will be left in the table. When querying a model that uses soft deletes, the soft deleted models will automatically be excluded from all query results."]}),"\n",(0,i.jsxs)(n.p,{children:["To determine if a given model instance has been soft deleted, you may use the ",(0,i.jsx)(n.code,{children:"trashed"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"if (flight->trashed()) {\n //\n}\n"})}),"\n",(0,i.jsx)(n.h4,{id:"restoring-soft-deleted-models",children:"Restoring Soft Deleted Models"}),"\n",(0,i.jsxs)(n.p,{children:['Sometimes you may wish to "un-delete" a soft deleted model. To restore a soft deleted model, you may call the ',(0,i.jsx)(n.code,{children:"restore"})," method on a model instance. The ",(0,i.jsx)(n.code,{children:"restore"})," method will set the model's ",(0,i.jsx)(n.code,{children:"deleted_at"})," column to ",(0,i.jsx)(n.code,{children:"null"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->restore();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["You may also use the ",(0,i.jsx)(n.code,{children:"restore"})," method in a query to restore multiple models:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Flight::withTrashed()\n ->whereEq("airline_id", 1)\n .restore();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"restore"})," method may also be used when building ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," queries:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->restore();\n"})}),"\n",(0,i.jsx)(n.h4,{id:"permanently-deleting-models",children:"Permanently Deleting Models"}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes you may need to truly remove a model from your database. You may use the ",(0,i.jsx)(n.code,{children:"forceDelete"})," method (or it's alias ",(0,i.jsx)(n.code,{children:"forceRemove"}),") to permanently remove a soft deleted model from the database table:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->forceDelete();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["You may also use the ",(0,i.jsx)(n.code,{children:"forceDelete"})," method when building TinyORM relationship queries:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->forceDelete();\n"})}),"\n",(0,i.jsx)(n.h3,{id:"querying-soft-deleted-models",children:"Querying Soft Deleted Models"}),"\n",(0,i.jsx)(n.h4,{id:"including-soft-deleted-models",children:"Including Soft Deleted Models"}),"\n",(0,i.jsxs)(n.p,{children:["As noted above, soft deleted models will automatically be excluded from query results. However, you may force soft deleted models to be included in a query's results by calling the ",(0,i.jsx)(n.code,{children:"withTrashed"})," method on the query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flights = Flight::withTrashed()\n ->whereEq("account_id", 1)\n .get();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"withTrashed"})," method may also be called when building a ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->withTrashed().get();\n"})}),"\n",(0,i.jsx)(n.h4,{id:"retrieving-only-soft-deleted-models",children:"Retrieving Only Soft Deleted Models"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"onlyTrashed"})," method will retrieve ",(0,i.jsx)(n.strong,{children:"only"})," soft deleted models:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flights = Flight::onlyTrashed()\n ->whereEq("airline_id", 1)\n .get();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"onlyTrashed"})," method may also be called when building a ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->onlyTrashed().get();\n"})}),"\n",(0,i.jsx)(n.h4,{id:"excluding-soft-deleted-models",children:"Excluding Soft Deleted Models"}),"\n",(0,i.jsxs)(n.p,{children:["As noted above, soft deleted models will automatically be excluded from query results. However, you may force soft deleted models to be ",(0,i.jsx)(n.strong,{children:"excluded"})," in a query's results by calling the ",(0,i.jsx)(n.code,{children:"withoutTrashed"})," method on the query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flights = Flight::withoutTrashed()\n ->whereEq("account_id", 1)\n .get();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"withoutTrashed"})," method may also be called when building a ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->withoutTrashed().get();\n"})}),"\n",(0,i.jsx)(n.h3,{id:"truncate-table",children:"Truncate Table"}),"\n",(0,i.jsxs)(n.p,{children:["You may call the ",(0,i.jsx)(n.code,{children:"truncate"})," method to delete all of the model's associated database records. The ",(0,i.jsx)(n.code,{children:"truncate"})," operation will also reset any auto-incrementing IDs on the model's associated table:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"Flight::truncate();\n"})}),"\n",(0,i.jsx)(n.h2,{id:"replicating-models",children:"Replicating Models"}),"\n",(0,i.jsxs)(n.p,{children:["You may create an unsaved copy of an existing model instance using the ",(0,i.jsx)(n.code,{children:"replicate"})," method. This method is particularly useful when you have model instances that share many of the same attributes:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto shipping = Address::create({\n {"type", "shipping"},\n {"line_1", "123 Example Street"},\n {"city", "Victorville"},\n {"state", "CA"},\n {"postcode", "90001"},\n});\n\nauto billing = shipping.replicate();\n\nbilling.fill({\n {"type", "billing"},\n});\n\nbilling.save();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["To exclude one or more attributes from being replicated to the new model, you may pass an unordered_set to the ",(0,i.jsx)(n.code,{children:"replicate"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::create({\n {"destination", "LAX"},\n {"origin", "LHR"},\n {"last_flown", "2020-03-04 11:00:00"},\n {"last_pilot_id", 747},\n});\n\nflight = flight.replicate({\n "last_flown",\n "last_pilot_id",\n});\n'})}),"\n",(0,i.jsx)(n.h2,{id:"comparing-models",children:"Comparing Models"}),"\n",(0,i.jsxs)(n.p,{children:['Sometimes you may need to determine if two models are the "same" or not. The ',(0,i.jsx)(n.code,{children:"is"})," and ",(0,i.jsx)(n.code,{children:"isNot"})," methods may be used to quickly verify two models have the same primary key, table, and database connection or not:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"if (post->is(anotherPost)) {\n //\n}\n\nif (post->isNot(anotherPost)) {\n //\n}\n"})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"is"})," and ",(0,i.jsx)(n.code,{children:"isNot"})," methods are also available when using the ",(0,i.jsx)(n.code,{children:"belongsTo"})," and ",(0,i.jsx)(n.code,{children:"hasOne"})," ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationships"}),". This method is particularly helpful when you would like to compare a related model without issuing a query to retrieve that model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"if (post->author()->is(user)) {\n //\n}\n"})}),"\n",(0,i.jsx)(n.h5,{id:"equality-comparison",children:"Equality comparison"}),"\n",(0,i.jsxs)(n.p,{children:["The base ",(0,i.jsx)(n.code,{children:"Model"})," class also defines the ",(0,i.jsx)(n.code,{children:"operator=="})," that allows precisely comparing two models. It compares the content of all the model's data members, from all base classes to the most derived model class. The ",(0,i.jsx)(n.code,{children:"model1 == model2"})," expression guarantees that these two models are exactly the same."]}),"\n",(0,i.jsxs)(n.p,{children:["It would be appropriate to mention that this comparison also includes relations, which means it will also compare ",(0,i.jsx)(n.strong,{children:"all"})," models (including their data members) these relations contain."]})]})}function m(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>d});var i=t(6540);const s={},a=i.createContext(s);function l(e){const n=i.useContext(a);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),i.createElement(a.Provider,{value:n},e.children)}}}]);
\ No newline at end of file
+"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[82],{5105:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>o,contentTitle:()=>d,default:()=>m,frontMatter:()=>l,metadata:()=>r,toc:()=>c});var i=t(4848),s=t(8453),a=t(8774);const l={sidebar_position:0,sidebar_label:"Getting Started",description:'TinyORM is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using TinyORM, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, TinyORM models allow you to insert, update, and delete records from the table as well.',keywords:["c++ orm","orm","getting started","tinyorm"]},d="TinyORM: Getting Started",r={id:"tinyorm/getting-started",title:"TinyORM: Getting Started",description:'TinyORM is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using TinyORM, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, TinyORM models allow you to insert, update, and delete records from the table as well.',source:"@site/docs/tinyorm/getting-started.mdx",sourceDirName:"tinyorm",slug:"/tinyorm/getting-started",permalink:"/tinyorm/getting-started",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"Getting Started",description:'TinyORM is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using TinyORM, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, TinyORM models allow you to insert, update, and delete records from the table as well.',keywords:["c++ orm","orm","getting started","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Seeding",permalink:"/database/seeding"},next:{title:"Relationships",permalink:"/tinyorm/relationships"}},o={},c=[{value:"Introduction",id:"introduction",level:2},{value:"Generating Model Classes",id:"generating-model-classes",level:2},{value:"TinyORM Model Conventions",id:"tinyorm-model-conventions",level:2},{value:"Table Names",id:"table-names",level:3},{value:"Primary Keys",id:"primary-keys",level:3},{value:""Composite" Primary Keys",id:"composite-primary-keys",level:4},{value:"Timestamps",id:"timestamps",level:3},{value:"Unix timestamps",id:"unix-timestamps",level:5},{value:"Custom timestamp column names",id:"custom-timestamp-column-names",level:5},{value:"Touching timestamps",id:"touching-timestamps",level:4},{value:"Database Connections",id:"database-connections",level:3},{value:"Default Attribute Values",id:"default-attribute-values",level:2},{value:"QDateTime and connection name problem",id:"qdatetime-and-connection-name-problem",level:5},{value:"Retrieving Models",id:"retrieving-models",level:2},{value:"Building Queries",id:"building-queries",level:4},{value:"Refreshing Models",id:"refreshing-models",level:4},{value:"Containers",id:"containers",level:3},{value:"Chunking Results",id:"chunking-results",level:3},{value:"Advanced Subqueries",id:"advanced-subqueries",level:3},{value:"Subquery Selects",id:"subquery-selects",level:4},{value:"Subquery Ordering",id:"subquery-ordering",level:4},{value:"Retrieving Single Models / Aggregates",id:"retrieving-single-models-and-aggregates",level:2},{value:"Not Found Exceptions",id:"not-found-exceptions",level:4},{value:"Retrieving Or Creating Models",id:"retrieving-or-creating-models",level:3},{value:"Retrieving Aggregates",id:"retrieving-aggregates",level:3},{value:"Inserting & Updating Models",id:"inserting-and-updating-models",level:2},{value:"Inserts",id:"inserts",level:3},{value:"Updates",id:"updates",level:3},{value:"Mass Updates",id:"mass-updates",level:4},{value:"Examining Attribute Changes",id:"examining-attribute-changes",level:4},{value:"Mass Assignment",id:"mass-assignment",level:3},{value:"Allowing Mass Assignment",id:"allowing-mass-assignment",level:4},{value:"Upserts",id:"upserts",level:3},{value:"Deleting Models",id:"deleting-models",level:2},{value:"Deleting An Existing Model By Its Primary Key",id:"deleting-an-existing-model-by-its-primary-key",level:4},{value:"Deleting Models Using Queries",id:"deleting-models-using-queries",level:4},{value:"Soft Deleting",id:"soft-deleting",level:3},{value:"Restoring Soft Deleted Models",id:"restoring-soft-deleted-models",level:4},{value:"Permanently Deleting Models",id:"permanently-deleting-models",level:4},{value:"Querying Soft Deleted Models",id:"querying-soft-deleted-models",level:3},{value:"Including Soft Deleted Models",id:"including-soft-deleted-models",level:4},{value:"Retrieving Only Soft Deleted Models",id:"retrieving-only-soft-deleted-models",level:4},{value:"Excluding Soft Deleted Models",id:"excluding-soft-deleted-models",level:4},{value:"Truncate Table",id:"truncate-table",level:3},{value:"Replicating Models",id:"replicating-models",level:2},{value:"Comparing Models",id:"comparing-models",level:2},{value:"Equality comparison",id:"equality-comparison",level:5}];function h(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h1,{id:"tinyorm-getting-started",children:"TinyORM: Getting Started"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#introduction",children:"Introduction"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#generating-model-classes",children:"Generating Model Classes"})}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#tinyorm-model-conventions",children:"TinyORM Model Conventions"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#table-names",children:"Table Names"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#primary-keys",children:"Primary Keys"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#timestamps",children:"Timestamps"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#database-connections",children:"Database Connections"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#default-attribute-values",children:"Default Attribute Values"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#retrieving-models",children:"Retrieving Models"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#containers",children:"Containers"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#chunking-results",children:"Chunking Results"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#advanced-subqueries",children:"Advanced Subqueries"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#retrieving-single-models-and-aggregates",children:"Retrieving Single Models / Aggregates"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#retrieving-or-creating-models",children:"Retrieving Or Creating Models"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#retrieving-aggregates",children:"Retrieving Aggregates"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#inserting-and-updating-models",children:"Inserting & Updating Models"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#inserts",children:"Inserts"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#updates",children:"Updates"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#mass-assignment",children:"Mass Assignment"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#upserts",children:"Upserts"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#deleting-models",children:"Deleting Models"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#soft-deleting",children:"Soft Deleting"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#querying-soft-deleted-models",children:"Querying Soft Deleted Models"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#truncate-table",children:"Truncate Table"})}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#replicating-models",children:"Replicating Models"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#comparing-models",children:"Comparing Models"})}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsx)(n.p,{children:'TinyORM is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using TinyORM, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, TinyORM models allow you to insert, update, and delete records from the table as well.'}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["Before getting started, be sure to configure a database connection in your application. For more information on configuring your database, check out the ",(0,i.jsx)(n.a,{href:"/database/getting-started#configuration",children:"database configuration documentation"}),"."]})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["If you want to see a model in which are used all possible TinyORM features you can look at the ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/tests/models/models/torrent.hpp",children:(0,i.jsx)(n.code,{children:"torrent.hpp"})})," in the TinyORM's tests, this ",(0,i.jsx)(n.code,{children:"Models::Torrent"})," class serves also as a showcase, so all possible features are defined in it."]})}),"\n",(0,i.jsx)(n.h2,{id:"generating-model-classes",children:"Generating Model Classes"}),"\n",(0,i.jsxs)(n.p,{children:["To get started, let's create the simplest TinyORM model. Models typically live in the ",(0,i.jsx)(n.code,{children:"database\\models"})," directory and extend the ",(0,i.jsx)(n.code,{children:"Orm::Tiny::Model"})," class. You may use the ",(0,i.jsx)(n.code,{children:"make:model"})," command to generate a new model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"tom make:model User\n"})}),"\n",(0,i.jsxs)(n.p,{children:["If you would like to generate a database ",(0,i.jsx)(n.a,{href:"/database/migrations",children:"migration"})," or ",(0,i.jsx)(n.a,{href:"/database/seeding",children:"seeder"})," when you generate the model, you may use the ",(0,i.jsx)(n.code,{children:"--migration"}),"/",(0,i.jsx)(n.code,{children:"-m"})," or ",(0,i.jsx)(n.code,{children:"--seeder"}),"/",(0,i.jsx)(n.code,{children:"-s"})," options:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"tom make:model User --migration --seeder\n"})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"--force"})," option forces overwriting of existing files:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"tom make:model User --migration --seeder --force\n"})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"make:model"})," is king \ud83d\udc51 among scaffolding commands that you can use to generate complete TinyORM model classes, it supports all features that TinyORM models offer. All advanced features are described in the ",(0,i.jsx)(n.code,{children:"make:model"})," help command:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"tom make:model --help\n"})}),"\n",(0,i.jsx)(n.p,{children:"Few examples:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"# Setting some model attributes\ntom make:model User --table=users --fillable=name,email,banned_at `\n --guarded=password --dates=banned_at\n\n# Generate relationship methods\ntom make:model User --one-to-one=Passport `\n --one-to-many=Post --foreign-key=post_id `\n --one-to-many=Car\n\n# Generate a basic many-to-many relationship\ntom make:model User --belongs-to-many=Tag --with-timestamps\n\n# Generate a many-to-many relationship\ntom make:model User --belongs-to-many=Tag --foreign-key=tag_id `\n --pivot-table=user_tag --as=tagged `\n --with-pivot=active,soft --with-timestamps `\n --pivot=Tagged\n\n# Generate a pivot model\ntom make:model Tagged --pivot-model\ntom make:model Tagged --pivot-model --incrementing\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Writing a ",(0,i.jsx)(n.code,{children:"make:model"})," commands is superb with the ",(0,i.jsx)(n.a,{href:"/database/migrations#tab-completion",children:"tab completion"}),"."]})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"--path"})," and ",(0,i.jsx)(n.code,{children:"--realpath"})," options work the same as for the ",(0,i.jsx)(n.a,{href:"/database/migrations#generating-migrations",children:(0,i.jsx)(n.code,{children:"make:migration"})})," command."]})}),"\n",(0,i.jsx)(n.h2,{id:"tinyorm-model-conventions",children:"TinyORM Model Conventions"}),"\n",(0,i.jsx)(n.p,{children:"Let's examine a basic model class and discuss some of TinyORM's key conventions:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#pragma once\n#ifndef FLIGHT_HPP\n#define FLIGHT_HPP\n\n#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n\n using Model::Model;\n};\n\n#endif // FLIGHT_HPP\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"TinyORM"})," source tree contains the ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/tests/models/models/torrent.hpp#L43",children:(0,i.jsx)(n.code,{children:"Torrent"})})," example model that also acts as the full-fledged example model. It has defined and also nicely commented all possible features that model classes can use or define."]})}),"\n",(0,i.jsx)(n.h3,{id:"table-names",children:"Table Names"}),"\n",(0,i.jsxs)(n.p,{children:["After glancing at the example above, you may have noticed that we did not tell TinyORM which database table corresponds to our ",(0,i.jsx)(n.code,{children:"Flight"}),' model. By convention, the "snake_case", plural name of the class will be used as the table name unless another name is explicitly specified. So, in this case, TinyORM will assume the ',(0,i.jsx)(n.code,{children:"Flight"})," model stores records in the ",(0,i.jsx)(n.code,{children:"flights"})," table, while an ",(0,i.jsx)(n.code,{children:"AirTrafficController"})," model would store records in an ",(0,i.jsx)(n.code,{children:"air_traffic_controllers"})," table."]}),"\n",(0,i.jsxs)(n.p,{children:["If your model's corresponding database table does not fit this convention, you may manually specify the model's table name by defining the private ",(0,i.jsx)(n.code,{children:"u_table"})," data member on the model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The table associated with the model. */\n QString u_table {"flights"};\n};\n'})}),"\n",(0,i.jsx)(n.h3,{id:"primary-keys",children:"Primary Keys"}),"\n",(0,i.jsxs)(n.p,{children:["TinyORM will also assume that each model's corresponding database table has a primary key column named ",(0,i.jsx)(n.code,{children:"id"}),". If necessary, you may define a private ",(0,i.jsx)(n.code,{children:"u_primaryKey"})," data member on your model to specify a different column that serves as your model's primary key:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The primary key associated with the table. */\n QString u_primaryKey {"id"};\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["In addition, TinyORM assumes that the primary key is an incrementing integer value. If you wish to use a non-incrementing or a non-numeric primary key you must define a private ",(0,i.jsx)(n.code,{children:"u_incrementing"})," data member on your model that is set to ",(0,i.jsx)(n.code,{children:"false"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! Indicates if the model's ID is auto-incrementing. */\n bool u_incrementing = false;\n};\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsxs)(n.p,{children:["Non-numeric primary keys are not currently implemented, ",(0,i.jsx)(n.code,{children:"u_incrementing"})," code logic is fully implemented, but it is only one part to make it fully work."]})}),"\n",(0,i.jsx)(n.h4,{id:"composite-primary-keys",children:'"Composite" Primary Keys'}),"\n",(0,i.jsx)(n.p,{children:'TinyORM requires each model to have at least one uniquely identifying "ID" that can serve as its primary key. "Composite" primary keys are not supported by TinyORM models. However, you are free to add additional multi-column unique indexes to your database tables, in addition to the table\'s uniquely identifying primary key.'}),"\n",(0,i.jsx)(n.h3,{id:"timestamps",children:"Timestamps"}),"\n",(0,i.jsxs)(n.p,{children:["By default, TinyORM expects ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," columns to exist on your model's corresponding database table. TinyORM will automatically set these column's values when models are created or updated. If you do not want these columns to be automatically managed by TinyORM, you should define a private ",(0,i.jsx)(n.code,{children:"u_timestamps"})," data member on your model with a value of ",(0,i.jsx)(n.code,{children:"false"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! Indicates if the model should be timestamped. */\n bool u_timestamps = false;\n};\n"})}),"\n",(0,i.jsx)(a.A,{id:"timestamps-u_dates"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"u_dates"})," static data member controls the casting of timestamp attributes. The ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," columns are automatically added to the ",(0,i.jsx)(n.code,{children:"u_dates"})," string list when the ",(0,i.jsx)(n.code,{children:"u_timestamps"})," is ",(0,i.jsx)(n.code,{children:"true"}),". Also, the ",(0,i.jsx)(n.a,{href:"#soft-deleting",children:(0,i.jsx)(n.code,{children:"Soft Deleting"})})," feature adds the ",(0,i.jsx)(n.code,{children:"deleted_at"})," column to the ",(0,i.jsx)(n.code,{children:"u_dates"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:["You may add additional columns to the ",(0,i.jsx)(n.code,{children:"u_dates"})," list. After that, these columns will be automatically formatted using the format in the ",(0,i.jsx)(n.code,{children:"u_dateFormat"})," data member during the ",(0,i.jsx)(n.code,{children:"setAttribute"})," method call:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'class Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The attributes that should be mutated to dates. */\n inline static const QStringList u_dates {"departure_at"};\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If you need to customize the format of your model's timestamps, set the private ",(0,i.jsx)(n.code,{children:"u_dateFormat"})," data member on your model. This data member determines how date attributes are stored in the database, supported formats are described in the ",(0,i.jsx)(n.code,{children:"QDateTime"})," documentation:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The storage format of the model\'s date columns. */\n QString u_dateFormat {"yyyy-MM-dd HH:mm:ss"};\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If you need to customize the format of your model's time columns, set the private ",(0,i.jsx)(n.code,{children:"u_timeFormat"})," data member on your model. This data member determines how time attributes are stored in the database, supported formats are described in the ",(0,i.jsx)(n.code,{children:"QTime"})," documentation. The default value for ",(0,i.jsx)(n.code,{children:"u_timeFormat"})," is ",(0,i.jsx)(n.code,{children:"HH:mm:ss"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'/*! The storage format of the model\'s time columns. */\nQString u_timeFormat {"HH:mm:ss.zzz"};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The default value for datetime or timestamp columns is ",(0,i.jsx)(n.code,{children:"yyyy-MM-dd HH:mm:ss"})," and for time columns is ",(0,i.jsx)(n.code,{children:"HH:mm:ss"}),"."]}),"\n",(0,i.jsx)(n.h5,{id:"unix-timestamps",children:"Unix timestamps"}),"\n",(0,i.jsxs)(n.p,{children:["You can set the ",(0,i.jsx)(n.code,{children:"u_dateFormat"})," to ",(0,i.jsx)(n.code,{children:"U"})," if you want to store dates in the database as unix timestamps:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"QString u_dateFormat {QLatin1Char('U')};\n"})}),"\n",(0,i.jsxs)(n.p,{children:["In this case ",(0,i.jsx)(n.strong,{children:"all"})," date attributes set in the ",(0,i.jsx)(n.code,{children:"u_dates"})," will be handled as unix timestamps, so also the ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," timestamp attributes."]}),"\n",(0,i.jsxs)(n.p,{children:["To create unix timestamp columns using the ",(0,i.jsx)(n.a,{href:"/database/migrations",children:"tom migrations"})," you should use ",(0,i.jsx)(n.code,{children:"integer"})," types:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Schema::table("flights", [](Blueprint &table)\n{\n table.bigInteger("created_at").nullable();\n table.bigInteger("updated_at").nullable();\n});\n'})}),"\n",(0,i.jsx)(n.h5,{id:"custom-timestamp-column-names",children:"Custom timestamp column names"}),"\n",(0,i.jsxs)(n.p,{children:["If you need to customize the names of the columns used to store the timestamps, you may define ",(0,i.jsx)(n.code,{children:"CREATED_AT"})," and ",(0,i.jsx)(n.code,{children:"UPDATED_AT"})," private static getter methods on your model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The name of the "created at" column. */\n static QString CREATED_AT() { return QStringLiteral("creation_date"); }\n /*! The name of the "updated at" column. */\n static QString UPDATED_AT() { return QStringLiteral("updated_date"); }\n};\n'})}),"\n",(0,i.jsx)(n.h4,{id:"touching-timestamps",children:"Touching timestamps"}),"\n",(0,i.jsxs)(n.p,{children:["You can explicitly touch timestamps using the ",(0,i.jsx)(n.code,{children:"touch"})," method defined on the Model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::find(1);\n\nflight->touch();\nflight->touch("added_on"); // Custom column name\n'})}),"\n",(0,i.jsxs)(n.p,{children:["You can also touch multiple rows at once using the ",(0,i.jsx)(n.code,{children:"touch"})," method defined on the TinyBuilder:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto [affected, query] = Flight::whereEq("status", "new")->touch();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"touch"})," method may also be called when building a ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'flight->history()->touch();\nflight->history()->whereEq("status", "new").touch();\n'})}),"\n",(0,i.jsx)(n.h3,{id:"database-connections",children:"Database Connections"}),"\n",(0,i.jsxs)(n.p,{children:["By default, all TinyORM models will use the default database connection that is configured for your application. If you would like to specify a different connection that should be used when interacting with a particular model, you should define a ",(0,i.jsx)(n.code,{children:"u_connection"})," private data member on the model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The database connection that should be used by the model. */\n QString u_connection {"sqlite"};\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["In special cases, when you want to query the database through a different connection, you can use ",(0,i.jsx)(n.code,{children:"Model::on"})," method, which takes the connection name as the first argument:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto user = User::on("sqlite")->find(1);\n'})}),"\n",(0,i.jsx)(n.h2,{id:"default-attribute-values",children:"Default Attribute Values"}),"\n",(0,i.jsxs)(n.p,{children:["By default, a newly instantiated model instance will not contain any attribute values. If you would like to define the default values for some of your model's attributes, you may define an ",(0,i.jsx)(n.code,{children:"u_attributes"})," data member on your model, it has to be ",(0,i.jsx)(n.strong,{children:"static"})," and can be ",(0,i.jsx)(n.strong,{children:"const"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The model\'s default values for attributes. */\n inline static const QVector u_attributes {\n {"delayed", false},\n {"progress", 0},\n {"added_on", QDateTime::currentDateTimeUtc()},\n };\n};\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsxs)(n.p,{children:["Use the ",(0,i.jsx)(n.code,{children:"Model::instance"})," or ",(0,i.jsx)(n.code,{children:"Model::instanceHeap"})," related methods to instantiate a model that contains a ",(0,i.jsx)(n.code,{children:"QDateTime"})," in Default Attribute Values, or if attributes you want to pass to the model's constructor contain a ",(0,i.jsx)(n.code,{children:"QDateTime"})," instance ",(0,i.jsx)("small",{children:"(problem is described below)"}),"."]})}),"\n",(0,i.jsx)(n.h5,{id:"qdatetime-and-connection-name-problem",children:"QDateTime and connection name problem"}),"\n",(0,i.jsxs)(n.p,{children:["If your Default Attribute Values or attributes that you can pass to the ",(0,i.jsx)(n.code,{children:"Model"})," constructor contain the ",(0,i.jsx)(n.code,{children:"QDateTime"})," instance, then ",(0,i.jsx)(n.code,{children:"TinyORM"})," throws an exception. You have to use the ",(0,i.jsx)(n.code,{children:"Model::instance"})," related methods to create such a Model."]}),"\n",(0,i.jsxs)(n.p,{children:["Virtually everything important is covered in the thrown exception, but let me summarize it. The problem is that the ",(0,i.jsx)(n.code,{children:"QDateTime"})," instance is converted to a string based on the ",(0,i.jsx)(n.code,{children:"Model::u_dateFormat"}),", or if not defined, the date format from ",(0,i.jsx)(n.code,{children:"Orm::Query::Grammars::Grammar"})," will be used. This ",(0,i.jsx)(n.code,{children:"QueryGrammar"})," is obtained from ",(0,i.jsx)(n.code,{children:"Orm::DatabaseConnection"})," and because of that TinyORM needs to know the ",(0,i.jsx)(n.strong,{children:"connection name"})," and that's the crux of this problem. You can define your connection name using the ",(0,i.jsx)(n.code,{children:"Model::u_connection"})," in your derived model class, but this derived model ",(0,i.jsx)(n.strong,{children:"is not yet initialized"}),", so the ",(0,i.jsx)(n.code,{children:"Model::u_connection"})," is also not initialized."]}),"\n",(0,i.jsxs)(n.p,{children:["So if the ",(0,i.jsx)(n.code,{children:"Model::u_connection"})," is not yet initialized, ",(0,i.jsx)(n.code,{children:"TinyORM"})," can't obtain the ",(0,i.jsx)(n.code,{children:"Orm::DatabaseConnection"})," -> ",(0,i.jsx)(n.code,{children:"QueryGrammar"})," -> ",(0,i.jsx)(n.code,{children:"dateFormat"}),"."]}),"\n",(0,i.jsx)(n.h2,{id:"retrieving-models",children:"Retrieving Models"}),"\n",(0,i.jsxs)(n.p,{children:["Once you have created a model and its associated database table, you are ready to start retrieving data from your database. You can think of each TinyORM model as a powerful ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"})," allowing you to fluently query the database table associated with the model. The model's ",(0,i.jsx)(n.code,{children:"all"})," method will retrieve all of the records from the model's associated database table:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include "models/flight.hpp"\n\nfor (const auto &flight : Flight::all())\n qDebug() << flight["name"].toString();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"building-queries",children:"Building Queries"}),"\n",(0,i.jsxs)(n.p,{children:["The TinyORM ",(0,i.jsx)(n.code,{children:"all"})," method will return all of the results in the model's table. However, since each TinyORM model serves as a ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"}),", you may add additional constraints to queries and then invoke the ",(0,i.jsx)(n.code,{children:"get"})," method to retrieve the results:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flights = Flight::whereEq("active", 1)\n ->orderBy("name")\n .take(10)\n .get();\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["Since TinyORM models are query builders, you should review all of the methods provided by TinyORM's ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"}),". You may use any of these methods when writing your TinyORM queries."]})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["All the static methods defined on the ",(0,i.jsx)(n.code,{children:"Orm::Tiny::Model"})," class, which start building queries like ",(0,i.jsx)(n.code,{children:"where"}),", ",(0,i.jsx)(n.code,{children:"latest"}),", ",(0,i.jsx)(n.code,{children:"oldest"}),", ",(0,i.jsx)(n.code,{children:"with"}),", ... return ",(0,i.jsx)(n.code,{children:"std::unique_ptr>"}),", ",(0,i.jsx)(n.code,{children:"TinyBuilder = Orm::Tiny::Builder"})," and ",(0,i.jsx)(n.code,{children:"Model"})," template argument is queried model class."]})}),"\n",(0,i.jsx)(n.h4,{id:"refreshing-models",children:"Refreshing Models"}),"\n",(0,i.jsxs)(n.p,{children:['If you already have an instance of the TinyORM model that was retrieved from the database, you can "refresh" the model using the ',(0,i.jsx)(n.code,{children:"fresh"})," and ",(0,i.jsx)(n.code,{children:"refresh"})," methods. The ",(0,i.jsx)(n.code,{children:"fresh"})," method will re-retrieve the model from the database. The existing model instance will not be affected:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::whereEq("number", "FR 900")->first();\n\nauto freshFlight = flight->fresh();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"refresh"})," method will re-hydrate the existing model using fresh data from the database. In addition, all of its loaded relationships will be refreshed as well:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::whereEq("number", "FR 900")->first();\n\nflight->setAttribute("number", "FR 456");\n\nflight->refresh();\n\nflight->getAttribute("number"); // "FR 900"\n'})}),"\n",(0,i.jsx)(n.h3,{id:"containers",children:"Containers"}),"\n",(0,i.jsxs)(n.p,{children:["As we have seen, TinyORM methods like ",(0,i.jsx)(n.code,{children:"all"})," and ",(0,i.jsx)(n.code,{children:"get"})," retrieve multiple records from the database. Since these methods return a ",(0,i.jsx)(n.code,{children:"QVector"}),", you can iterate it like any other container with the ",(0,i.jsx)(n.a,{href:"https://en.cppreference.com/w/cpp/language/range-for",children:"Range-based for loop"}),", ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/containers.html#stl-style-iterators",children:"STL-Style Iterators"}),", ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/containers.html#java-style-iterators",children:"Java-Style Iterators"})," or ",(0,i.jsx)(n.a,{href:"https://www.walletfox.com/course/quickref_range_v3.php",children:"Ranges"}),"."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include "models/flight.hpp"\n\nfor (const auto &flight : Flight::all())\n qDebug() << flight["name"].toString();\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["An ",(0,i.jsx)(n.code,{children:"all"})," method is defined on the ",(0,i.jsx)(n.code,{children:"Orm::Tiny::Model"})," class and ",(0,i.jsx)(n.code,{children:"get"})," method is defined on the ",(0,i.jsx)(n.code,{children:"Orm::Tiny::Builder"}),", may be also referred as ",(0,i.jsx)(n.code,{children:"TinyBuilder"}),", and on the ",(0,i.jsx)(n.code,{children:"Orm::Query::Builder"})," alias ",(0,i.jsx)(n.code,{children:"QueryBuilder"}),"."]})}),"\n",(0,i.jsx)(n.h3,{id:"chunking-results",children:"Chunking Results"}),"\n",(0,i.jsxs)(n.p,{children:["Your application may run out of memory if you attempt to load tens of thousands of TinyORM records via the ",(0,i.jsx)(n.code,{children:"all"})," or ",(0,i.jsx)(n.code,{children:"get"})," methods. Instead of using these methods, the ",(0,i.jsx)(n.code,{children:"chunk"})," method may be used to process large numbers of models more efficiently."]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"chunk"})," method will retrieve a subset of TinyORM models, passing them to a lambda expression for processing. Since only the current chunk of TinyORM models is retrieved at a time, the ",(0,i.jsx)(n.code,{children:"chunk"})," method will provide significantly reduced memory usage when working with a large number of models:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"Flight::chunk(200, [](QVector &&flights, const int /*unused*/)\n{\n for (auto &&flight : flights) {\n //\n }\n\n return true;\n});\n"})}),"\n",(0,i.jsxs)(n.p,{children:["The first argument passed to the ",(0,i.jsx)(n.code,{children:"chunk"}),' method is the number of records you wish to receive per "chunk". The lambda expression passed as the second argument will be invoked for each chunk that is retrieved from the database. A database query will be executed to retrieve each chunk of records passed to the lambda expression.']}),"\n",(0,i.jsxs)(n.p,{children:["If you are filtering the results of the ",(0,i.jsx)(n.code,{children:"chunk"})," method based on a column that you will also be updating while iterating over the results, you should use the ",(0,i.jsx)(n.code,{children:"chunkById"})," method. Using the ",(0,i.jsx)(n.code,{children:"chunk"})," method in these scenarios could lead to unexpected and inconsistent results. Internally, the ",(0,i.jsx)(n.code,{children:"chunkById"})," method will always retrieve models with an ",(0,i.jsx)(n.code,{children:"id"})," column greater than the last model in the previous chunk:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Flight::whereEq("departed", true)\n ->chunkById(200, [](QVector &&flights, const int /*unused*/)\n {\n for (auto &&flight : flights)\n flight.update({{"departed", false}});\n\n return true;\n });\n'})}),"\n",(0,i.jsx)(n.h3,{id:"advanced-subqueries",children:"Advanced Subqueries"}),"\n",(0,i.jsx)(n.h4,{id:"subquery-selects",children:"Subquery Selects"}),"\n",(0,i.jsxs)(n.p,{children:["TinyORM also offers advanced subquery support, which allows you to pull information from related tables in a single query. For example, let's imagine that we have a table of flight ",(0,i.jsx)(n.code,{children:"destinations"})," and a table of ",(0,i.jsx)(n.code,{children:"flights"})," to destinations. The ",(0,i.jsx)(n.code,{children:"flights"})," table contains an ",(0,i.jsx)(n.code,{children:"arrived_at"})," column which indicates when the flight arrived at the destination."]}),"\n",(0,i.jsxs)(n.p,{children:["Using the subquery functionality available to the query builder's ",(0,i.jsx)(n.code,{children:"select"})," and ",(0,i.jsx)(n.code,{children:"addSelect"})," methods, we can select all of the ",(0,i.jsx)(n.code,{children:"destinations"})," and the name of the flight that most recently arrived at that destination using a single query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/destination.hpp"\n#include "models/flight.hpp"\n\nreturn Destination::addSelect(\n Flight::select("name")\n ->whereColumnEq("destination_id", "destinations.id")\n .orderByDesc("arrived_at")\n .limit(1)\n .toBase(),\n "last_flight")\n ->get();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"subquery-ordering",children:"Subquery Ordering"}),"\n",(0,i.jsxs)(n.p,{children:["In addition, the query builder's ",(0,i.jsx)(n.code,{children:"orderBy"})," function supports subqueries. Continuing to use our flight example, we may use this functionality to sort all destinations based on when the last flight arrived at that destination. Again, this may be done while executing a single database query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'return Destination::orderByDesc(\n Flight::select("arrived_at")\n ->whereColumnEq("destination_id", "destinations.id")\n .orderByDesc("arrived_at")\n .limit(1)\n .toBase())\n ->get();\n'})}),"\n",(0,i.jsx)(n.h2,{id:"retrieving-single-models-and-aggregates",children:"Retrieving Single Models / Aggregates"}),"\n",(0,i.jsxs)(n.p,{children:["In addition to retrieving all of the records matching a given query, you may also retrieve single records using the ",(0,i.jsx)(n.code,{children:"find"}),", ",(0,i.jsx)(n.code,{children:"first"}),", ",(0,i.jsx)(n.code,{children:"firstWhere"}),", or ",(0,i.jsx)(n.code,{children:"firstWhereEq"})," methods. Instead of returning a vector of models, these methods return a single model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\n// Retrieve a model by its primary key...\nauto flight = Flight::find(1);\n\n// Retrieve the first model matching the query constraints...\nauto flight = Flight::whereEq("active", 1)->first();\n\n// Alternative to retrieving the first model matching the query constraints...\nauto flight = Flight::firstWhere("active", "=", 1);\n\n// Alternative firstWhere method syntax\nauto flight = Flight::firstWhereEq("active", 1);\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes you may wish to perform some other action if no results are found. The ",(0,i.jsx)(n.code,{children:"findOr"})," methods will return a single model instance or, if no results are found, execute the given lambda expression. The value returned by the lambda will be considered the result of the method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"auto flight = Flight::findOr(1, [] {\n // ...\n});\n\nauto flight = Flight::findOr(1, [] {\n // ...\n return 10;\n});\n\nauto flight = Flight::findOr>(1, [] {\n // ...\n return Flight::find(10);\n});\n"})}),"\n",(0,i.jsxs)(n.p,{children:["To obtain only a subset of the model's attributes you may use the ",(0,i.jsx)(n.code,{children:"Model::only"})," method, it returns the ",(0,i.jsx)(n.code,{children:"QVector"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nusing Orm::Constants::ID;\nusing Orm::Constants::NAME;\n\nauto flight = Flight::find(1);\n\nauto attributes = flight->only({ID, NAME});\n'})}),"\n",(0,i.jsx)(n.h4,{id:"not-found-exceptions",children:"Not Found Exceptions"}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes you may wish to throw an exception if a model is not found. The ",(0,i.jsx)(n.code,{children:"findOrFail"})," and ",(0,i.jsx)(n.code,{children:"firstOrFail"})," methods will retrieve the first result of the query; however, if no result is found, an ",(0,i.jsx)(n.code,{children:"Orm::Tiny::ModelNotFoundError"})," will be thrown:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::findOrFail(1);\n\nauto flight = Flight::where("legs", ">", 3)->firstOrFail();\n'})}),"\n",(0,i.jsx)(n.h3,{id:"retrieving-or-creating-models",children:"Retrieving Or Creating Models"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"firstOrCreate"})," method will attempt to locate a database record using the given column / value pairs. If the model can not be found in the database, a record will be inserted with the attributes resulting from merging the first ",(0,i.jsx)(n.code,{children:"QVector"})," argument with the optional second ",(0,i.jsx)(n.code,{children:"QVector"})," argument:"]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"firstOrNew"})," method, like ",(0,i.jsx)(n.code,{children:"firstOrCreate"}),", will attempt to locate a record in the database matching the given attributes. However, if a model is not found, a new model instance will be returned. Note that the model returned by ",(0,i.jsx)(n.code,{children:"firstOrNew"})," has not yet been persisted to the database. You will need to manually call the ",(0,i.jsx)(n.code,{children:"save"})," method to persist it:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\n// Retrieve flight by name or create it if it doesn\'t exist...\nauto flight = Flight::firstOrCreate({\n {"name", "London to Paris"}\n});\n\n// Retrieve flight by name or create it with the name, delayed, and arrival_time attributes...\nauto flight = Flight::firstOrCreate(\n {{"name", "London to Paris"}},\n {{"delayed", 1}, {"arrival_time", "11:30"}}\n);\n\n// Retrieve flight by name or instantiate a new Flight instance...\nauto flight = Flight::firstOrNew({\n {"name", "London to Paris"}\n});\n\n// Retrieve flight by name or instantiate with the name, delayed, and arrival_time attributes...\nauto flight = Flight::firstOrNew(\n {{"name", "Tokyo to Sydney"}},\n {{"delayed", 1}, {"arrival_time", "11:30"}}\n);\n'})}),"\n",(0,i.jsx)(n.h3,{id:"retrieving-aggregates",children:"Retrieving Aggregates"}),"\n",(0,i.jsxs)(n.p,{children:["When interacting with TinyORM models, you may also use the ",(0,i.jsx)(n.code,{children:"count"}),", ",(0,i.jsx)(n.code,{children:"sum"}),", ",(0,i.jsx)(n.code,{children:"max"}),", and other ",(0,i.jsx)(n.a,{href:"/database/query-builder#aggregates",children:"aggregate methods"})," provided by the ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"}),". As you might expect, these methods return a scalar value instead of a TinyORM model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto count = Flight::whereEq("active", 1)->count();\n\nauto max = Flight::whereEq("active", 1)->max("price");\n'})}),"\n",(0,i.jsx)(n.h2,{id:"inserting-and-updating-models",children:"Inserting & Updating Models"}),"\n",(0,i.jsx)(n.h3,{id:"inserts",children:"Inserts"}),"\n",(0,i.jsxs)(n.p,{children:["Of course, when using TinyORM, we don't only need to retrieve models from the database. We also need to insert new records. Thankfully, TinyORM makes it simple. To insert a new record into the database, you should instantiate a new model instance and set attributes on the model. Then, call the ",(0,i.jsx)(n.code,{children:"save"})," method on the model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\n// Store a new flight in the database\nFlight flight;\nflight.setAttribute("name", "Slovakia to Czech");\nflight.save();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["In this example, we assign the ",(0,i.jsx)(n.code,{children:"name"})," attribute of the ",(0,i.jsx)(n.code,{children:"Flight"})," model instance. When we call the ",(0,i.jsx)(n.code,{children:"save"})," method, a record will be inserted into the database. The model's ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," timestamps will automatically be set when the ",(0,i.jsx)(n.code,{children:"save"})," method is called, so there is no need to set them manually."]}),"\n",(0,i.jsxs)(n.p,{children:["Alternatively, you may use the ",(0,i.jsx)(n.code,{children:"create"}),' method to "save" a new model using a single C++ statement. The inserted model instance will be returned to you by the ',(0,i.jsx)(n.code,{children:"create"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nauto flight = Flight::create({\n {"name", "London to Paris"},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["However, before using the ",(0,i.jsx)(n.code,{children:"create"})," method, you will need to specify either a ",(0,i.jsx)(n.code,{children:"u_fillable"})," or ",(0,i.jsx)(n.code,{children:"u_guarded"})," static data member on your model class. These static data members are required because all TinyORM models are protected against mass assignment vulnerabilities by default. To learn more about mass assignment, please consult the ",(0,i.jsx)(n.a,{href:"#mass-assignment",children:"mass assignment documentation"}),"."]}),"\n",(0,i.jsx)(n.h3,{id:"updates",children:"Updates"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"save"})," method may also be used to update models that already exist in the database. To update a model, you should retrieve it and set any attributes you wish to update. Then, you should call the model's ",(0,i.jsx)(n.code,{children:"save"})," method. Again, the ",(0,i.jsx)(n.code,{children:"updated_at"})," timestamp will automatically be updated, so there is no need to manually set its value:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nauto flight = Flight::find(1);\n\nflight->setAttribute("name", "Paris to London");\n\nflight->save();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"mass-updates",children:"Mass Updates"}),"\n",(0,i.jsxs)(n.p,{children:["Updates can also be performed against models that match a given query. In this example, all flights that are ",(0,i.jsx)(n.code,{children:"active"})," and have a ",(0,i.jsx)(n.code,{children:"destination"})," of ",(0,i.jsx)(n.code,{children:"San Diego"})," will be marked as delayed:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Flight::whereEq("active", 1)\n ->whereEq("destination", "San Diego")\n .update({{"delayed", 1}});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"update"})," method expects the ",(0,i.jsx)(n.code,{children:"QVector"})," of column and value pairs representing the columns that should be updated."]}),"\n",(0,i.jsx)(n.h4,{id:"examining-attribute-changes",children:"Examining Attribute Changes"}),"\n",(0,i.jsxs)(n.p,{children:["TinyORM provides the ",(0,i.jsx)(n.code,{children:"isDirty"}),", ",(0,i.jsx)(n.code,{children:"isClean"}),", and ",(0,i.jsx)(n.code,{children:"wasChanged"})," methods to examine the internal state of your model and determine how its attributes have changed from when the model was originally retrieved."]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"isDirty"})," method determines if any of the model's attributes have been changed since the model was retrieved. You may pass a specific attribute name to the ",(0,i.jsx)(n.code,{children:"isDirty"})," method to determine if a particular attribute is dirty. The ",(0,i.jsx)(n.code,{children:"isClean"})," will determine if an attribute has remained unchanged since the model was retrieved. This method also accepts an optional attribute argument:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/user.hpp"\n\nauto user = User::create({\n {"first_name", "Silver"},\n {"last_name", "Zachara"},\n {"title", "Developer"},\n});\n\nuser.setAttribute("title", "Painter");\n\nuser.isDirty(); // true\nuser.isDirty("title"); // true\nuser.isDirty("first_name"); // false\n\nuser.isClean(); // false\nuser.isClean("title"); // false\nuser.isClean("first_name"); // true\n\nuser.save();\n\nuser.isDirty(); // false\nuser.isClean(); // true\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"wasChanged"})," method determines if any attributes were changed after the model was last saved into the database. If needed, you may pass an attribute name to see if a particular attribute was changed:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto user = User::create({\n {"first_name", "Silver"},\n {"last_name", "Zachara"},\n {"title", "Developer"},\n});\n\nuser.setAttribute("title", "Painter");\n\nuser.wasChanged(); // false\n\nuser.save();\n\nuser.wasChanged(); // true\nuser.wasChanged("title"); // true\nuser.wasChanged("first_name"); // false\n'})}),"\n",(0,i.jsx)(n.h3,{id:"mass-assignment",children:"Mass Assignment"}),"\n",(0,i.jsxs)(n.p,{children:["You may use the ",(0,i.jsx)(n.code,{children:"create"}),' method to "save" a new model using a single C++ statement. The inserted model instance will be returned to you by the method:']}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nauto flight = Flight::create({\n {"name", "London to Paris"},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["However, before using the ",(0,i.jsx)(n.code,{children:"create"})," method, you will need to specify either a ",(0,i.jsx)(n.code,{children:"u_fillable"})," or ",(0,i.jsx)(n.code,{children:"u_guarded"})," static data member on your model class. These data members are required because all TinyORM models are protected against mass assignment vulnerabilities by default."]}),"\n",(0,i.jsxs)(n.p,{children:["A mass assignment vulnerability occurs when a user passes an unexpected HTTP request field and that field changes a column in your database that you did not expect. For example, a malicious user might send an ",(0,i.jsx)(n.code,{children:"is_admin"})," parameter through an HTTP request, which is then passed to your model's ",(0,i.jsx)(n.code,{children:"create"})," method, allowing the user to escalate themselves to an administrator."]}),"\n",(0,i.jsxs)(n.p,{children:["So, to get started, you should define which model attributes you want to make mass assignable. You may do this using the ",(0,i.jsx)(n.code,{children:"u_fillable"})," static data member on the model. For example, let's make the ",(0,i.jsx)(n.code,{children:"name"})," attribute of our ",(0,i.jsx)(n.code,{children:"Flight"})," model mass assignable:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n\n using Model::Model;\n\n /*! The attributes that are mass assignable. */\n inline static QStringList u_fillable {\n "name",\n };\n};\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Once you have specified which attributes are mass assignable, you may use the ",(0,i.jsx)(n.code,{children:"create"})," method to insert a new record in the database. The ",(0,i.jsx)(n.code,{children:"create"})," method returns the newly created model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::create({{"name", "London to Paris"}});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If you already have a model instance, you may use the ",(0,i.jsx)(n.code,{children:"fill"})," method to populate it with the vector of attributes:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'flight.fill({{"name", "Amsterdam to Frankfurt"}});\n'})}),"\n",(0,i.jsx)(n.h4,{id:"allowing-mass-assignment",children:"Allowing Mass Assignment"}),"\n",(0,i.jsxs)(n.p,{children:["If you would like to make all of your attributes mass assignable, you may define your model's ",(0,i.jsx)(n.code,{children:"u_guarded"})," static data member as an empty vector. If you choose to unguard your model, you should take special care to always hand-craft the vectors passed to TinyORM's ",(0,i.jsx)(n.code,{children:"fill"}),", ",(0,i.jsx)(n.code,{children:"create"}),", and ",(0,i.jsx)(n.code,{children:"update"})," methods:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#include \n\nusing Orm::Tiny::Model;\n\nclass Flight final : public Model\n{\n friend Model;\n\n using Model::Model;\n\n /*! The attributes that aren't mass assignable. */\n inline static QStringList u_guarded {};\n};\n"})}),"\n",(0,i.jsx)(n.h3,{id:"upserts",children:"Upserts"}),"\n",(0,i.jsx)(n.p,{children:"Occasionally, you may need to update an existing model or create a new model if no matching model exists."}),"\n",(0,i.jsxs)(n.p,{children:["In the example below, if a flight exists with a ",(0,i.jsx)(n.code,{children:"departure"})," location of ",(0,i.jsx)(n.code,{children:"Oakland"})," and a ",(0,i.jsx)(n.code,{children:"destination"})," location of ",(0,i.jsx)(n.code,{children:"San Diego"}),", its ",(0,i.jsx)(n.code,{children:"price"})," and ",(0,i.jsx)(n.code,{children:"discounted"})," columns will be updated. If no such flight exists, a new flight will be created which has the attributes resulting from merging the first argument vector with the second argument vector:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::updateOrCreate(\n {{"departure", "Oakland"}, {"destination", "San Diego"}},\n {{"price", 99}, {"discounted", 1}}\n);\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"firstOrCreate"})," and ",(0,i.jsx)(n.code,{children:"updateOrCreate"})," methods persist the model, so there's no need to manually call the ",(0,i.jsx)(n.code,{children:"save"})," method."]})}),"\n",(0,i.jsxs)(n.p,{children:['If you would like to perform multiple "upserts" in a single query, then you should use the ',(0,i.jsx)(n.code,{children:"upsert"})," method instead. The method's first argument consists of the values to insert or update, while the second argument lists the column(s) that uniquely identify records within the associated table. The method's third and final argument is the vector of the columns that should be updated if a matching record already exists in the database. The ",(0,i.jsx)(n.code,{children:"upsert"})," method will automatically set the ",(0,i.jsx)(n.code,{children:"created_at"})," and ",(0,i.jsx)(n.code,{children:"updated_at"})," timestamps if timestamps are enabled on the model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Flight::upsert(\n {{{"departure", "Oakland"}, {"destination", "San Diego"}, {"price", 99}},\n {{"departure", "Chicago"}, {"destination", "New York"}, {"price", 150}}},\n {"departure", "destination"},\n {"price"}\n);\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsxs)(n.p,{children:["All databases except SQL Server require the columns in the second argument of the ",(0,i.jsx)(n.code,{children:"upsert"}),' method to have a "primary" or "unique" index. In addition, the MySQL database driver ignores the second argument of the ',(0,i.jsx)(n.code,{children:"upsert"}),' method and always uses the "primary" and "unique" indexes of the table to detect existing records.']})}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["Row and column aliases will be used with the MySQL server >=8.0.19 instead of the VALUES() function as is described in the MySQL ",(0,i.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.4/en/insert-on-duplicate.html",children:"documentation"}),". The MySQL server version is auto-detected and can be overridden in the ",(0,i.jsx)(n.a,{href:"/database/getting-started#configuration",children:"configuration"}),"."]})}),"\n",(0,i.jsx)(n.h2,{id:"deleting-models",children:"Deleting Models"}),"\n",(0,i.jsxs)(n.p,{children:["To delete a model, you may call the ",(0,i.jsx)(n.code,{children:"remove"}),", or an alias ",(0,i.jsx)(n.code,{children:"deleteRow"})," method on the model instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include "models/flight.hpp"\n\nauto flight = Flight::find(1);\n\nflight->remove();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"deleting-an-existing-model-by-its-primary-key",children:"Deleting An Existing Model By Its Primary Key"}),"\n",(0,i.jsxs)(n.p,{children:["In the example above, we are retrieving the model from the database before calling the ",(0,i.jsx)(n.code,{children:"remove"})," method. However, if you know the primary key of the model, you may delete the model without explicitly retrieving it by calling the ",(0,i.jsx)(n.code,{children:"destroy"})," method. In addition to accepting the single primary key, the ",(0,i.jsx)(n.code,{children:"destroy"})," method can accept multiple primary keys:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"Flight::destroy(1);\n\nFlight::destroy({1, 2, 3});\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"destroy"})," method loads models from the database and calls the ",(0,i.jsx)(n.code,{children:"remove"})," method on each model individually, the reason for this is future compatibility with events."]})}),"\n",(0,i.jsx)(n.h4,{id:"deleting-models-using-queries",children:"Deleting Models Using Queries"}),"\n",(0,i.jsx)(n.p,{children:"Of course, you may build the query to delete all models matching your query's criteria. In this example, we will delete all flights that are marked as inactive:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto deletedRows = Flight::whereEq("active", 0)->remove();\n'})}),"\n",(0,i.jsx)(n.h3,{id:"soft-deleting",children:"Soft Deleting"}),"\n",(0,i.jsxs)(n.p,{children:['In addition to actually removing records from your database, TinyORM can also "soft delete" models. When models are soft deleted, they are not actually removed from your database. Instead, a ',(0,i.jsx)(n.code,{children:"deleted_at"}),' attribute is set on the model indicating the date and time at which the model was "deleted". To enable soft deletes for a model, add the ',(0,i.jsx)(n.code,{children:"Orm::Tiny::SoftDeletes"})," base class to the model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::Tiny::Model;\nusing Orm::Tiny::SoftDeletes;\n\nclass Flight final : public Model,\n public SoftDeletes\n{\n friend Model;\n using Model::Model;\n\nprivate:\n /*! The table associated with the model. */\n QString u_table {"flights"};\n};\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"SoftDeletes"})," base class will automatically cast the ",(0,i.jsx)(n.code,{children:"deleted_at"})," attribute to the ",(0,i.jsx)(n.code,{children:"QDateTime"})," instance for you (it adds the ",(0,i.jsx)(n.code,{children:"deleted_at"})," column to the model's ",(0,i.jsx)(n.a,{href:"#timestamps-u_dates",children:(0,i.jsx)(n.code,{children:"u_dates"})})," list)."]})}),"\n",(0,i.jsxs)(n.p,{children:["You should also add the ",(0,i.jsx)(n.code,{children:"deleted_at"})," column to your database table. The TinyORM ",(0,i.jsx)(n.a,{href:"/database/migrations",children:"schema builder"})," contains a helper method to create this column:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Schema::table("flights", [](Blueprint &table)\n{\n table.softDeletes();\n});\n\nSchema::table("flights", [](Blueprint &table)\n{\n table.dropSoftDeletes();\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Now, when you call the ",(0,i.jsx)(n.code,{children:"remove"})," or ",(0,i.jsx)(n.code,{children:"deleteModel"})," method on the model, the ",(0,i.jsx)(n.code,{children:"deleted_at"})," column will be set to the current date and time. However, the model's database record will be left in the table. When querying a model that uses soft deletes, the soft deleted models will automatically be excluded from all query results."]}),"\n",(0,i.jsxs)(n.p,{children:["To determine if a given model instance has been soft deleted, you may use the ",(0,i.jsx)(n.code,{children:"trashed"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"if (flight->trashed()) {\n //\n}\n"})}),"\n",(0,i.jsx)(n.h4,{id:"restoring-soft-deleted-models",children:"Restoring Soft Deleted Models"}),"\n",(0,i.jsxs)(n.p,{children:['Sometimes you may wish to "un-delete" a soft deleted model. To restore a soft deleted model, you may call the ',(0,i.jsx)(n.code,{children:"restore"})," method on a model instance. The ",(0,i.jsx)(n.code,{children:"restore"})," method will set the model's ",(0,i.jsx)(n.code,{children:"deleted_at"})," column to ",(0,i.jsx)(n.code,{children:"null"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->restore();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["You may also use the ",(0,i.jsx)(n.code,{children:"restore"})," method in a query to restore multiple models:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'Flight::withTrashed()\n ->whereEq("airline_id", 1)\n .restore();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"restore"})," method may also be used when building ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," queries:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->restore();\n"})}),"\n",(0,i.jsx)(n.h4,{id:"permanently-deleting-models",children:"Permanently Deleting Models"}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes you may need to truly remove a model from your database. You may use the ",(0,i.jsx)(n.code,{children:"forceDelete"})," method (or it's alias ",(0,i.jsx)(n.code,{children:"forceRemove"}),") to permanently remove a soft deleted model from the database table:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->forceDelete();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["You may also use the ",(0,i.jsx)(n.code,{children:"forceDelete"})," method when building TinyORM relationship queries:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->forceDelete();\n"})}),"\n",(0,i.jsx)(n.h3,{id:"querying-soft-deleted-models",children:"Querying Soft Deleted Models"}),"\n",(0,i.jsx)(n.h4,{id:"including-soft-deleted-models",children:"Including Soft Deleted Models"}),"\n",(0,i.jsxs)(n.p,{children:["As noted above, soft deleted models will automatically be excluded from query results. However, you may force soft deleted models to be included in a query's results by calling the ",(0,i.jsx)(n.code,{children:"withTrashed"})," method on the query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flights = Flight::withTrashed()\n ->whereEq("account_id", 1)\n .get();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"withTrashed"})," method may also be called when building a ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->withTrashed().get();\n"})}),"\n",(0,i.jsx)(n.h4,{id:"retrieving-only-soft-deleted-models",children:"Retrieving Only Soft Deleted Models"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"onlyTrashed"})," method will retrieve ",(0,i.jsx)(n.strong,{children:"only"})," soft deleted models:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flights = Flight::onlyTrashed()\n ->whereEq("airline_id", 1)\n .get();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"onlyTrashed"})," method may also be called when building a ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->onlyTrashed().get();\n"})}),"\n",(0,i.jsx)(n.h4,{id:"excluding-soft-deleted-models",children:"Excluding Soft Deleted Models"}),"\n",(0,i.jsxs)(n.p,{children:["As noted above, soft deleted models will automatically be excluded from query results. However, you may force soft deleted models to be ",(0,i.jsx)(n.strong,{children:"excluded"})," in a query's results by calling the ",(0,i.jsx)(n.code,{children:"withoutTrashed"})," method on the query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flights = Flight::withoutTrashed()\n ->whereEq("account_id", 1)\n .get();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"withoutTrashed"})," method may also be called when building a ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationship"})," query:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"flight->history()->withoutTrashed().get();\n"})}),"\n",(0,i.jsx)(n.h3,{id:"truncate-table",children:"Truncate Table"}),"\n",(0,i.jsxs)(n.p,{children:["You may call the ",(0,i.jsx)(n.code,{children:"truncate"})," method to delete all of the model's associated database records. The ",(0,i.jsx)(n.code,{children:"truncate"})," operation will also reset any auto-incrementing IDs on the model's associated table:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"Flight::truncate();\n"})}),"\n",(0,i.jsx)(n.h2,{id:"replicating-models",children:"Replicating Models"}),"\n",(0,i.jsxs)(n.p,{children:["You may create an unsaved copy of an existing model instance using the ",(0,i.jsx)(n.code,{children:"replicate"})," method. This method is particularly useful when you have model instances that share many of the same attributes:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto shipping = Address::create({\n {"type", "shipping"},\n {"line_1", "123 Example Street"},\n {"city", "Victorville"},\n {"state", "CA"},\n {"postcode", "90001"},\n});\n\nauto billing = shipping.replicate();\n\nbilling.fill({\n {"type", "billing"},\n});\n\nbilling.save();\n'})}),"\n",(0,i.jsxs)(n.p,{children:["To exclude one or more attributes from being replicated to the new model, you may pass an unordered_set to the ",(0,i.jsx)(n.code,{children:"replicate"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'auto flight = Flight::create({\n {"destination", "LAX"},\n {"origin", "LHR"},\n {"last_flown", "2020-03-04 11:00:00"},\n {"last_pilot_id", 747},\n});\n\nflight = flight.replicate({\n "last_flown",\n "last_pilot_id",\n});\n'})}),"\n",(0,i.jsx)(n.h2,{id:"comparing-models",children:"Comparing Models"}),"\n",(0,i.jsxs)(n.p,{children:['Sometimes you may need to determine if two models are the "same" or not. The ',(0,i.jsx)(n.code,{children:"is"})," and ",(0,i.jsx)(n.code,{children:"isNot"})," methods may be used to quickly verify two models have the same primary key, table, and database connection or not:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"if (post->is(anotherPost)) {\n //\n}\n\nif (post->isNot(anotherPost)) {\n //\n}\n"})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"is"})," and ",(0,i.jsx)(n.code,{children:"isNot"})," methods are also available when using the ",(0,i.jsx)(n.code,{children:"belongsTo"})," and ",(0,i.jsx)(n.code,{children:"hasOne"})," ",(0,i.jsx)(n.a,{href:"/tinyorm/relationships",children:"relationships"}),". This method is particularly helpful when you would like to compare a related model without issuing a query to retrieve that model:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"if (post->author()->is(user)) {\n //\n}\n"})}),"\n",(0,i.jsx)(n.h5,{id:"equality-comparison",children:"Equality comparison"}),"\n",(0,i.jsxs)(n.p,{children:["The base ",(0,i.jsx)(n.code,{children:"Model"})," class also defines the ",(0,i.jsx)(n.code,{children:"operator=="})," that allows precisely comparing two models. It compares the content of all the model's data members, from all base classes to the most derived model class. The ",(0,i.jsx)(n.code,{children:"model1 == model2"})," expression guarantees that these two models are exactly the same."]}),"\n",(0,i.jsxs)(n.p,{children:["It would be appropriate to mention that this comparison also includes relations, which means it will also compare ",(0,i.jsx)(n.strong,{children:"all"})," models (including their data members) these relations contain."]})]})}function m(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>d});var i=t(6540);const s={},a=i.createContext(s);function l(e){const n=i.useContext(a);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),i.createElement(a.Provider,{value:n},e.children)}}}]);
\ No newline at end of file
diff --git a/assets/js/ba3d4959.0b166b7a.js b/assets/js/ba3d4959.0c16349a.js
similarity index 99%
rename from assets/js/ba3d4959.0b166b7a.js
rename to assets/js/ba3d4959.0c16349a.js
index af699f7c2..a63938a63 100644
--- a/assets/js/ba3d4959.0b166b7a.js
+++ b/assets/js/ba3d4959.0c16349a.js
@@ -1 +1 @@
-"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[170],{3418:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>Q,contentTitle:()=>v,default:()=>L,frontMatter:()=>y,metadata:()=>_,toc:()=>T});var i=t(4848),r=t(8453),a=t(9365),s=t(1470),o=t(6540);let l=null,c=null;function d(){const[e,n]=(0,o.useState)(!1),[t,r]=(0,o.useState)(!1);return(0,o.useEffect)((()=>(h(),()=>{h()})),[]),(0,i.jsxs)("form",{children:[(0,i.jsxs)("div",{className:"tinyorm-configuration-row",children:[(0,i.jsx)("label",{htmlFor:"tinyorm-toggle-full",children:"Full configuration"}),(0,i.jsx)("input",{id:"tinyorm-toggle-full",type:"checkbox",checked:e,onChange:()=>n(u),title:"Show full configuration example"})]}),(0,i.jsxs)("div",{className:"tinyorm-configuration-row",children:[(0,i.jsx)("label",{htmlFor:"tinyorm-toggle-prefix",children:"Prefix environment"}),(0,i.jsx)("input",{id:"tinyorm-toggle-prefix",type:"checkbox",checked:t,onChange:()=>r(j),title:"Prefix all environment variables by the database type"})]})]})}function h(){l=null,c=null}function u(e){const n=l||(l=document.getElementById("tinyorm-configuration")?.querySelectorAll(".tabs-container")),t=!e;if(!n)return e;if(2!==n.length)throw new Error(`Wrong number of .tabs-container (!== 2) found in the toggle configuration feature, found ${n.length}.`);return t?(n[0].style.display="none",n[1].style.display="block"):(n[0].style.display="block",n[1].style.display="none"),!e}const p='"DB_',m="MARIA",g="MYSQL",x="PGSQL",f="SQLITE",b=[g,x,f,m,g,x,f,m];function j(e){const n=function(){if(c)return c;const e=document.getElementById("tinyorm-configuration")?.querySelectorAll(".prism-code > code");if(!e)return e;if(8!==e.length)throw new Error(`Wrong number of .prism-code > code (!== 8) found in the prefix env. feature, found ${e.length}.`);return c=new Array(e.length),e.forEach(((e,n)=>{c[n]=Array.from(e.querySelectorAll(".token.string")).filter((e=>e?.textContent.startsWith(p)))})),c}(),t=!e;return n?(n.forEach(((e,n)=>{e.forEach((e=>{const i=e.textContent,r=`${p}${b[n]}_`;if(t)e.textContent=`${r}${i.substring(4)}`;else{if(!i.startsWith(r))throw new Error(`Token doesn't start with the '${r}' prefix.`);e.textContent=`${p}${i.substring(r.length)}`}}))})),!e):e}var S=t(7324);const y={sidebar_position:0,sidebar_label:"Getting Started",description:"TinyORM makes interacting with a database extremely simple using raw SQL, a fluent query builder, and the TinyORM. It provides first-party support for four databases MySQL/MariaDB, PostgreSQL, and SQLite.",keywords:["c++ orm","database","getting started","tinyorm"]},v="Database: Getting Started",_={id:"database/getting-started",title:"Database: Getting Started",description:"TinyORM makes interacting with a database extremely simple using raw SQL, a fluent query builder, and the TinyORM. It provides first-party support for four databases MySQL/MariaDB, PostgreSQL, and SQLite.",source:"@site/docs/database/getting-started.mdx",sourceDirName:"database",slug:"/database/getting-started",permalink:"/database/getting-started",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"Getting Started",description:"TinyORM makes interacting with a database extremely simple using raw SQL, a fluent query builder, and the TinyORM. It provides first-party support for four databases MySQL/MariaDB, PostgreSQL, and SQLite.",keywords:["c++ orm","database","getting started","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"\ud83d\ude80 Supported Compilers",permalink:"/supported-compilers"},next:{title:"Query Builder",permalink:"/database/query-builder"}},Q={},T=[{value:"Introduction",id:"introduction",level:2},{value:"Configuration",id:"configuration",level:3},{value:"SQLite Configuration",id:"sqlite-configuration",level:4},{value:"SSL Connections",id:"ssl-connections",level:3},{value:"MySQL",id:"mysql",level:5},{value:"PostgreSQL",id:"postgresql",level:5},{value:"Running SQL Queries",id:"running-sql-queries",level:2},{value:"Running A Select Query",id:"running-a-select-query",level:4},{value:"Selecting Scalar Values",id:"selecting-scalar-values",level:4},{value:"Running An Insert Statement",id:"running-an-insert-statement",level:4},{value:"Running An Update Statement",id:"running-an-update-statement",level:4},{value:"Running A Delete Statement",id:"running-a-delete-statement",level:4},{value:"Running A General Statement",id:"running-a-general-statement",level:4},{value:"Running An Unprepared Statement",id:"running-an-unprepared-statement",level:4},{value:"Implicit Commits",id:"implicit-commits",level:4},{value:"Using Multiple Database Connections",id:"using-multiple-database-connections",level:3},{value:"Database Transactions",id:"database-transactions",level:2},{value:"Manually Using Transactions",id:"manually-using-transactions",level:4},{value:"Multi-threading support",id:"multi-threading-support",level:2}];function D(e){const n={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h1,{id:"database-getting-started",children:"Database: Getting Started"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#introduction",children:"Introduction"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#configuration",children:"Configuration"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#ssl-connections",children:"SSL Connections"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#running-sql-queries",children:"Running SQL Queries"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#using-multiple-database-connections",children:"Using Multiple Database Connections"})}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#database-transactions",children:"Database Transactions"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#multi-threading-support",children:"Multi-threading support"})}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(n.p,{children:["Almost every modern application interacts with a database. TinyORM makes interacting with a database extremely simple using raw SQL, a ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"fluent query builder"}),", and the ",(0,i.jsx)(n.a,{href:"/tinyorm/getting-started",children:"TinyORM"}),". Currently, TinyORM provides first-party support for four databases:"]}),"\n",(0,i.jsx)("div",{id:"databases-supported-versions",children:(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["MySQL ",(0,i.jsx)(n.code,{children:">=5.7"})," (",(0,i.jsx)(n.a,{href:"https://en.wikipedia.org/wiki/MySQL#Release_history",children:"Version Policy"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["MariaDB ",(0,i.jsx)(n.code,{children:">=10.3"})," (",(0,i.jsx)(n.a,{href:"https://mariadb.org/about/#maintenance-policy",children:"Version Policy"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["PostgreSQL ",(0,i.jsx)(n.code,{children:">=11"})," (",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/support/versioning/",children:"Version Policy"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["SQLite ",(0,i.jsx)(n.code,{children:">=3.8.8"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["native rename column ",(0,i.jsx)(n.code,{children:">=3.25.0"})," (",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/lang_altertable.html#alter_table_rename_column",children:"docs"})," , ",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/releaselog/3_25_0.html",children:"release notes"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["native drop column ",(0,i.jsx)(n.code,{children:">=3.35.0"})," (",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/lang_altertable.html#alter_table_drop_column",children:"docs"}),", ",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/releaselog/3_35_0.html",children:"release notes"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["generated columns ",(0,i.jsx)(n.code,{children:">=3.31.0"})," (",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/gencol.html",children:"docs"}),", ",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/releaselog/3_31_0.html",children:"release notes"}),")"]}),"\n"]}),"\n"]}),"\n"]})}),"\n",(0,i.jsxs)(n.p,{children:["TinyORM internally uses ",(0,i.jsx)(n.code,{children:"QtSql"})," module, you can look for ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/sql-driver.html#supported-databases",children:"supported databases"}),"."]}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsx)(n.p,{children:"TinyORM's code is ready and designed to simply add support for the SQL Server."})}),"\n",(0,i.jsx)(n.h3,{id:"configuration",children:"Configuration"}),"\n",(0,i.jsxs)(n.p,{children:["You can create and configure a new database connection using the ",(0,i.jsx)(n.code,{children:"create"})," method provided by the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsxs)("div",{id:"tinyorm-configuration",children:[(0,i.jsx)(d,{}),(0,i.jsxs)(s.A,{className:"tinyorm-configuration-basic",groupId:S.OO,children:[(0,i.jsx)(a.A,{value:S.Dx,label:S.A3,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_HOST", "127.0.0.1")},\n {"port", qEnvironmentVariable("DB_PORT", "3306")},\n {"database", qEnvironmentVariable("DB_DATABASE", "")},\n {"username", qEnvironmentVariable("DB_USERNAME", "root")},\n {"password", qEnvironmentVariable("DB_PASSWORD", "")},\n {"charset", qEnvironmentVariable("DB_CHARSET", "utf8mb4")},\n {"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_0900_ai_ci")},\n {"timezone", "+00:00"},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {"qt_timezone", QVariant::fromValue(Qt::UTC)},\n {"prefix", ""},\n {"prefix_indexes", false},\n {"strict", true},\n {"engine", "InnoDB"},\n {"options", QVariantHash()},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.os,label:S.LQ,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_HOST", "127.0.0.1")},\n {"port", qEnvironmentVariable("DB_PORT", "5432")},\n {"database", qEnvironmentVariable("DB_DATABASE", "")},\n {"search_path", qEnvironmentVariable("DB_SEARCHPATH", "public")},\n {"username", qEnvironmentVariable("DB_USERNAME", "postgres")},\n {"password", qEnvironmentVariable("DB_PASSWORD", "")},\n {"charset", qEnvironmentVariable("DB_CHARSET", "utf8")},\n {"timezone", "UTC"},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {"qt_timezone", QVariant::fromValue(Qt::UTC)},\n {"prefix", ""},\n {"prefix_indexes", false},\n {"options", QVariantHash()},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.F4,label:S.Q7,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QSQLITE"},\n {"database", qEnvironmentVariable("DB_DATABASE", "/example/example.sqlite3")},\n {"foreign_key_constraints", qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},\n {"check_database_exists", true},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {"qt_timezone", QVariant::fromValue(Qt::UTC)},\n /* Return a QDateTime/QDate with the correct time zone instead of the QString,\n only works when the qt_timezone isn\'t set to the DontConvert. */\n {"return_qdatetime", true},\n {"prefix", ""},\n {"prefix_indexes", false},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.Fi,label:S.CW,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_HOST", "127.0.0.1")},\n {"port", qEnvironmentVariable("DB_PORT", "3306")},\n {"database", qEnvironmentVariable("DB_DATABASE", "")},\n {"username", qEnvironmentVariable("DB_USERNAME", "root")},\n {"password", qEnvironmentVariable("DB_PASSWORD", "")},\n {"charset", qEnvironmentVariable("DB_CHARSET", "utf8mb4")},\n {"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_unicode_520_ci")},\n {"timezone", "+00:00"},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {"qt_timezone", QVariant::fromValue(Qt::UTC)},\n {"prefix", ""},\n {"prefix_indexes", false},\n {"strict", true},\n {"engine", "InnoDB"},\n {"options", QVariantHash()},\n});\n'})})})]}),(0,i.jsxs)(s.A,{className:"tinyorm-configuration-full",groupId:S.OO,children:[(0,i.jsx)(a.A,{value:S.Dx,label:S.A3,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\nusing namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {driver_, QMYSQL},\n {host_, qEnvironmentVariable("DB_HOST", H127001)},\n {port_, qEnvironmentVariable("DB_PORT", P3306)},\n {database_, qEnvironmentVariable("DB_DATABASE", EMPTY)},\n {username_, qEnvironmentVariable("DB_USERNAME", ROOT)},\n {password_, qEnvironmentVariable("DB_PASSWORD", EMPTY)},\n {charset_, qEnvironmentVariable("DB_CHARSET", UTF8MB4)},\n {collation_, qEnvironmentVariable("DB_COLLATION", UTF8MB40900aici)},\n // SSL-related\n {ssl_ca, QStringLiteral("C:/mysql/data/ca.pem")},\n {ssl_cert, QStringLiteral("C:/mysql/data/client-cert.pem")},\n {ssl_key, QStringLiteral("C:/mysql/data/client-key.pem")},\n {ssl_mode, VerifyCA},\n // Or\n// {options, ConfigUtils::mysqlSslOptions()},\n {timezone_, TZ00},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {qt_timezone, QVariant::fromValue(Qt::UTC)},\n {prefix_, EMPTY},\n {prefix_indexes, false},\n {strict_, true},\n// {isolation_level, QStringLiteral("REPEATABLE READ")}, // MySQL default is REPEATABLE READ for InnoDB\n {engine_, InnoDB},\n {Version, {}}, // Autodetect\n {options_, QVariantHash()},\n // Examples\n// {options_, QStringLiteral("MYSQL_OPT_CONNECT_TIMEOUT = 1 ; MYSQL_OPT_READ_TIMEOUT=1")},\n// {options_, QVariantHash {{QStringLiteral("MYSQL_OPT_CONNECT_TIMEOUT"), 1},\n// {QStringLiteral("MYSQL_OPT_READ_TIMEOUT"), 1}}},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.os,label:S.LQ,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\nusing namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {driver_, QPSQL},\n {application_name, QStringLiteral("Example application")},\n {host_, qEnvironmentVariable("DB_HOST", H127001)},\n {port_, qEnvironmentVariable("DB_PORT", P5432)},\n {database_, qEnvironmentVariable("DB_DATABASE", EMPTY)},\n {search_path, qEnvironmentVariable("DB_SEARCHPATH", PUBLIC)},\n {username_, qEnvironmentVariable("DB_USERNAME", postgres_)},\n {password_, qEnvironmentVariable("DB_PASSWORD", EMPTY)},\n {charset_, qEnvironmentVariable("DB_CHARSET", UTF8)},\n // SSL-related\n {sslmode_, QStringLiteral("verify-full")},\n {sslcert, QStringLiteral("C:/example/postgres.crt")},\n {sslkey, QStringLiteral("C:/example/postgres.key")},\n {sslrootcert, QStringLiteral("C:/example/root.crt")},\n // Or\n// {options_, ConfigUtils::postgresSslOptions()},\n {timezone_, UTC},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {qt_timezone, QVariant::fromValue(Qt::UTC)},\n {prefix_, EMPTY},\n {prefix_indexes, false},\n// {isolation_level, QStringLiteral("REPEATABLE READ")}, // Postgres default is READ COMMITTED\n// {synchronous_commit, QStringLiteral("off")}, // Postgres default is on\n // ConnectionFactory provides a default value for this, this is only for reference\n// {dont_drop, QStringList {spatial_ref_sys}},\n {options_, QVariantHash()},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.F4,label:S.Q7,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\nusing namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {driver_, QSQLITE},\n {database_, qEnvironmentVariable("DB_DATABASE", "C:/SQLite/example.sqlite3")},\n {foreign_key_constraints, qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},\n {check_database_exists, true},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {qt_timezone, QVariant::fromValue(Qt::UTC)},\n /* Return a QDateTime/QDate with the correct time zone instead of the QString,\n only works when the qt_timezone isn\'t set to the DontConvert. */\n {return_qdatetime, true},\n {prefix_, EMPTY},\n {prefix_indexes, false},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.Fi,label:S.CW,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\nusing namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {driver_, QMYSQL},\n {host_, qEnvironmentVariable("DB_HOST", H127001)},\n {port_, qEnvironmentVariable("DB_PORT", P3306)},\n {database_, qEnvironmentVariable("DB_DATABASE", EMPTY)},\n {username_, qEnvironmentVariable("DB_USERNAME", ROOT)},\n {password_, qEnvironmentVariable("DB_PASSWORD", EMPTY)},\n {charset_, qEnvironmentVariable("DB_CHARSET", UTF8MB4)},\n {collation_, qEnvironmentVariable("DB_COLLATION", UTF8MB4Unicode520ci)},\n // SSL-related\n {ssl_ca, QStringLiteral("C:/maria/data/ca.pem")},\n {ssl_cert, QStringLiteral("C:/maria/data/client-cert.pem")},\n {ssl_key, QStringLiteral("C:/maria/data/client-key.pem")},\n // Or\n// {options, ConfigUtils::mariaSslOptions()},\n {timezone_, TZ00},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {qt_timezone, QVariant::fromValue(Qt::UTC)},\n {prefix_, EMPTY},\n {prefix_indexes, false},\n {strict_, true},\n// {isolation_level, QStringLiteral("REPEATABLE READ")}, // MariaDB default is REPEATABLE READ for InnoDB\n {engine_, InnoDB},\n {Version, {}}, // Autodetect\n {options_, QVariantHash()},\n // Examples\n// {options_, QStringLiteral("MYSQL_OPT_CONNECT_TIMEOUT = 1 ; MYSQL_OPT_READ_TIMEOUT=1")},\n// {options_, QVariantHash {{QStringLiteral("MYSQL_OPT_CONNECT_TIMEOUT"), 1},\n// {QStringLiteral("MYSQL_OPT_READ_TIMEOUT"), 1}}},\n});\n'})})})]})]}),"\n",(0,i.jsxs)(n.p,{children:["The first argument is configuration hash which is of type ",(0,i.jsx)(n.code,{children:"QVariantHash"})," and the second argument specifies the name of the ",(0,i.jsx)(n.em,{children:"connection"}),", this connection will also be a ",(0,i.jsx)(n.em,{children:"default connection"}),". You can configure multiple database connections at once and choose the needed one before executing SQL query, section ",(0,i.jsx)(n.a,{href:"#using-multiple-database-connections",children:"Using Multiple Database Connections"})," describes how to create and use multiple database connections."]}),"\n",(0,i.jsxs)(n.p,{children:["You may also configure connection options by ",(0,i.jsx)(n.code,{children:"options"})," key as ",(0,i.jsx)(n.code,{children:"QVariantHash"})," or ",(0,i.jsx)(n.code,{children:"QString"}),", you can pass any ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/qsqldatabase.html#setConnectOptions",children:"connection options"})," supported by ",(0,i.jsx)(n.code,{children:"QSqlDatabase"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also configure ",(0,i.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.3/en/innodb-transaction-isolation-levels.html",children:"Transaction Isolation Levels"})," for MySQL connection with the ",(0,i.jsx)(n.code,{children:"isolation_level"})," configuration option."]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"version"})," option is relevant only for the MySQL connections and you can save/avoid one database query (select version()) if you provide it manually. On the base of this version will be decided which ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/src/orm/connectors/mysqlconnector.cpp#L154",children:"session variables"})," will be set if strict mode is enabled and whether to use an ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/src/orm/query/grammars/mysqlgrammar.cpp#L36",children:"alias"})," during the ",(0,i.jsx)(n.code,{children:"upsert"})," method call."]}),"\n",(0,i.jsxs)(n.p,{children:["Breaking values are as follows; use an upsert alias on the MySQL >=8.0.19 and remove the ",(0,i.jsx)(n.code,{children:"NO_AUTO_CREATE_USER"})," sql mode on the MySQL >=8.0.11 if the strict mode is enabled."]}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["A database connection is resolved lazily, which means that the connection configuration is only saved after the ",(0,i.jsx)(n.code,{children:"DB::create"})," method call. The connection will be resolved after you run some query or you can create it using the ",(0,i.jsx)(n.code,{children:"DB::connection"})," method."]})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["You can also use predefined string constants to avoid unnecessary ",(0,i.jsx)(n.code,{children:"QString"})," instantiations, as used in the ",(0,i.jsx)(n.code,{children:"tom"})," migrations ",(0,i.jsx)(n.a,{href:"/building/migrations#string-constants-example",children:"example"}),"."]})}),"\n",(0,i.jsx)(n.h4,{id:"sqlite-configuration",children:"SQLite Configuration"}),"\n",(0,i.jsxs)(n.p,{children:["SQLite databases are contained within a single file on your filesystem. You can create a new SQLite database using the ",(0,i.jsx)(n.code,{children:"touch"})," command in your terminal: ",(0,i.jsx)(n.code,{children:"touch database.sqlite3"}),". After the database has been created, you may configure SQLite database connection:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QSQLITE"},\n {"database", qEnvironmentVariable("DB_DATABASE", "/absolute/path/to/database.sqlite3")},\n {"foreign_key_constraints", qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},\n {"check_database_exists", true},\n {"prefix", ""},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"database"})," configuration value is the absolute path to the database. To enable foreign key constraints for SQLite connections, you should set the ",(0,i.jsx)(n.code,{children:"foreign_key_constraints"})," configuration value to ",(0,i.jsx)(n.code,{children:"true"}),", if this configuration value is not set, then the default of the SQLite driver will be used (currently the default is ",(0,i.jsx)(n.strong,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.p,{children:["If the ",(0,i.jsx)(n.code,{children:"check_database_exists"})," configuration value is set to the ",(0,i.jsx)(n.code,{children:"true"})," value, then the database connection throws an ",(0,i.jsx)(n.code,{children:"Orm::InvalidArgumentError"})," exception, when the SQLite database file doesn't exist. If it is set to the ",(0,i.jsx)(n.code,{children:"false"})," value and the SQLite database file doesn't exist, then it will be created for you by SQLite driver. The default value is ",(0,i.jsx)(n.code,{children:"true"}),"."]}),"\n",(0,i.jsx)(n.h3,{id:"ssl-connections",children:"SSL Connections"}),"\n",(0,i.jsxs)(n.p,{children:["SSL connections are supported for the ",(0,i.jsx)(n.code,{children:"MySQL"})," and ",(0,i.jsx)(n.code,{children:"PostgreSQL"})," databases. They can be set using the ",(0,i.jsx)(n.code,{children:"options"})," configuration option."]}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["This feature is heavily dependent on the underlying ",(0,i.jsx)(n.code,{children:"QSqlDatabase"})," module. What means that you can pass the same ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/qsqldatabase.html#setConnectOptions",children:"connection options"})," to the ",(0,i.jsx)(n.code,{children:"TinyORM"})," that the ",(0,i.jsx)(n.code,{children:"QSqlDatabase"})," accepts."]})}),"\n",(0,i.jsx)(n.h5,{id:"mysql",children:"MySQL"}),"\n",(0,i.jsxs)(n.p,{children:["You have to pass the ",(0,i.jsx)(n.code,{children:"SSL_CA"}),", ",(0,i.jsx)(n.code,{children:"SSL_CERT"}),", ",(0,i.jsx)(n.code,{children:"SSL_KEY"}),", and ",(0,i.jsx)(n.code,{children:"MYSQL_OPT_SSL_MODE"})," options."]}),"\n",(0,i.jsxs)(s.A,{groupId:S.vf,children:[(0,i.jsx)(a.A,{value:S.b,label:S.ux,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"options", QVariantHash({{"SSL_CA", "C:/mysql/data/ca.pem"},\n {"SSL_CERT", "C:/mysql/data/client-cert.pem"},\n {"SSL_KEY", "C:/mysql/data/client-key.pem"},\n {"MYSQL_OPT_SSL_MODE", "VERIFY_CA"}})},\n // highlight-end\n});\n'})})}),(0,i.jsx)(a.A,{value:S.xj,label:S.gg,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"options", QVariantHash({{"SSL_CA", "~/.local/share/TinyORM/ssl/ca.pem"},\n {"SSL_CERT", "~/.local/share/TinyORM/ssl/client-cert.pem"},\n {"SSL_KEY", "~/.local/share/TinyORM/ssl/client-key.pem"},\n {"MYSQL_OPT_SSL_MODE", "VERIFY_CA"}})},\n // highlight-end\n});\n'})})})]}),"\n",(0,i.jsxs)(n.p,{children:["You may also use the ",(0,i.jsx)(n.code,{children:"ConfigUtils::mysqlSslOptions()"})," or the ",(0,i.jsx)(n.code,{children:"ConfigUtils::insertMySqlSslOptions()"})," methods to insert these options for you and define them using the ",(0,i.jsx)(n.code,{children:"DB_MYSQL_SSL_CA"}),", ",(0,i.jsx)(n.code,{children:"DB_MYSQL_SSL_CERT"}),", ",(0,i.jsx)(n.code,{children:"DB_MYSQL_SSL_KEY"}),", and ",(0,i.jsx)(n.code,{children:"DB_MYSQL_SSL_MODE"})," environment variables."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", ConfigUtils::mysqlSslOptions()},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["You can define these SSL-related options in the top-level configuration, they will be copied to the ",(0,i.jsx)(n.code,{children:"options"})," option hash during configuration parsing. The top-level configuration takes precedence and overwrites the options in the ",(0,i.jsx)(n.code,{children:"options"})," hash."]}),"\n",(0,i.jsxs)(s.A,{groupId:S.vf,children:[(0,i.jsx)(a.A,{value:S.b,label:S.ux,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"SSL_CA", "C:/mysql/data/ca.pem"},\n {"SSL_CERT", "C:/mysql/data/client-cert.pem"},\n {"SSL_KEY", "C:/mysql/data/client-key.pem"},\n {"MYSQL_OPT_SSL_MODE", "VERIFY_CA"},\n // highlight-end\n});\n'})})}),(0,i.jsx)(a.A,{value:S.xj,label:S.gg,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"SSL_CA", "~/.local/share/TinyORM/ssl/ca.pem"},\n {"SSL_CERT", "~/.local/share/TinyORM/ssl/client-cert.pem"},\n {"SSL_KEY", "~/.local/share/TinyORM/ssl/client-key.pem"},\n {"MYSQL_OPT_SSL_MODE", "VERIFY_CA"},\n // highlight-end\n});\n'})})})]}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["You can take a look at the GitHub actions how the ",(0,i.jsx)(n.code,{children:"MySQL"})," certificates are generated in the CI pipeline for ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/msvc2022-qt6.yml",children:"Windows"})," and ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/linux-qt6.yml",children:"Linux"}),"."]})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["You can also pass the ",(0,i.jsx)(n.code,{children:"QString"})," to the ",(0,i.jsx)(n.code,{children:"options"})," configuration separated by the ",(0,i.jsx)(n.code,{children:";"})," semicolon character and use the ",(0,i.jsx)(n.code,{children:"="})," to assign values."]})}),"\n",(0,i.jsx)(n.h5,{id:"postgresql",children:"PostgreSQL"}),"\n",(0,i.jsxs)(n.p,{children:["You have to pass the ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS",children:(0,i.jsx)(n.code,{children:"sslmode"})})," or the deprecated ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-REQUIRESSL",children:(0,i.jsx)(n.code,{children:"requiressl"})})," options."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", QVariantHash({{"sslmode", "verify-full"}})},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["And place your ",(0,i.jsx)(n.strong,{children:"client"})," certificates to the ",(0,i.jsx)(n.code,{children:"~/.postgres/"})," on ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-FILE-USAGE",children:"Linux"})," and ",(0,i.jsx)(n.code,{children:"$env:APPDATA/postgres/"})," on Windows. Everything is described in the PostgreSQL's ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-ssl.html",children:"libpq client"})," and ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/15/ssl-tcp.html#SSL-FILE-USAGE",children:"server"})," documentation."]}),"\n",(0,i.jsxs)(n.p,{children:["If you want to keep your ",(0,i.jsx)(n.strong,{children:"client"})," certificates in your own location, you can set the ",(0,i.jsx)(n.code,{children:"sslcert"}),", ",(0,i.jsx)(n.code,{children:"sslkey"}),", and ",(0,i.jsx)(n.code,{children:"sslrootcert"})," options."]}),"\n",(0,i.jsxs)(s.A,{groupId:S.vf,children:[(0,i.jsx)(a.A,{value:S.b,label:S.ux,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", QVariantHash({{"sslmode", "verify-full"},\n // highlight-start\n {"sslcert", "C:/example/postgres.crt"},\n {"sslkey", "C:/example/postgres.key"},\n {"sslrootcert", "C:/example/root.crt"}})},\n // highlight-end\n});\n'})})}),(0,i.jsx)(a.A,{value:S.xj,label:S.gg,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", QVariantHash({{"sslmode", "verify-full"},\n // highlight-start\n {"sslcert", "/example/postgres.crt"},\n {"sslkey", "/example/postgres.key"},\n {"sslrootcert", "/example/root.crt"}})},\n // highlight-end\n});\n'})})})]}),"\n",(0,i.jsxs)(n.p,{children:["You can define these SSL-related options in the top-level configuration, they will be copied to the ",(0,i.jsx)(n.code,{children:"options"})," option hash during a configuration parsing. The top-level configuration takes precedence and overwrites the options in the ",(0,i.jsx)(n.code,{children:"options"})," hash."]}),"\n",(0,i.jsxs)(s.A,{groupId:S.vf,children:[(0,i.jsx)(a.A,{value:S.b,label:S.ux,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"sslmode", "verify-full"},\n {"sslcert", "C:/example/postgres.crt"},\n {"sslkey", "C:/example/postgres.key"},\n {"sslrootcert", "C:/example/root.crt"},\n // highlight-end\n});\n'})})}),(0,i.jsx)(a.A,{value:S.xj,label:S.gg,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"sslmode", "verify-full"},\n {"sslcert", "/example/postgres.crt"},\n {"sslkey", "/example/postgres.key"},\n {"sslrootcert", "/example/root.crt"},\n // highlight-end\n});\n'})})})]}),"\n",(0,i.jsxs)(n.p,{children:["You may also use the ",(0,i.jsx)(n.code,{children:"ConfigUtils::postgresSslOptions()"})," or the ",(0,i.jsx)(n.code,{children:"ConfigUtils::insertPostgresSslOptions()"})," methods to insert the ",(0,i.jsx)(n.code,{children:"sslmode"}),", ",(0,i.jsx)(n.code,{children:"sslcert"}),", ",(0,i.jsx)(n.code,{children:"sslkey"}),", and ",(0,i.jsx)(n.code,{children:"sslrootcert"})," options for you and define them using the ",(0,i.jsx)(n.code,{children:"DB_PGSQL_SSLMODE"}),", ",(0,i.jsx)(n.code,{children:"DB_PGSQL_SSLCERT"}),", ",(0,i.jsx)(n.code,{children:"DB_PGSQL_SSLKEY"}),", and ",(0,i.jsx)(n.code,{children:"DB_PGSQL_SSLROOTCERT"})," environment variable."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", ConfigUtils::postgresSslOptions()},\n});\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["The PostgreSQL's libpq client library provides the ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.13.1.1",children:(0,i.jsx)(n.code,{children:"PGSSLMODE"})}),", ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.16.1.1",children:(0,i.jsx)(n.code,{children:"PGSSLCERT"})}),", ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.17.1.1",children:(0,i.jsx)(n.code,{children:"PGSSLKEY"})}),", and ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.18.1.1",children:(0,i.jsx)(n.code,{children:"PGSSLROOTCERT"})})," environment variables, so you don't have to use TinyORM's ",(0,i.jsx)(n.code,{children:"options"})," configuration and may use these environment variables instead."]})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["You can take a look at the GitHub actions how the ",(0,i.jsx)(n.code,{children:"PostgreSQL"})," certificates are generated in the CI pipeline for ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/msvc2022-qt6.yml",children:"Windows"})," and ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/linux-qt6.yml",children:"Linux"}),"."]})}),"\n",(0,i.jsx)(n.h2,{id:"running-sql-queries",children:"Running SQL Queries"}),"\n",(0,i.jsxs)(n.p,{children:["Once you have configured your database connection, you may run queries using the ",(0,i.jsx)(n.code,{children:"DB"})," facade. The ",(0,i.jsx)(n.code,{children:"DB"})," facade provides methods for each type of query: ",(0,i.jsx)(n.code,{children:"select"}),", ",(0,i.jsx)(n.code,{children:"update"}),", ",(0,i.jsx)(n.code,{children:"insert"}),", ",(0,i.jsx)(n.code,{children:"delete"}),", and ",(0,i.jsx)(n.code,{children:"statement"}),"."]}),"\n",(0,i.jsx)(n.h4,{id:"running-a-select-query",children:"Running A Select Query"}),"\n",(0,i.jsxs)(n.p,{children:["To run a basic SELECT query, you may use the ",(0,i.jsx)(n.code,{children:"select"})," method on the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsxs)(n.p,{children:['auto users = DB::select("select * from users where active = ?", ',1,");"]}),"\n",(0,i.jsxs)(n.p,{children:["The first argument passed to the ",(0,i.jsx)(n.code,{children:"select"})," method is the SQL query, while the second argument is any parameter bindings that need to be bound to the query. Typically, these are the values of the ",(0,i.jsx)(n.code,{children:"where"})," clause constraints. Parameter binding provides protection against SQL injection."]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"select"})," method returns a ",(0,i.jsx)(n.code,{children:"QSqlQuery"})," containing the results of the query, where each result can be accessed by ",(0,i.jsx)(n.code,{children:"QSqlQuery::next"})," method. Look into the ",(0,i.jsx)(n.code,{children:"QSqlQuery"}),' documentation on how to obtain results from the "query". You may access each column\'s value by ',(0,i.jsx)(n.code,{children:"QSqlQuery::value"})," method. The first ",(0,i.jsx)(n.code,{children:"bool"})," return value is the value returned from ",(0,i.jsx)(n.code,{children:"QSqlQuery::exec"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include \n\nauto users = DB::select("select * from users");\n\nwhile(users.next())\n qDebug() << users.value("name").toString();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"selecting-scalar-values",children:"Selecting Scalar Values"}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes your database query may result in a single, scalar value. Instead of being required to retrieve the query's scalar result from a record instance, TinyORM allows you to retrieve this value directly using the ",(0,i.jsx)(n.code,{children:"scalar"})," shortcut method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto states = DB::scalar(\n "select count(case when state = \'pending\' then 1 end) as states "\n "from comments"\n);\n\n// With binding\nauto states = DB::scalar(\n "select count(case when state = ? then 1 end) as states from comments",\n {"pending"}\n);\n'})}),"\n",(0,i.jsx)(n.h4,{id:"running-an-insert-statement",children:"Running An Insert Statement"}),"\n",(0,i.jsxs)(n.p,{children:["To execute an ",(0,i.jsx)(n.code,{children:"insert"})," statement, you may use the ",(0,i.jsx)(n.code,{children:"insert"})," method on the ",(0,i.jsx)(n.code,{children:"DB"})," facade. Like ",(0,i.jsx)(n.code,{children:"select"}),", this method accepts the SQL query as its first argument and bindings as its second argument and returns ",(0,i.jsx)(n.code,{children:"QSqlQuery"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nDB::insert("insert into users (id, name) values (?, ?)", {1, "Marc"});\n'})}),"\n",(0,i.jsx)(n.h4,{id:"running-an-update-statement",children:"Running An Update Statement"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"update"})," method should be used to update existing records in the database. The number of rows affected by the statement and ",(0,i.jsx)(n.code,{children:"QSqlQuery"})," is returned by the method as ",(0,i.jsx)(n.code,{children:"std::tuple"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include \n\nauto [affected, query] = DB::update(\n "update users set updated_at = ? where name = ?",\n {QDateTime::currentDateTimeUtc(), "Anita"}\n);\n\nif (!affected)\n qDebug() << "Any record was updated.";\n'})}),"\n",(0,i.jsx)(n.h4,{id:"running-a-delete-statement",children:"Running A Delete Statement"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"remove"})," method should be used to delete records from the database. Like ",(0,i.jsx)(n.code,{children:"update"}),", the number of affected rows and ",(0,i.jsx)(n.code,{children:"QSqlQuery"})," will be returned by the method as ",(0,i.jsx)(n.code,{children:"std::tuple"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto [affected, query] = DB::remove("delete from users");\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"delete"})," can not be used as the method name because it is the reserved word."]})}),"\n",(0,i.jsx)(n.h4,{id:"running-a-general-statement",children:"Running A General Statement"}),"\n",(0,i.jsxs)(n.p,{children:["Some database statements do not return any value. For these types of operations, you may use the ",(0,i.jsx)(n.code,{children:"statement"})," method on the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'DB::statement("drop table users");\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"DB::statement"})," method should be used for ",(0,i.jsx)(n.a,{href:"https://en.wikipedia.org/wiki/Data_definition_language",children:"DDL"}),' queries, don\'t use it for "select" queries because it internally calls ',(0,i.jsx)(n.code,{children:"recordsHaveBeenModified"})," method."]})}),"\n",(0,i.jsx)(n.h4,{id:"running-an-unprepared-statement",children:"Running An Unprepared Statement"}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes you may want to execute an SQL statement without binding any values. You may use the ",(0,i.jsx)(n.code,{children:"DB"})," facade's ",(0,i.jsx)(n.code,{children:"unprepared"})," method to accomplish this:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"DB::unprepared(\"update users set votes = 100 where name = 'Dries'\");\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"warning",children:(0,i.jsx)(n.p,{children:"Since unprepared statements do not bind parameters, they may be vulnerable to SQL injection. You should never allow user controlled values within an unprepared statement."})}),"\n",(0,i.jsx)(n.h4,{id:"implicit-commits",children:"Implicit Commits"}),"\n",(0,i.jsxs)(n.p,{children:["When using the ",(0,i.jsx)(n.code,{children:"DB"})," facade's ",(0,i.jsx)(n.code,{children:"statement"})," methods within transactions, you must be careful to avoid statements that cause ",(0,i.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.3/en/implicit-commit.html",children:"implicit commits"}),". These statements will cause the database engine to indirectly commit the entire transaction, leaving TinyORM unaware of the database's transaction level. An example of such a statement is creating a database table:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'DB::statement("create table users (name varchar(255) null)");\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Please refer to the MySQL manual for ",(0,i.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.3/en/implicit-commit.html",children:"a list of all statements"})," that trigger implicit commits."]}),"\n",(0,i.jsx)(n.h3,{id:"using-multiple-database-connections",children:"Using Multiple Database Connections"}),"\n",(0,i.jsxs)(n.p,{children:["You can configure multiple database connections at once during ",(0,i.jsx)(n.code,{children:"DatabaseManager"})," instantiation using the ",(0,i.jsx)(n.code,{children:"DB::create"})," overload, where the first argument is a hash of multiple connections and is of type ",(0,i.jsx)(n.code,{children:"QHash"})," and the second argument is the name of the default connection:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"mysql", {\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n {"port", qEnvironmentVariable("DB_MYSQL_PORT", "3306")},\n {"database", qEnvironmentVariable("DB_MYSQL_DATABASE", "")},\n {"username", qEnvironmentVariable("DB_MYSQL_USERNAME", "root")},\n {"password", qEnvironmentVariable("DB_MYSQL_PASSWORD", "")},\n {"charset", qEnvironmentVariable("DB_MYSQL_CHARSET", "utf8mb4")},\n {"collation", qEnvironmentVariable("DB_MYSQL_COLLATION", "utf8mb4_0900_ai_ci")},\n {"strict", true},\n {"options", QVariantHash()},\n }},\n {"sqlite", {\n {"driver", "QSQLITE"},\n {"database", qEnvironmentVariable("DB_SQLITE_DATABASE", "")},\n {"foreign_key_constraints", qEnvironmentVariable("DB_SQLITE_FOREIGN_KEYS", "true")},\n {"check_database_exists", true},\n {"prefix", ""},\n }},\n}, "mysql");\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If your application needs to use multiple connections, you may access each connection via the ",(0,i.jsx)(n.code,{children:"connection"})," method provided by the ",(0,i.jsx)(n.code,{children:"DB"})," facade. The connection name passed to the ",(0,i.jsx)(n.code,{children:"connection"})," method should correspond to one of the connections key listed in your configuration:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto query = DB::connection("mysql_test").select(...);\n'})}),"\n",(0,i.jsxs)(n.p,{children:["You may access the raw underlying ",(0,i.jsx)(n.code,{children:"QSqlQuery"})," instance of a connection using the ",(0,i.jsx)(n.code,{children:"getQtQuery"})," method on a connection instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"auto query = DB::connection().getQtQuery();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Or you can use the shortcut method ",(0,i.jsx)(n.code,{children:"qtQuery"})," provided by the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"auto query = DB::qtQuery();\n"})}),"\n",(0,i.jsx)(n.h2,{id:"database-transactions",children:"Database Transactions"}),"\n",(0,i.jsx)(n.h4,{id:"manually-using-transactions",children:"Manually Using Transactions"}),"\n",(0,i.jsxs)(n.p,{children:["If you would like to begin a transaction manually and have complete control over rollbacks and commits, you may use the ",(0,i.jsx)(n.code,{children:"beginTransaction"})," method provided by the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#include \n\nDB::beginTransaction();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["You can rollback the transaction via the ",(0,i.jsx)(n.code,{children:"rollBack"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"DB::rollBack();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Lastly, you can commit a transaction via the ",(0,i.jsx)(n.code,{children:"commit"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"DB::commit();\n"})}),"\n",(0,i.jsx)(n.p,{children:"All transaction methods accept a connection name as the optional argument:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'DB::beginTransaction("mysql_test");\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"DB"})," facade's transaction methods control the transactions for both the ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"})," and ",(0,i.jsx)(n.a,{href:"/tinyorm/getting-started",children:"TinyORM"}),"."]})}),"\n",(0,i.jsx)(n.h2,{id:"multi-threading-support",children:"Multi-threading support"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"TinyORM"})," supports multi-threading for the ",(0,i.jsx)(n.code,{children:"MSVC"})," and ",(0,i.jsx)(n.code,{children:"GCC"})," on Linux compilers. Multi-threading is disabled for the ",(0,i.jsx)(n.code,{children:"Clang <14.0.3"})," compiler on MSYS2, ",(0,i.jsx)(n.code,{children:"Clang <14.0.4"})," on Linux and for the ",(0,i.jsx)(n.code,{children:"GCC"})," compiler on MSYS2. The reason are bugs in the ",(0,i.jsx)(n.code,{children:"TLS"})," wrapper that is generated by the ",(0,i.jsx)(n.a,{href:"https://en.cppreference.com/w/cpp/keyword/thread_local",children:(0,i.jsx)(n.code,{children:"thread_local"})})," keyword."]}),"\n",(0,i.jsx)(n.p,{children:"A connection can only be used from within the thread that created it. Moving connections between threads or creating queries from a different thread where the connection was created is not supported."}),"\n",(0,i.jsxs)(n.p,{children:["In addition, the third party libraries used by the ",(0,i.jsx)(n.code,{children:"QSqlDrivers"})," can impose further restrictions on using the SQL Module in a multithreaded program."]}),"\n",(0,i.jsxs)(n.p,{children:["In short, if you create a ",(0,i.jsx)(n.code,{children:"DB::connection"})," in some thread then you have to use this connection only from this particular thread and of course all queries that will be executed on this connection."]}),"\n",(0,i.jsx)(n.p,{children:"If you want to execute some query from another thread for the same connection then you have to create a new connection first and if you have a new connection you can send a query from this new thread to the database."}),"\n",(0,i.jsx)(n.admonition,{type:"warning",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.a,{href:"/database/migrations#tables",children:(0,i.jsx)(n.code,{children:"schema builder"})})," and ",(0,i.jsx)(n.a,{href:"/database/migrations",children:(0,i.jsx)(n.code,{children:"migrations"})})," don't support multi-threading."]})})]})}function L(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(D,{...e})}):D(e)}},9365:(e,n,t)=>{t.d(n,{A:()=>s});t(6540);var i=t(4164);const r={tabItem:"tabItem_Ymn6"};var a=t(4848);function s(e){let{children:n,hidden:t,className:s}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,i.A)(r.tabItem,s),hidden:t,children:n})}},1470:(e,n,t)=>{t.d(n,{A:()=>v});var i=t(6540),r=t(4164),a=t(3104),s=t(6347),o=t(205),l=t(7485),c=t(1682),d=t(9466);function h(e){return i.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:n,children:t}=e;return(0,i.useMemo)((()=>{const e=n??function(e){return h(e).map((e=>{let{props:{value:n,label:t,attributes:i,default:r}}=e;return{value:n,label:t,attributes:i,default:r}}))}(t);return function(e){const n=(0,c.X)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:t}=e;const r=(0,s.W6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:n,groupId:t});return[(0,l.aZ)(a),(0,i.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})}),[a,r])]}function g(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,a=u(e),[s,l]=(0,i.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const i=t.find((e=>e.default))??t[0];if(!i)throw new Error("Unexpected error: 0 tabValues");return i.value}({defaultValue:n,tabValues:a}))),[c,h]=m({queryString:t,groupId:r}),[g,x]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,a]=(0,d.Dv)(t);return[r,(0,i.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:r}),f=(()=>{const e=c??g;return p({value:e,tabValues:a})?e:null})();(0,o.A)((()=>{f&&l(f)}),[f]);return{selectedValue:s,selectValue:(0,i.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),h(e),x(e)}),[h,x,a]),tabValues:a}}var x=t(2303);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=t(4848);function j(e){let{className:n,block:t,selectedValue:i,selectValue:s,tabValues:o}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),d=e=>{const n=e.currentTarget,t=l.indexOf(n),r=o[t].value;r!==i&&(c(n),s(r))},h=e=>{let n=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;n=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;n=l[t]??l[l.length-1];break}}n?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":t},n),children:o.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:i===n?0:-1,"aria-selected":i===n,ref:e=>l.push(e),onKeyDown:h,onClick:d,...a,className:(0,r.A)("tabs__item",f.tabItem,a?.className,{"tabs__item--active":i===n}),children:t??n},n)}))})}function S(e){let{lazy:n,children:t,selectedValue:r}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===r));return e?(0,i.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,i.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function y(e){const n=g(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,b.jsx)(j,{...n,...e}),(0,b.jsx)(S,{...n,...e})]})}function v(e){const n=(0,x.A)();return(0,b.jsx)(y,{...e,children:h(e.children)},String(n))}},7324:(e,n,t)=>{t.d(n,{$E:()=>x,A3:()=>b,CW:()=>f,Dx:()=>d,F4:()=>u,Fi:()=>c,J_:()=>v,LQ:()=>j,Lf:()=>_,OO:()=>r,Q7:()=>S,b:()=>o,cy:()=>l,gg:()=>m,kl:()=>p,os:()=>h,pW:()=>a,ux:()=>g,vf:()=>i,xj:()=>s,xt:()=>y});const i="shell",r="database",a="application",s="bash",o="pwsh",l="zsh",c="maria",d="mysql",h="postgres",u="sqlite",p="application",m="bash",g="pwsh",x="zsh",f="MariaDB",b="MySQL",j="PostgreSQL",S="SQLite",y="tinyorm.org",v="$HOME/Code/c/",_="$env:USERPROFILE\\Code\\c\\"},8453:(e,n,t)=>{t.d(n,{R:()=>s,x:()=>o});var i=t(6540);const r={},a=i.createContext(r);function s(e){const n=i.useContext(a);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:s(e.components),i.createElement(a.Provider,{value:n},e.children)}}}]);
\ No newline at end of file
+"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[170],{3418:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>Q,contentTitle:()=>v,default:()=>L,frontMatter:()=>y,metadata:()=>_,toc:()=>T});var i=t(4848),r=t(8453),a=t(9365),s=t(1470),o=t(6540);let l=null,c=null;function d(){const[e,n]=(0,o.useState)(!1),[t,r]=(0,o.useState)(!1);return(0,o.useEffect)((()=>(h(),()=>{h()})),[]),(0,i.jsxs)("form",{children:[(0,i.jsxs)("div",{className:"tinyorm-configuration-row",children:[(0,i.jsx)("label",{htmlFor:"tinyorm-toggle-full",children:"Full configuration"}),(0,i.jsx)("input",{id:"tinyorm-toggle-full",type:"checkbox",checked:e,onChange:()=>n(u),title:"Show full configuration example"})]}),(0,i.jsxs)("div",{className:"tinyorm-configuration-row",children:[(0,i.jsx)("label",{htmlFor:"tinyorm-toggle-prefix",children:"Prefix environment"}),(0,i.jsx)("input",{id:"tinyorm-toggle-prefix",type:"checkbox",checked:t,onChange:()=>r(j),title:"Prefix all environment variables by the database type"})]})]})}function h(){l=null,c=null}function u(e){const n=l||(l=document.getElementById("tinyorm-configuration")?.querySelectorAll(".tabs-container")),t=!e;if(!n)return e;if(2!==n.length)throw new Error(`Wrong number of .tabs-container (!== 2) found in the toggle configuration feature, found ${n.length}.`);return t?(n[0].style.display="none",n[1].style.display="block"):(n[0].style.display="block",n[1].style.display="none"),!e}const p='"DB_',m="MARIA",g="MYSQL",x="PGSQL",f="SQLITE",b=[g,x,f,m,g,x,f,m];function j(e){const n=function(){if(c)return c;const e=document.getElementById("tinyorm-configuration")?.querySelectorAll(".prism-code > code");if(!e)return e;if(8!==e.length)throw new Error(`Wrong number of .prism-code > code (!== 8) found in the prefix env. feature, found ${e.length}.`);return c=new Array(e.length),e.forEach(((e,n)=>{c[n]=Array.from(e.querySelectorAll(".token.string")).filter((e=>e?.textContent.startsWith(p)))})),c}(),t=!e;return n?(n.forEach(((e,n)=>{e.forEach((e=>{const i=e.textContent,r=`${p}${b[n]}_`;if(t)e.textContent=`${r}${i.substring(4)}`;else{if(!i.startsWith(r))throw new Error(`Token doesn't start with the '${r}' prefix.`);e.textContent=`${p}${i.substring(r.length)}`}}))})),!e):e}var S=t(7324);const y={sidebar_position:0,sidebar_label:"Getting Started",description:"TinyORM makes interacting with a database extremely simple using raw SQL, a fluent query builder, and the TinyORM. It provides first-party support for four databases MySQL/MariaDB, PostgreSQL, and SQLite.",keywords:["c++ orm","database","getting started","tinyorm"]},v="Database: Getting Started",_={id:"database/getting-started",title:"Database: Getting Started",description:"TinyORM makes interacting with a database extremely simple using raw SQL, a fluent query builder, and the TinyORM. It provides first-party support for four databases MySQL/MariaDB, PostgreSQL, and SQLite.",source:"@site/docs/database/getting-started.mdx",sourceDirName:"database",slug:"/database/getting-started",permalink:"/database/getting-started",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"Getting Started",description:"TinyORM makes interacting with a database extremely simple using raw SQL, a fluent query builder, and the TinyORM. It provides first-party support for four databases MySQL/MariaDB, PostgreSQL, and SQLite.",keywords:["c++ orm","database","getting started","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"\ud83d\ude80 Supported Compilers",permalink:"/supported-compilers"},next:{title:"Query Builder",permalink:"/database/query-builder"}},Q={},T=[{value:"Introduction",id:"introduction",level:2},{value:"Configuration",id:"configuration",level:3},{value:"SQLite Configuration",id:"sqlite-configuration",level:4},{value:"SSL Connections",id:"ssl-connections",level:3},{value:"MySQL",id:"mysql",level:5},{value:"PostgreSQL",id:"postgresql",level:5},{value:"Running SQL Queries",id:"running-sql-queries",level:2},{value:"Running A Select Query",id:"running-a-select-query",level:4},{value:"Selecting Scalar Values",id:"selecting-scalar-values",level:4},{value:"Running An Insert Statement",id:"running-an-insert-statement",level:4},{value:"Running An Update Statement",id:"running-an-update-statement",level:4},{value:"Running A Delete Statement",id:"running-a-delete-statement",level:4},{value:"Running A General Statement",id:"running-a-general-statement",level:4},{value:"Running An Unprepared Statement",id:"running-an-unprepared-statement",level:4},{value:"Implicit Commits",id:"implicit-commits",level:4},{value:"Using Multiple Database Connections",id:"using-multiple-database-connections",level:3},{value:"Database Transactions",id:"database-transactions",level:2},{value:"Manually Using Transactions",id:"manually-using-transactions",level:4},{value:"Multi-threading support",id:"multi-threading-support",level:2}];function D(e){const n={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h1,{id:"database-getting-started",children:"Database: Getting Started"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#introduction",children:"Introduction"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#configuration",children:"Configuration"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#ssl-connections",children:"SSL Connections"})}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.a,{href:"#running-sql-queries",children:"Running SQL Queries"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#using-multiple-database-connections",children:"Using Multiple Database Connections"})}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#database-transactions",children:"Database Transactions"})}),"\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"#multi-threading-support",children:"Multi-threading support"})}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(n.p,{children:["Almost every modern application interacts with a database. TinyORM makes interacting with a database extremely simple using raw SQL, a ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"fluent query builder"}),", and the ",(0,i.jsx)(n.a,{href:"/tinyorm/getting-started",children:"TinyORM"}),". Currently, TinyORM provides first-party support for four databases:"]}),"\n",(0,i.jsx)("div",{id:"databases-supported-versions",children:(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["MySQL ",(0,i.jsx)(n.code,{children:">=5.7"})," (",(0,i.jsx)(n.a,{href:"https://en.wikipedia.org/wiki/MySQL#Release_history",children:"Version Policy"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["MariaDB ",(0,i.jsx)(n.code,{children:">=10.3"})," (",(0,i.jsx)(n.a,{href:"https://mariadb.org/about/#maintenance-policy",children:"Version Policy"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["PostgreSQL ",(0,i.jsx)(n.code,{children:">=11"})," (",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/support/versioning/",children:"Version Policy"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["SQLite ",(0,i.jsx)(n.code,{children:">=3.8.8"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["native rename column ",(0,i.jsx)(n.code,{children:">=3.25.0"})," (",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/lang_altertable.html#alter_table_rename_column",children:"docs"})," , ",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/releaselog/3_25_0.html",children:"release notes"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["native drop column ",(0,i.jsx)(n.code,{children:">=3.35.0"})," (",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/lang_altertable.html#alter_table_drop_column",children:"docs"}),", ",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/releaselog/3_35_0.html",children:"release notes"}),")"]}),"\n",(0,i.jsxs)(n.li,{children:["generated columns ",(0,i.jsx)(n.code,{children:">=3.31.0"})," (",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/gencol.html",children:"docs"}),", ",(0,i.jsx)(n.a,{href:"https://www.sqlite.org/releaselog/3_31_0.html",children:"release notes"}),")"]}),"\n"]}),"\n"]}),"\n"]})}),"\n",(0,i.jsxs)(n.p,{children:["TinyORM internally uses ",(0,i.jsx)(n.code,{children:"QtSql"})," module, you can look for ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/sql-driver.html#supported-databases",children:"supported databases"}),"."]}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsx)(n.p,{children:"TinyORM's code is ready and designed to simply add support for the SQL Server."})}),"\n",(0,i.jsx)(n.h3,{id:"configuration",children:"Configuration"}),"\n",(0,i.jsxs)(n.p,{children:["You can create and configure a new database connection using the ",(0,i.jsx)(n.code,{children:"create"})," method provided by the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsxs)("div",{id:"tinyorm-configuration",children:[(0,i.jsx)(d,{}),(0,i.jsxs)(s.A,{className:"tinyorm-configuration-basic",groupId:S.OO,children:[(0,i.jsx)(a.A,{value:S.Dx,label:S.A3,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_HOST", "127.0.0.1")},\n {"port", qEnvironmentVariable("DB_PORT", "3306")},\n {"database", qEnvironmentVariable("DB_DATABASE", "")},\n {"username", qEnvironmentVariable("DB_USERNAME", "root")},\n {"password", qEnvironmentVariable("DB_PASSWORD", "")},\n {"charset", qEnvironmentVariable("DB_CHARSET", "utf8mb4")},\n {"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_0900_ai_ci")},\n {"timezone", "+00:00"},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {"qt_timezone", QVariant::fromValue(Qt::UTC)},\n {"prefix", ""},\n {"prefix_indexes", false},\n {"strict", true},\n {"engine", "InnoDB"},\n {"options", QVariantHash()},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.os,label:S.LQ,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_HOST", "127.0.0.1")},\n {"port", qEnvironmentVariable("DB_PORT", "5432")},\n {"database", qEnvironmentVariable("DB_DATABASE", "")},\n {"search_path", qEnvironmentVariable("DB_SEARCHPATH", "public")},\n {"username", qEnvironmentVariable("DB_USERNAME", "postgres")},\n {"password", qEnvironmentVariable("DB_PASSWORD", "")},\n {"charset", qEnvironmentVariable("DB_CHARSET", "utf8")},\n {"timezone", "UTC"},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {"qt_timezone", QVariant::fromValue(Qt::UTC)},\n {"prefix", ""},\n {"prefix_indexes", false},\n {"options", QVariantHash()},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.F4,label:S.Q7,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QSQLITE"},\n {"database", qEnvironmentVariable("DB_DATABASE", "/example/example.sqlite3")},\n {"foreign_key_constraints", qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},\n {"check_database_exists", true},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {"qt_timezone", QVariant::fromValue(Qt::UTC)},\n /* Return a QDateTime/QDate with the correct time zone instead of the QString,\n only works when the qt_timezone isn\'t set to the DontConvert. */\n {"return_qdatetime", true},\n {"prefix", ""},\n {"prefix_indexes", false},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.Fi,label:S.CW,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_HOST", "127.0.0.1")},\n {"port", qEnvironmentVariable("DB_PORT", "3306")},\n {"database", qEnvironmentVariable("DB_DATABASE", "")},\n {"username", qEnvironmentVariable("DB_USERNAME", "root")},\n {"password", qEnvironmentVariable("DB_PASSWORD", "")},\n {"charset", qEnvironmentVariable("DB_CHARSET", "utf8mb4")},\n {"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_unicode_520_ci")},\n {"timezone", "+00:00"},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {"qt_timezone", QVariant::fromValue(Qt::UTC)},\n {"prefix", ""},\n {"prefix_indexes", false},\n {"strict", true},\n {"engine", "InnoDB"},\n {"options", QVariantHash()},\n});\n'})})})]}),(0,i.jsxs)(s.A,{className:"tinyorm-configuration-full",groupId:S.OO,children:[(0,i.jsx)(a.A,{value:S.Dx,label:S.A3,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\nusing namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {driver_, QMYSQL},\n {host_, qEnvironmentVariable("DB_HOST", H127001)},\n {port_, qEnvironmentVariable("DB_PORT", P3306)},\n {database_, qEnvironmentVariable("DB_DATABASE", EMPTY)},\n {username_, qEnvironmentVariable("DB_USERNAME", ROOT)},\n {password_, qEnvironmentVariable("DB_PASSWORD", EMPTY)},\n {charset_, qEnvironmentVariable("DB_CHARSET", UTF8MB4)},\n {collation_, qEnvironmentVariable("DB_COLLATION", UTF8MB40900aici)},\n // SSL-related\n {ssl_ca, QStringLiteral("C:/mysql/data/ca.pem")},\n {ssl_cert, QStringLiteral("C:/mysql/data/client-cert.pem")},\n {ssl_key, QStringLiteral("C:/mysql/data/client-key.pem")},\n {ssl_mode, VerifyCA},\n // Or\n// {options, ConfigUtils::mysqlSslOptions()},\n {timezone_, TZ00},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {qt_timezone, QVariant::fromValue(Qt::UTC)},\n {prefix_, EMPTY},\n {prefix_indexes, false},\n {strict_, true},\n// {isolation_level, QStringLiteral("REPEATABLE READ")}, // MySQL default is REPEATABLE READ for InnoDB\n {engine_, InnoDB},\n {Version, {}}, // Autodetect\n {options_, QVariantHash()},\n // Examples\n// {options_, QStringLiteral("MYSQL_OPT_CONNECT_TIMEOUT = 1 ; MYSQL_OPT_READ_TIMEOUT=1")},\n// {options_, QVariantHash {{QStringLiteral("MYSQL_OPT_CONNECT_TIMEOUT"), 1},\n// {QStringLiteral("MYSQL_OPT_READ_TIMEOUT"), 1}}},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.os,label:S.LQ,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\nusing namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {driver_, QPSQL},\n {application_name, QStringLiteral("Example application")},\n {host_, qEnvironmentVariable("DB_HOST", H127001)},\n {port_, qEnvironmentVariable("DB_PORT", P5432)},\n {database_, qEnvironmentVariable("DB_DATABASE", EMPTY)},\n {search_path, qEnvironmentVariable("DB_SEARCHPATH", PUBLIC)},\n {username_, qEnvironmentVariable("DB_USERNAME", postgres_)},\n {password_, qEnvironmentVariable("DB_PASSWORD", EMPTY)},\n {charset_, qEnvironmentVariable("DB_CHARSET", UTF8)},\n // SSL-related\n {sslmode_, QStringLiteral("verify-full")},\n {sslcert, QStringLiteral("C:/example/postgres.crt")},\n {sslkey, QStringLiteral("C:/example/postgres.key")},\n {sslrootcert, QStringLiteral("C:/example/root.crt")},\n // Or\n// {options_, ConfigUtils::postgresSslOptions()},\n {timezone_, UTC},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {qt_timezone, QVariant::fromValue(Qt::UTC)},\n {prefix_, EMPTY},\n {prefix_indexes, false},\n// {isolation_level, QStringLiteral("REPEATABLE READ")}, // Postgres default is READ COMMITTED\n// {synchronous_commit, QStringLiteral("off")}, // Postgres default is on\n // ConnectionFactory provides a default value for this, this is only for reference\n// {dont_drop, QStringList {spatial_ref_sys}},\n {options_, QVariantHash()},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.F4,label:S.Q7,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\nusing namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {driver_, QSQLITE},\n {database_, qEnvironmentVariable("DB_DATABASE", "C:/SQLite/example.sqlite3")},\n {foreign_key_constraints, qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},\n {check_database_exists, true},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {qt_timezone, QVariant::fromValue(Qt::UTC)},\n /* Return a QDateTime/QDate with the correct time zone instead of the QString,\n only works when the qt_timezone isn\'t set to the DontConvert. */\n {return_qdatetime, true},\n {prefix_, EMPTY},\n {prefix_indexes, false},\n});\n'})})}),(0,i.jsx)(a.A,{value:S.Fi,label:S.CW,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\nusing namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {driver_, QMYSQL},\n {host_, qEnvironmentVariable("DB_HOST", H127001)},\n {port_, qEnvironmentVariable("DB_PORT", P3306)},\n {database_, qEnvironmentVariable("DB_DATABASE", EMPTY)},\n {username_, qEnvironmentVariable("DB_USERNAME", ROOT)},\n {password_, qEnvironmentVariable("DB_PASSWORD", EMPTY)},\n {charset_, qEnvironmentVariable("DB_CHARSET", UTF8MB4)},\n {collation_, qEnvironmentVariable("DB_COLLATION", UTF8MB4Unicode520ci)},\n // SSL-related\n {ssl_ca, QStringLiteral("C:/maria/data/ca.pem")},\n {ssl_cert, QStringLiteral("C:/maria/data/client-cert.pem")},\n {ssl_key, QStringLiteral("C:/maria/data/client-key.pem")},\n // Or\n// {options, ConfigUtils::mariaSslOptions()},\n {timezone_, TZ00},\n /* Specifies what time zone all QDateTime-s will have, the overridden default is\n the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use\n the system local time. */\n {qt_timezone, QVariant::fromValue(Qt::UTC)},\n {prefix_, EMPTY},\n {prefix_indexes, false},\n {strict_, true},\n// {isolation_level, QStringLiteral("REPEATABLE READ")}, // MariaDB default is REPEATABLE READ for InnoDB\n {engine_, InnoDB},\n {Version, {}}, // Autodetect\n {options_, QVariantHash()},\n // Examples\n// {options_, QStringLiteral("MYSQL_OPT_CONNECT_TIMEOUT = 1 ; MYSQL_OPT_READ_TIMEOUT=1")},\n// {options_, QVariantHash {{QStringLiteral("MYSQL_OPT_CONNECT_TIMEOUT"), 1},\n// {QStringLiteral("MYSQL_OPT_READ_TIMEOUT"), 1}}},\n});\n'})})})]})]}),"\n",(0,i.jsxs)(n.p,{children:["The first argument is configuration hash which is of type ",(0,i.jsx)(n.code,{children:"QVariantHash"})," and the second argument specifies the name of the ",(0,i.jsx)(n.em,{children:"connection"}),", this connection will also be a ",(0,i.jsx)(n.em,{children:"default connection"}),". You can configure multiple database connections at once and choose the needed one before executing SQL query, section ",(0,i.jsx)(n.a,{href:"#using-multiple-database-connections",children:"Using Multiple Database Connections"})," describes how to create and use multiple database connections."]}),"\n",(0,i.jsxs)(n.p,{children:["You may also configure connection options by ",(0,i.jsx)(n.code,{children:"options"})," key as ",(0,i.jsx)(n.code,{children:"QVariantHash"})," or ",(0,i.jsx)(n.code,{children:"QString"}),", you can pass any ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/qsqldatabase.html#setConnectOptions",children:"connection options"})," supported by ",(0,i.jsx)(n.code,{children:"QSqlDatabase"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:["You can also configure ",(0,i.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.4/en/innodb-transaction-isolation-levels.html",children:"Transaction Isolation Levels"})," for MySQL connection with the ",(0,i.jsx)(n.code,{children:"isolation_level"})," configuration option."]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"version"})," option is relevant only for the MySQL connections and you can save/avoid one database query (select version()) if you provide it manually. On the base of this version will be decided which ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/src/orm/connectors/mysqlconnector.cpp#L154",children:"session variables"})," will be set if strict mode is enabled and whether to use an ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/src/orm/query/grammars/mysqlgrammar.cpp#L36",children:"alias"})," during the ",(0,i.jsx)(n.code,{children:"upsert"})," method call."]}),"\n",(0,i.jsxs)(n.p,{children:["Breaking values are as follows; use an upsert alias on the MySQL >=8.0.19 and remove the ",(0,i.jsx)(n.code,{children:"NO_AUTO_CREATE_USER"})," sql mode on the MySQL >=8.0.11 if the strict mode is enabled."]}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["A database connection is resolved lazily, which means that the connection configuration is only saved after the ",(0,i.jsx)(n.code,{children:"DB::create"})," method call. The connection will be resolved after you run some query or you can create it using the ",(0,i.jsx)(n.code,{children:"DB::connection"})," method."]})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["You can also use predefined string constants to avoid unnecessary ",(0,i.jsx)(n.code,{children:"QString"})," instantiations, as used in the ",(0,i.jsx)(n.code,{children:"tom"})," migrations ",(0,i.jsx)(n.a,{href:"/building/migrations#string-constants-example",children:"example"}),"."]})}),"\n",(0,i.jsx)(n.h4,{id:"sqlite-configuration",children:"SQLite Configuration"}),"\n",(0,i.jsxs)(n.p,{children:["SQLite databases are contained within a single file on your filesystem. You can create a new SQLite database using the ",(0,i.jsx)(n.code,{children:"touch"})," command in your terminal: ",(0,i.jsx)(n.code,{children:"touch database.sqlite3"}),". After the database has been created, you may configure SQLite database connection:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QSQLITE"},\n {"database", qEnvironmentVariable("DB_DATABASE", "/absolute/path/to/database.sqlite3")},\n {"foreign_key_constraints", qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},\n {"check_database_exists", true},\n {"prefix", ""},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"database"})," configuration value is the absolute path to the database. To enable foreign key constraints for SQLite connections, you should set the ",(0,i.jsx)(n.code,{children:"foreign_key_constraints"})," configuration value to ",(0,i.jsx)(n.code,{children:"true"}),", if this configuration value is not set, then the default of the SQLite driver will be used (currently the default is ",(0,i.jsx)(n.strong,{children:"disabled"}),")."]}),"\n",(0,i.jsxs)(n.p,{children:["If the ",(0,i.jsx)(n.code,{children:"check_database_exists"})," configuration value is set to the ",(0,i.jsx)(n.code,{children:"true"})," value, then the database connection throws an ",(0,i.jsx)(n.code,{children:"Orm::InvalidArgumentError"})," exception, when the SQLite database file doesn't exist. If it is set to the ",(0,i.jsx)(n.code,{children:"false"})," value and the SQLite database file doesn't exist, then it will be created for you by SQLite driver. The default value is ",(0,i.jsx)(n.code,{children:"true"}),"."]}),"\n",(0,i.jsx)(n.h3,{id:"ssl-connections",children:"SSL Connections"}),"\n",(0,i.jsxs)(n.p,{children:["SSL connections are supported for the ",(0,i.jsx)(n.code,{children:"MySQL"})," and ",(0,i.jsx)(n.code,{children:"PostgreSQL"})," databases. They can be set using the ",(0,i.jsx)(n.code,{children:"options"})," configuration option."]}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["This feature is heavily dependent on the underlying ",(0,i.jsx)(n.code,{children:"QSqlDatabase"})," module. What means that you can pass the same ",(0,i.jsx)(n.a,{href:"https://doc.qt.io/qt/qsqldatabase.html#setConnectOptions",children:"connection options"})," to the ",(0,i.jsx)(n.code,{children:"TinyORM"})," that the ",(0,i.jsx)(n.code,{children:"QSqlDatabase"})," accepts."]})}),"\n",(0,i.jsx)(n.h5,{id:"mysql",children:"MySQL"}),"\n",(0,i.jsxs)(n.p,{children:["You have to pass the ",(0,i.jsx)(n.code,{children:"SSL_CA"}),", ",(0,i.jsx)(n.code,{children:"SSL_CERT"}),", ",(0,i.jsx)(n.code,{children:"SSL_KEY"}),", and ",(0,i.jsx)(n.code,{children:"MYSQL_OPT_SSL_MODE"})," options."]}),"\n",(0,i.jsxs)(s.A,{groupId:S.vf,children:[(0,i.jsx)(a.A,{value:S.b,label:S.ux,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"options", QVariantHash({{"SSL_CA", "C:/mysql/data/ca.pem"},\n {"SSL_CERT", "C:/mysql/data/client-cert.pem"},\n {"SSL_KEY", "C:/mysql/data/client-key.pem"},\n {"MYSQL_OPT_SSL_MODE", "VERIFY_CA"}})},\n // highlight-end\n});\n'})})}),(0,i.jsx)(a.A,{value:S.xj,label:S.gg,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"options", QVariantHash({{"SSL_CA", "~/.local/share/TinyORM/ssl/ca.pem"},\n {"SSL_CERT", "~/.local/share/TinyORM/ssl/client-cert.pem"},\n {"SSL_KEY", "~/.local/share/TinyORM/ssl/client-key.pem"},\n {"MYSQL_OPT_SSL_MODE", "VERIFY_CA"}})},\n // highlight-end\n});\n'})})})]}),"\n",(0,i.jsxs)(n.p,{children:["You may also use the ",(0,i.jsx)(n.code,{children:"ConfigUtils::mysqlSslOptions()"})," or the ",(0,i.jsx)(n.code,{children:"ConfigUtils::insertMySqlSslOptions()"})," methods to insert these options for you and define them using the ",(0,i.jsx)(n.code,{children:"DB_MYSQL_SSL_CA"}),", ",(0,i.jsx)(n.code,{children:"DB_MYSQL_SSL_CERT"}),", ",(0,i.jsx)(n.code,{children:"DB_MYSQL_SSL_KEY"}),", and ",(0,i.jsx)(n.code,{children:"DB_MYSQL_SSL_MODE"})," environment variables."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", ConfigUtils::mysqlSslOptions()},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["You can define these SSL-related options in the top-level configuration, they will be copied to the ",(0,i.jsx)(n.code,{children:"options"})," option hash during configuration parsing. The top-level configuration takes precedence and overwrites the options in the ",(0,i.jsx)(n.code,{children:"options"})," hash."]}),"\n",(0,i.jsxs)(s.A,{groupId:S.vf,children:[(0,i.jsx)(a.A,{value:S.b,label:S.ux,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"SSL_CA", "C:/mysql/data/ca.pem"},\n {"SSL_CERT", "C:/mysql/data/client-cert.pem"},\n {"SSL_KEY", "C:/mysql/data/client-key.pem"},\n {"MYSQL_OPT_SSL_MODE", "VERIFY_CA"},\n // highlight-end\n});\n'})})}),(0,i.jsx)(a.A,{value:S.xj,label:S.gg,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"SSL_CA", "~/.local/share/TinyORM/ssl/ca.pem"},\n {"SSL_CERT", "~/.local/share/TinyORM/ssl/client-cert.pem"},\n {"SSL_KEY", "~/.local/share/TinyORM/ssl/client-key.pem"},\n {"MYSQL_OPT_SSL_MODE", "VERIFY_CA"},\n // highlight-end\n});\n'})})})]}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["You can take a look at the GitHub actions how the ",(0,i.jsx)(n.code,{children:"MySQL"})," certificates are generated in the CI pipeline for ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/msvc2022-qt6.yml",children:"Windows"})," and ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/linux-qt6.yml",children:"Linux"}),"."]})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["You can also pass the ",(0,i.jsx)(n.code,{children:"QString"})," to the ",(0,i.jsx)(n.code,{children:"options"})," configuration separated by the ",(0,i.jsx)(n.code,{children:";"})," semicolon character and use the ",(0,i.jsx)(n.code,{children:"="})," to assign values."]})}),"\n",(0,i.jsx)(n.h5,{id:"postgresql",children:"PostgreSQL"}),"\n",(0,i.jsxs)(n.p,{children:["You have to pass the ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS",children:(0,i.jsx)(n.code,{children:"sslmode"})})," or the deprecated ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-REQUIRESSL",children:(0,i.jsx)(n.code,{children:"requiressl"})})," options."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", QVariantHash({{"sslmode", "verify-full"}})},\n});\n'})}),"\n",(0,i.jsxs)(n.p,{children:["And place your ",(0,i.jsx)(n.strong,{children:"client"})," certificates to the ",(0,i.jsx)(n.code,{children:"~/.postgres/"})," on ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-FILE-USAGE",children:"Linux"})," and ",(0,i.jsx)(n.code,{children:"$env:APPDATA/postgres/"})," on Windows. Everything is described in the PostgreSQL's ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-ssl.html",children:"libpq client"})," and ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/15/ssl-tcp.html#SSL-FILE-USAGE",children:"server"})," documentation."]}),"\n",(0,i.jsxs)(n.p,{children:["If you want to keep your ",(0,i.jsx)(n.strong,{children:"client"})," certificates in your own location, you can set the ",(0,i.jsx)(n.code,{children:"sslcert"}),", ",(0,i.jsx)(n.code,{children:"sslkey"}),", and ",(0,i.jsx)(n.code,{children:"sslrootcert"})," options."]}),"\n",(0,i.jsxs)(s.A,{groupId:S.vf,children:[(0,i.jsx)(a.A,{value:S.b,label:S.ux,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", QVariantHash({{"sslmode", "verify-full"},\n // highlight-start\n {"sslcert", "C:/example/postgres.crt"},\n {"sslkey", "C:/example/postgres.key"},\n {"sslrootcert", "C:/example/root.crt"}})},\n // highlight-end\n});\n'})})}),(0,i.jsx)(a.A,{value:S.xj,label:S.gg,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", QVariantHash({{"sslmode", "verify-full"},\n // highlight-start\n {"sslcert", "/example/postgres.crt"},\n {"sslkey", "/example/postgres.key"},\n {"sslrootcert", "/example/root.crt"}})},\n // highlight-end\n});\n'})})})]}),"\n",(0,i.jsxs)(n.p,{children:["You can define these SSL-related options in the top-level configuration, they will be copied to the ",(0,i.jsx)(n.code,{children:"options"})," option hash during a configuration parsing. The top-level configuration takes precedence and overwrites the options in the ",(0,i.jsx)(n.code,{children:"options"})," hash."]}),"\n",(0,i.jsxs)(s.A,{groupId:S.vf,children:[(0,i.jsx)(a.A,{value:S.b,label:S.ux,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"sslmode", "verify-full"},\n {"sslcert", "C:/example/postgres.crt"},\n {"sslkey", "C:/example/postgres.key"},\n {"sslrootcert", "C:/example/root.crt"},\n // highlight-end\n});\n'})})}),(0,i.jsx)(a.A,{value:S.xj,label:S.gg,children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nusing Orm::DB;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-start\n {"sslmode", "verify-full"},\n {"sslcert", "/example/postgres.crt"},\n {"sslkey", "/example/postgres.key"},\n {"sslrootcert", "/example/root.crt"},\n // highlight-end\n});\n'})})})]}),"\n",(0,i.jsxs)(n.p,{children:["You may also use the ",(0,i.jsx)(n.code,{children:"ConfigUtils::postgresSslOptions()"})," or the ",(0,i.jsx)(n.code,{children:"ConfigUtils::insertPostgresSslOptions()"})," methods to insert the ",(0,i.jsx)(n.code,{children:"sslmode"}),", ",(0,i.jsx)(n.code,{children:"sslcert"}),", ",(0,i.jsx)(n.code,{children:"sslkey"}),", and ",(0,i.jsx)(n.code,{children:"sslrootcert"})," options for you and define them using the ",(0,i.jsx)(n.code,{children:"DB_PGSQL_SSLMODE"}),", ",(0,i.jsx)(n.code,{children:"DB_PGSQL_SSLCERT"}),", ",(0,i.jsx)(n.code,{children:"DB_PGSQL_SSLKEY"}),", and ",(0,i.jsx)(n.code,{children:"DB_PGSQL_SSLROOTCERT"})," environment variable."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nusing Orm::DB;\n\nusing ConfigUtils = Orm::Utils::Configuration;\n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"driver", "QPSQL"},\n {"host", qEnvironmentVariable("DB_PGSQL_HOST", "127.0.0.1")},\n ...\n // highlight-next-line\n {"options", ConfigUtils::postgresSslOptions()},\n});\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["The PostgreSQL's libpq client library provides the ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.13.1.1",children:(0,i.jsx)(n.code,{children:"PGSSLMODE"})}),", ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.16.1.1",children:(0,i.jsx)(n.code,{children:"PGSSLCERT"})}),", ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.17.1.1",children:(0,i.jsx)(n.code,{children:"PGSSLKEY"})}),", and ",(0,i.jsx)(n.a,{href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.18.1.1",children:(0,i.jsx)(n.code,{children:"PGSSLROOTCERT"})})," environment variables, so you don't have to use TinyORM's ",(0,i.jsx)(n.code,{children:"options"})," configuration and may use these environment variables instead."]})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["You can take a look at the GitHub actions how the ",(0,i.jsx)(n.code,{children:"PostgreSQL"})," certificates are generated in the CI pipeline for ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/msvc2022-qt6.yml",children:"Windows"})," and ",(0,i.jsx)(n.a,{href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/linux-qt6.yml",children:"Linux"}),"."]})}),"\n",(0,i.jsx)(n.h2,{id:"running-sql-queries",children:"Running SQL Queries"}),"\n",(0,i.jsxs)(n.p,{children:["Once you have configured your database connection, you may run queries using the ",(0,i.jsx)(n.code,{children:"DB"})," facade. The ",(0,i.jsx)(n.code,{children:"DB"})," facade provides methods for each type of query: ",(0,i.jsx)(n.code,{children:"select"}),", ",(0,i.jsx)(n.code,{children:"update"}),", ",(0,i.jsx)(n.code,{children:"insert"}),", ",(0,i.jsx)(n.code,{children:"delete"}),", and ",(0,i.jsx)(n.code,{children:"statement"}),"."]}),"\n",(0,i.jsx)(n.h4,{id:"running-a-select-query",children:"Running A Select Query"}),"\n",(0,i.jsxs)(n.p,{children:["To run a basic SELECT query, you may use the ",(0,i.jsx)(n.code,{children:"select"})," method on the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsxs)(n.p,{children:['auto users = DB::select("select * from users where active = ?", ',1,");"]}),"\n",(0,i.jsxs)(n.p,{children:["The first argument passed to the ",(0,i.jsx)(n.code,{children:"select"})," method is the SQL query, while the second argument is any parameter bindings that need to be bound to the query. Typically, these are the values of the ",(0,i.jsx)(n.code,{children:"where"})," clause constraints. Parameter binding provides protection against SQL injection."]}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"select"})," method returns a ",(0,i.jsx)(n.code,{children:"QSqlQuery"})," containing the results of the query, where each result can be accessed by ",(0,i.jsx)(n.code,{children:"QSqlQuery::next"})," method. Look into the ",(0,i.jsx)(n.code,{children:"QSqlQuery"}),' documentation on how to obtain results from the "query". You may access each column\'s value by ',(0,i.jsx)(n.code,{children:"QSqlQuery::value"})," method. The first ",(0,i.jsx)(n.code,{children:"bool"})," return value is the value returned from ",(0,i.jsx)(n.code,{children:"QSqlQuery::exec"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include \n\nauto users = DB::select("select * from users");\n\nwhile(users.next())\n qDebug() << users.value("name").toString();\n'})}),"\n",(0,i.jsx)(n.h4,{id:"selecting-scalar-values",children:"Selecting Scalar Values"}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes your database query may result in a single, scalar value. Instead of being required to retrieve the query's scalar result from a record instance, TinyORM allows you to retrieve this value directly using the ",(0,i.jsx)(n.code,{children:"scalar"})," shortcut method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto states = DB::scalar(\n "select count(case when state = \'pending\' then 1 end) as states "\n "from comments"\n);\n\n// With binding\nauto states = DB::scalar(\n "select count(case when state = ? then 1 end) as states from comments",\n {"pending"}\n);\n'})}),"\n",(0,i.jsx)(n.h4,{id:"running-an-insert-statement",children:"Running An Insert Statement"}),"\n",(0,i.jsxs)(n.p,{children:["To execute an ",(0,i.jsx)(n.code,{children:"insert"})," statement, you may use the ",(0,i.jsx)(n.code,{children:"insert"})," method on the ",(0,i.jsx)(n.code,{children:"DB"})," facade. Like ",(0,i.jsx)(n.code,{children:"select"}),", this method accepts the SQL query as its first argument and bindings as its second argument and returns ",(0,i.jsx)(n.code,{children:"QSqlQuery"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nDB::insert("insert into users (id, name) values (?, ?)", {1, "Marc"});\n'})}),"\n",(0,i.jsx)(n.h4,{id:"running-an-update-statement",children:"Running An Update Statement"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"update"})," method should be used to update existing records in the database. The number of rows affected by the statement and ",(0,i.jsx)(n.code,{children:"QSqlQuery"})," is returned by the method as ",(0,i.jsx)(n.code,{children:"std::tuple"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include \n\nauto [affected, query] = DB::update(\n "update users set updated_at = ? where name = ?",\n {QDateTime::currentDateTimeUtc(), "Anita"}\n);\n\nif (!affected)\n qDebug() << "Any record was updated.";\n'})}),"\n",(0,i.jsx)(n.h4,{id:"running-a-delete-statement",children:"Running A Delete Statement"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"remove"})," method should be used to delete records from the database. Like ",(0,i.jsx)(n.code,{children:"update"}),", the number of affected rows and ",(0,i.jsx)(n.code,{children:"QSqlQuery"})," will be returned by the method as ",(0,i.jsx)(n.code,{children:"std::tuple"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto [affected, query] = DB::remove("delete from users");\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"delete"})," can not be used as the method name because it is the reserved word."]})}),"\n",(0,i.jsx)(n.h4,{id:"running-a-general-statement",children:"Running A General Statement"}),"\n",(0,i.jsxs)(n.p,{children:["Some database statements do not return any value. For these types of operations, you may use the ",(0,i.jsx)(n.code,{children:"statement"})," method on the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'DB::statement("drop table users");\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"DB::statement"})," method should be used for ",(0,i.jsx)(n.a,{href:"https://en.wikipedia.org/wiki/Data_definition_language",children:"DDL"}),' queries, don\'t use it for "select" queries because it internally calls ',(0,i.jsx)(n.code,{children:"recordsHaveBeenModified"})," method."]})}),"\n",(0,i.jsx)(n.h4,{id:"running-an-unprepared-statement",children:"Running An Unprepared Statement"}),"\n",(0,i.jsxs)(n.p,{children:["Sometimes you may want to execute an SQL statement without binding any values. You may use the ",(0,i.jsx)(n.code,{children:"DB"})," facade's ",(0,i.jsx)(n.code,{children:"unprepared"})," method to accomplish this:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"DB::unprepared(\"update users set votes = 100 where name = 'Dries'\");\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"warning",children:(0,i.jsx)(n.p,{children:"Since unprepared statements do not bind parameters, they may be vulnerable to SQL injection. You should never allow user controlled values within an unprepared statement."})}),"\n",(0,i.jsx)(n.h4,{id:"implicit-commits",children:"Implicit Commits"}),"\n",(0,i.jsxs)(n.p,{children:["When using the ",(0,i.jsx)(n.code,{children:"DB"})," facade's ",(0,i.jsx)(n.code,{children:"statement"})," methods within transactions, you must be careful to avoid statements that cause ",(0,i.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.4/en/implicit-commit.html",children:"implicit commits"}),". These statements will cause the database engine to indirectly commit the entire transaction, leaving TinyORM unaware of the database's transaction level. An example of such a statement is creating a database table:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'DB::statement("create table users (name varchar(255) null)");\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Please refer to the MySQL manual for ",(0,i.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.4/en/implicit-commit.html",children:"a list of all statements"})," that trigger implicit commits."]}),"\n",(0,i.jsx)(n.h3,{id:"using-multiple-database-connections",children:"Using Multiple Database Connections"}),"\n",(0,i.jsxs)(n.p,{children:["You can configure multiple database connections at once during ",(0,i.jsx)(n.code,{children:"DatabaseManager"})," instantiation using the ",(0,i.jsx)(n.code,{children:"DB::create"})," overload, where the first argument is a hash of multiple connections and is of type ",(0,i.jsx)(n.code,{children:"QHash"})," and the second argument is the name of the default connection:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\n// Ownership of a shared_ptr()\nauto manager = DB::create({\n {"mysql", {\n {"driver", "QMYSQL"},\n {"host", qEnvironmentVariable("DB_MYSQL_HOST", "127.0.0.1")},\n {"port", qEnvironmentVariable("DB_MYSQL_PORT", "3306")},\n {"database", qEnvironmentVariable("DB_MYSQL_DATABASE", "")},\n {"username", qEnvironmentVariable("DB_MYSQL_USERNAME", "root")},\n {"password", qEnvironmentVariable("DB_MYSQL_PASSWORD", "")},\n {"charset", qEnvironmentVariable("DB_MYSQL_CHARSET", "utf8mb4")},\n {"collation", qEnvironmentVariable("DB_MYSQL_COLLATION", "utf8mb4_0900_ai_ci")},\n {"strict", true},\n {"options", QVariantHash()},\n }},\n {"sqlite", {\n {"driver", "QSQLITE"},\n {"database", qEnvironmentVariable("DB_SQLITE_DATABASE", "")},\n {"foreign_key_constraints", qEnvironmentVariable("DB_SQLITE_FOREIGN_KEYS", "true")},\n {"check_database_exists", true},\n {"prefix", ""},\n }},\n}, "mysql");\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If your application needs to use multiple connections, you may access each connection via the ",(0,i.jsx)(n.code,{children:"connection"})," method provided by the ",(0,i.jsx)(n.code,{children:"DB"})," facade. The connection name passed to the ",(0,i.jsx)(n.code,{children:"connection"})," method should correspond to one of the connections key listed in your configuration:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto query = DB::connection("mysql_test").select(...);\n'})}),"\n",(0,i.jsxs)(n.p,{children:["You may access the raw underlying ",(0,i.jsx)(n.code,{children:"QSqlQuery"})," instance of a connection using the ",(0,i.jsx)(n.code,{children:"getQtQuery"})," method on a connection instance:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"auto query = DB::connection().getQtQuery();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Or you can use the shortcut method ",(0,i.jsx)(n.code,{children:"qtQuery"})," provided by the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"auto query = DB::qtQuery();\n"})}),"\n",(0,i.jsx)(n.h2,{id:"database-transactions",children:"Database Transactions"}),"\n",(0,i.jsx)(n.h4,{id:"manually-using-transactions",children:"Manually Using Transactions"}),"\n",(0,i.jsxs)(n.p,{children:["If you would like to begin a transaction manually and have complete control over rollbacks and commits, you may use the ",(0,i.jsx)(n.code,{children:"beginTransaction"})," method provided by the ",(0,i.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"#include \n\nDB::beginTransaction();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["You can rollback the transaction via the ",(0,i.jsx)(n.code,{children:"rollBack"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"DB::rollBack();\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Lastly, you can commit a transaction via the ",(0,i.jsx)(n.code,{children:"commit"})," method:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:"DB::commit();\n"})}),"\n",(0,i.jsx)(n.p,{children:"All transaction methods accept a connection name as the optional argument:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cpp",children:'DB::beginTransaction("mysql_test");\n'})}),"\n",(0,i.jsx)(n.admonition,{type:"tip",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"DB"})," facade's transaction methods control the transactions for both the ",(0,i.jsx)(n.a,{href:"/database/query-builder",children:"query builder"})," and ",(0,i.jsx)(n.a,{href:"/tinyorm/getting-started",children:"TinyORM"}),"."]})}),"\n",(0,i.jsx)(n.h2,{id:"multi-threading-support",children:"Multi-threading support"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"TinyORM"})," supports multi-threading for the ",(0,i.jsx)(n.code,{children:"MSVC"})," and ",(0,i.jsx)(n.code,{children:"GCC"})," on Linux compilers. Multi-threading is disabled for the ",(0,i.jsx)(n.code,{children:"Clang <14.0.3"})," compiler on MSYS2, ",(0,i.jsx)(n.code,{children:"Clang <14.0.4"})," on Linux and for the ",(0,i.jsx)(n.code,{children:"GCC"})," compiler on MSYS2. The reason are bugs in the ",(0,i.jsx)(n.code,{children:"TLS"})," wrapper that is generated by the ",(0,i.jsx)(n.a,{href:"https://en.cppreference.com/w/cpp/keyword/thread_local",children:(0,i.jsx)(n.code,{children:"thread_local"})})," keyword."]}),"\n",(0,i.jsx)(n.p,{children:"A connection can only be used from within the thread that created it. Moving connections between threads or creating queries from a different thread where the connection was created is not supported."}),"\n",(0,i.jsxs)(n.p,{children:["In addition, the third party libraries used by the ",(0,i.jsx)(n.code,{children:"QSqlDrivers"})," can impose further restrictions on using the SQL Module in a multithreaded program."]}),"\n",(0,i.jsxs)(n.p,{children:["In short, if you create a ",(0,i.jsx)(n.code,{children:"DB::connection"})," in some thread then you have to use this connection only from this particular thread and of course all queries that will be executed on this connection."]}),"\n",(0,i.jsx)(n.p,{children:"If you want to execute some query from another thread for the same connection then you have to create a new connection first and if you have a new connection you can send a query from this new thread to the database."}),"\n",(0,i.jsx)(n.admonition,{type:"warning",children:(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.a,{href:"/database/migrations#tables",children:(0,i.jsx)(n.code,{children:"schema builder"})})," and ",(0,i.jsx)(n.a,{href:"/database/migrations",children:(0,i.jsx)(n.code,{children:"migrations"})})," don't support multi-threading."]})})]})}function L(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(D,{...e})}):D(e)}},9365:(e,n,t)=>{t.d(n,{A:()=>s});t(6540);var i=t(4164);const r={tabItem:"tabItem_Ymn6"};var a=t(4848);function s(e){let{children:n,hidden:t,className:s}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,i.A)(r.tabItem,s),hidden:t,children:n})}},1470:(e,n,t)=>{t.d(n,{A:()=>v});var i=t(6540),r=t(4164),a=t(3104),s=t(6347),o=t(205),l=t(7485),c=t(1682),d=t(9466);function h(e){return i.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:n,children:t}=e;return(0,i.useMemo)((()=>{const e=n??function(e){return h(e).map((e=>{let{props:{value:n,label:t,attributes:i,default:r}}=e;return{value:n,label:t,attributes:i,default:r}}))}(t);return function(e){const n=(0,c.X)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:t}=e;const r=(0,s.W6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:n,groupId:t});return[(0,l.aZ)(a),(0,i.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})}),[a,r])]}function g(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,a=u(e),[s,l]=(0,i.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const i=t.find((e=>e.default))??t[0];if(!i)throw new Error("Unexpected error: 0 tabValues");return i.value}({defaultValue:n,tabValues:a}))),[c,h]=m({queryString:t,groupId:r}),[g,x]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,a]=(0,d.Dv)(t);return[r,(0,i.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:r}),f=(()=>{const e=c??g;return p({value:e,tabValues:a})?e:null})();(0,o.A)((()=>{f&&l(f)}),[f]);return{selectedValue:s,selectValue:(0,i.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),h(e),x(e)}),[h,x,a]),tabValues:a}}var x=t(2303);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=t(4848);function j(e){let{className:n,block:t,selectedValue:i,selectValue:s,tabValues:o}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.a_)(),d=e=>{const n=e.currentTarget,t=l.indexOf(n),r=o[t].value;r!==i&&(c(n),s(r))},h=e=>{let n=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;n=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;n=l[t]??l[l.length-1];break}}n?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":t},n),children:o.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:i===n?0:-1,"aria-selected":i===n,ref:e=>l.push(e),onKeyDown:h,onClick:d,...a,className:(0,r.A)("tabs__item",f.tabItem,a?.className,{"tabs__item--active":i===n}),children:t??n},n)}))})}function S(e){let{lazy:n,children:t,selectedValue:r}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===r));return e?(0,i.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,i.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function y(e){const n=g(e);return(0,b.jsxs)("div",{className:(0,r.A)("tabs-container",f.tabList),children:[(0,b.jsx)(j,{...n,...e}),(0,b.jsx)(S,{...n,...e})]})}function v(e){const n=(0,x.A)();return(0,b.jsx)(y,{...e,children:h(e.children)},String(n))}},7324:(e,n,t)=>{t.d(n,{$E:()=>x,A3:()=>b,CW:()=>f,Dx:()=>d,F4:()=>u,Fi:()=>c,J_:()=>v,LQ:()=>j,Lf:()=>_,OO:()=>r,Q7:()=>S,b:()=>o,cy:()=>l,gg:()=>m,kl:()=>p,os:()=>h,pW:()=>a,ux:()=>g,vf:()=>i,xj:()=>s,xt:()=>y});const i="shell",r="database",a="application",s="bash",o="pwsh",l="zsh",c="maria",d="mysql",h="postgres",u="sqlite",p="application",m="bash",g="pwsh",x="zsh",f="MariaDB",b="MySQL",j="PostgreSQL",S="SQLite",y="tinyorm.org",v="$HOME/Code/c/",_="$env:USERPROFILE\\Code\\c\\"},8453:(e,n,t)=>{t.d(n,{R:()=>s,x:()=>o});var i=t(6540);const r={},a=i.createContext(r);function s(e){const n=i.useContext(a);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:s(e.components),i.createElement(a.Provider,{value:n},e.children)}}}]);
\ No newline at end of file
diff --git a/assets/js/cb1e72f9.37f5a4bc.js b/assets/js/cb1e72f9.37f5a4bc.js
deleted file mode 100644
index 6ab50e95e..000000000
--- a/assets/js/cb1e72f9.37f5a4bc.js
+++ /dev/null
@@ -1 +0,0 @@
-"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[258],{4028:(e,i,n)=>{n.r(i),n.d(i,{assets:()=>a,contentTitle:()=>t,default:()=>h,frontMatter:()=>d,metadata:()=>l,toc:()=>c});var r=n(4848),s=n(8453);const d={sidebar_position:0,sidebar_label:"Getting Started",description:"The TinyDrivers library is an underlying SQL database layer for TinyORM. It can be used instead of the QtSql module, can be swapped at compile time, and has 1:1 API as the QtSql module. Swapping is controlled by the qmake and CMake build system options. It was designed to drop the QtSql dependency while maintaining backward compatibility and without the need for any code changes after the swap.",keywords:["c++ orm","database","getting started","tinydrivers","sql drivers"]},t="TinyDrivers: Getting Started",l={id:"tinydrivers/getting-started",title:"TinyDrivers: Getting Started",description:"The TinyDrivers library is an underlying SQL database layer for TinyORM. It can be used instead of the QtSql module, can be swapped at compile time, and has 1:1 API as the QtSql module. Swapping is controlled by the qmake and CMake build system options. It was designed to drop the QtSql dependency while maintaining backward compatibility and without the need for any code changes after the swap.",source:"@site/docs/tinydrivers/getting-started.mdx",sourceDirName:"tinydrivers",slug:"/tinydrivers/getting-started",permalink:"/tinydrivers/getting-started",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"Getting Started",description:"The TinyDrivers library is an underlying SQL database layer for TinyORM. It can be used instead of the QtSql module, can be swapped at compile time, and has 1:1 API as the QtSql module. Swapping is controlled by the qmake and CMake build system options. It was designed to drop the QtSql dependency while maintaining backward compatibility and without the need for any code changes after the swap.",keywords:["c++ orm","database","getting started","tinydrivers","sql drivers"]},sidebar:"tinyormSidebar",previous:{title:"Serialization",permalink:"/tinyorm/serialization"},next:{title:"TinyORM",permalink:"/building/tinyorm"}},a={},c=[{value:"Introduction",id:"introduction",level:2},{value:"Features summary",id:"features-summary",level:5},{value:"Differences from QtSql",id:"differences-from-qtsql",level:2},{value:"Naming conventions",id:"naming-conventions",level:5},{value:"MySQL driver",id:"mysql-driver",level:5},{value:"Removed features",id:"removed-features",level:5},{value:"Missing features",id:"missing-features",level:5},{value:"Build system",id:"build-system",level:3},{value:"The Shared library build",id:"the-shared-library-build",level:5},{value:"The Static build",id:"the-static-build",level:5},{value:"The Loadable SQL drivers build",id:"the-loadable-sql-drivers-build",level:5},{value:"CMake/qmake build options",id:"cmakeqmake-build-options",level:4},{value:"For CMake",id:"for-cmake",level:5},{value:"For qmake",id:"for-qmake",level:5},{value:"Performance",id:"performance",level:3},{value:"Internals",id:"internals",level:2},{value:"SqlDatabase",id:"sqldatabase",level:5},{value:"Namespaces",id:"namespaces",level:5},{value:"Documentation",id:"documentation",level:5}];function o(e){const i={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.h1,{id:"tinydrivers-getting-started",children:"TinyDrivers: Getting Started"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsx)(i.li,{children:(0,r.jsx)(i.a,{href:"#introduction",children:"Introduction"})}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"#differences-from-qtsql",children:"Differences from QtSql"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsx)(i.li,{children:(0,r.jsx)(i.a,{href:"#build-system",children:"Build system"})}),"\n",(0,r.jsx)(i.li,{children:(0,r.jsx)(i.a,{href:"#performance",children:"Performance"})}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(i.li,{children:(0,r.jsx)(i.a,{href:"#internals",children:"Internals"})}),"\n"]}),"\n",(0,r.jsx)(i.h2,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsxs)(i.p,{children:["The ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," library is an underlying SQL database layer for ",(0,r.jsx)(i.code,{children:"TinyORM"}),". It can be used instead of the ",(0,r.jsx)(i.code,{children:"QtSql"})," module, can be ",(0,r.jsx)("u",{children:(0,r.jsx)(i.strong,{children:"swapped"})})," at compile time, and has ",(0,r.jsx)(i.strong,{children:"1:1"})," API as the ",(0,r.jsx)(i.code,{children:"QtSql"})," module. \ud83d\ude2e Swapping is controlled by the ",(0,r.jsx)(i.code,{children:"qmake"})," and ",(0,r.jsx)(i.code,{children:"CMake"})," build system options."]}),"\n",(0,r.jsxs)(i.p,{children:["It was designed to drop the ",(0,r.jsx)(i.code,{children:"QtSql"})," dependency while maintaining backward compatibility and without the need for any code changes after the swap."]}),"\n",(0,r.jsx)(i.h5,{id:"features-summary",children:"Features summary"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsx)(i.li,{children:"both, normal and prepared statements are supported"}),"\n",(0,r.jsxs)(i.li,{children:["TLS/SSL connections using ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/en/mysql-options.html",children:(0,r.jsx)(i.code,{children:"MYSQL_OPT_SSL_MODE"})})," (verify_ca, verify_identity) \ud83d\udd25"]}),"\n",(0,r.jsxs)(i.li,{children:["setting many other connection options (see ",(0,r.jsx)(i.a,{href:"https://github.com/silverqx/TinyORM/blob/main/drivers/mysql/src/orm/drivers/mysql/mysqldriver_p.cpp",children:(0,r.jsx)(i.code,{children:"mysqldriver_p.cpp"})}),")"]}),"\n",(0,r.jsxs)(i.li,{children:["building and linking against the ",(0,r.jsx)(i.a,{href:"https://mariadb.com/kb/en/mariadb-connector-c/",children:(0,r.jsx)(i.code,{children:"MariaDB Connector/C"})})]}),"\n",(0,r.jsx)(i.li,{children:"transactions"}),"\n",(0,r.jsxs)(i.li,{children:["re-using the current ",(0,r.jsx)(i.code,{children:"SqlQuery"})," instance to re-execute the same or another query"]}),"\n",(0,r.jsx)(i.li,{children:"detaching from the result set (associated to release memory)"}),"\n",(0,r.jsxs)(i.li,{children:["query size, number of affected rows, last inserted ID, testing ",(0,r.jsx)(i.code,{children:"isNull()"}),", ..."]}),"\n",(0,r.jsxs)(i.li,{children:["all ",(0,r.jsx)(i.strong,{children:"3366 unit tests"})," passed \ud83d\ude2e"]}),"\n"]}),"\n",(0,r.jsx)(i.admonition,{type:"info",children:(0,r.jsxs)(i.p,{children:["Currently, only the ",(0,r.jsx)(i.code,{children:"MySQL"})," database driver is supported and finished."]})}),"\n",(0,r.jsx)(i.admonition,{type:"info",children:(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," can only be built with ",(0,r.jsx)(i.code,{children:"Qt v6"}),", ",(0,r.jsx)(i.code,{children:"Qt v5.15"})," isn't supported."]})}),"\n",(0,r.jsx)(i.admonition,{type:"note",children:(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," library supports both build systems ",(0,r.jsx)(i.code,{children:"qmake"})," and also ",(0,r.jsx)(i.code,{children:"CMake"}),"."]})}),"\n",(0,r.jsx)(i.h2,{id:"differences-from-qtsql",children:"Differences from QtSql"}),"\n",(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," doesn't return errors the the same way as the ",(0,r.jsx)(i.code,{children:"QtSql"})," module, which means return a ",(0,r.jsx)(i.code,{children:"bool"})," and if it's the result ",(0,r.jsx)(i.code,{children:"false"})," then obtain the ",(0,r.jsx)(i.code,{children:"SqlError"})," instance using the ",(0,r.jsx)(i.code,{children:"lastError()"})," method from ",(0,r.jsx)(i.code,{children:"SqlDatabase"})," or ",(0,r.jsx)(i.code,{children:"SqlQuery"})," instances. Instead, it throws exceptions, and methods returning a ",(0,r.jsx)(i.code,{children:"bool"})," type to report an error state always return ",(0,r.jsx)(i.code,{children:"true"}),"."]}),"\n",(0,r.jsx)(i.h5,{id:"naming-conventions",children:"Naming conventions"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.code,{children:"QtSql"})," ",(0,r.jsx)("small",{children:"module"})," -> ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," ",(0,r.jsx)("small",{children:"library"})]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.code,{children:"QMYSQL"})," ",(0,r.jsx)("small",{children:"driver"})," -> ",(0,r.jsx)(i.code,{children:"TinyMySql"})," ",(0,r.jsx)("small",{children:"driver"})]}),"\n"]}),"\n",(0,r.jsx)(i.h5,{id:"mysql-driver",children:"MySQL driver"}),"\n",(0,r.jsxs)(i.p,{children:["The following describes the differences between ",(0,r.jsx)(i.code,{children:"QMYSQL"})," and ",(0,r.jsx)(i.code,{children:"TinyMySql"})," drivers."]}),"\n",(0,r.jsxs)(i.p,{children:["The ",(0,r.jsx)(i.code,{children:"QMYSQL"})," driver doesn't support setting ",(0,r.jsx)(i.code,{children:"MySQL"})," non-flag ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/en/mysql-options.html",children:"connection options"})," like ",(0,r.jsx)(i.code,{children:"MYSQL_OPT_RECONNECT"})," without the value, it needs to be defined with value like ",(0,r.jsx)(i.code,{children:"=1"})," or ",(0,r.jsx)(i.code,{children:"=TRUE"})," (case-sensitive), only real flag options like ",(0,r.jsx)(i.code,{children:"CLIENT_INTERACTIVE"})," can be set without the value and ",(0,r.jsx)(i.code,{children:"="})," character."]}),"\n",(0,r.jsxs)(i.p,{children:["On the other hand, the ",(0,r.jsx)(i.code,{children:"TinyMySql"})," driver allows setting non-flag ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/en/mysql-options.html",children:"connection options"})," options without the value and ",(0,r.jsx)(i.code,{children:"="})," character, which are considered enabled (ON or TRUE)."]}),"\n",(0,r.jsx)(i.h5,{id:"removed-features",children:"Removed features"}),"\n",(0,r.jsxs)(i.p,{children:["Simulation of prepared statements while calling ",(0,r.jsx)(i.code,{children:"SqlQuery::exec(QString)"}),", this functionality is useless because you can call regular prepared statements using ",(0,r.jsx)(i.code,{children:"SqlQuery::prepare(QString)"})," and then ",(0,r.jsx)(i.code,{children:"SqlQuery::exec()"}),"."]}),"\n",(0,r.jsx)(i.h5,{id:"missing-features",children:"Missing features"}),"\n",(0,r.jsxs)(i.p,{children:["Fetching multiple result sets using ",(0,r.jsx)(i.code,{children:"SqlQuery::nextResult()"}),". Multiple statement queries are supported they will be executed correctly (they can return multiple result sets), but only the first result set can be fetched currently. However, destroying multiple result sets is handled correctly."]}),"\n",(0,r.jsx)(i.h3,{id:"build-system",children:"Build system"}),"\n",(0,r.jsxs)(i.p,{children:["Another difference is that you can build the ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," and its SQL drivers (",(0,r.jsx)(i.code,{children:"TinyMySql"}),") in 3 different ways; ",(0,r.jsx)(i.code,{children:"Shared"}),", ",(0,r.jsx)(i.code,{children:"Static"}),", and as a ",(0,r.jsx)(i.code,{children:"Loadable"})," library at runtime using ",(0,r.jsx)(i.code,{children:"LoadLibrary()"})," on Windows or ",(0,r.jsx)(i.code,{children:"dlopen()"})," on Linux."]}),"\n",(0,r.jsxs)(i.h5,{id:"the-shared-library-build",children:["The ",(0,r.jsx)(i.code,{children:"Shared"})," library build"]}),"\n",(0,r.jsxs)(i.p,{children:["It builds two shared libraries, the ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," shared library that contains the core/common code and the ",(0,r.jsx)(i.code,{children:"TinyMySql"})," shared library that contains ",(0,r.jsx)(i.code,{children:"MySQL"})," implementation. The ",(0,r.jsx)(i.code,{children:"TinyOrm"})," links only against the ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," shared library and ",(0,r.jsx)(i.code,{children:"TinyMySql"})," is a private implementation."]}),"\n",(0,r.jsxs)(i.h5,{id:"the-static-build",children:["The ",(0,r.jsx)(i.code,{children:"Static"})," build"]}),"\n",(0,r.jsxs)(i.p,{children:["It builds one ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," static archive that contains the core/common code and SQL drivers (",(0,r.jsx)(i.code,{children:"TinyMySql"}),"). This static library is linked or merged into the ",(0,r.jsx)(i.code,{children:"TinyOrm"})," shared or static library (both variants are supported)."]}),"\n",(0,r.jsxs)(i.h5,{id:"the-loadable-sql-drivers-build",children:["The ",(0,r.jsx)(i.code,{children:"Loadable"})," SQL drivers build"]}),"\n",(0,r.jsxs)(i.p,{children:["It builds two shared libraries, the ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," shared library that contains the core/common code and ",(0,r.jsx)(i.code,{children:"TinyMySql"})," shared library (module) that contains ",(0,r.jsx)(i.code,{children:"MySQL"})," implementation that is loaded at runtime using ",(0,r.jsx)(i.code,{children:"LoadLibrary()"})," on Windows or ",(0,r.jsx)(i.code,{children:"dlopen()"})," on Linux. The SQL driver library loader throws an exception if it cannot find this library at runtime."]}),"\n",(0,r.jsx)(i.admonition,{type:"info",children:(0,r.jsxs)(i.p,{children:["The ",(0,r.jsx)(i.code,{children:"TinyMySql"})," links directly against the ",(0,r.jsx)(i.code,{children:"MySQL C connector"})," (",(0,r.jsx)(i.code,{children:"libmysql"})," or ",(0,r.jsx)(i.code,{children:"mysqlclient"})," library)."]})}),"\n",(0,r.jsxs)(i.h4,{id:"cmakeqmake-build-options",children:[(0,r.jsx)(i.code,{children:"CMake"}),"/",(0,r.jsx)(i.code,{children:"qmake"})," build options"]}),"\n",(0,r.jsxs)(i.h5,{id:"for-cmake",children:["For ",(0,r.jsx)(i.code,{children:"CMake"})]}),"\n",(0,r.jsxs)(i.p,{children:["See ",(0,r.jsx)(i.a,{href:"/building/tinyorm#cmake-build-options",children:"CMake build options"}),", related ",(0,r.jsx)(i.code,{children:"CMake"})," build options are:",(0,r.jsx)("br",{}),(0,r.jsx)(i.a,{href:"/building/tinyorm#BUILD_DRIVERS",children:(0,r.jsx)(i.code,{children:"BUILD_DRIVERS"})}),", ",(0,r.jsx)(i.a,{href:"/building/tinyorm#BUILD_MYSQL_DRIVER",children:(0,r.jsx)(i.code,{children:"BUILD_MYSQL_DRIVER"})}),", and ",(0,r.jsx)(i.a,{href:"/building/tinyorm#DRIVERS_TYPE",children:(0,r.jsx)(i.code,{children:"DRIVERS_TYPE"})})]}),"\n",(0,r.jsxs)(i.p,{children:["To control shared and static build use ",(0,r.jsx)(i.a,{href:"https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html",children:(0,r.jsx)(i.code,{children:"BUILD_SHARED_LIBS"})})," ",(0,r.jsx)(i.code,{children:"CMake"})," configuration option."]}),"\n",(0,r.jsxs)(i.h5,{id:"for-qmake",children:["For ",(0,r.jsx)(i.code,{children:"qmake"})]}),"\n",(0,r.jsxs)(i.p,{children:["See ",(0,r.jsx)(i.a,{href:"/building/tinyorm#qmake-build-options",children:"qmake build options"}),", related ",(0,r.jsx)(i.code,{children:"qmake"})," configuration options are:",(0,r.jsx)("br",{}),(0,r.jsx)(i.a,{href:"/building/tinyorm#build_loadable_drivers",children:(0,r.jsx)(i.code,{children:"build_loadable_drivers"})}),", ",(0,r.jsx)(i.a,{href:"/building/tinyorm#build_mysql_driver",children:(0,r.jsx)(i.code,{children:"build_mysql_driver"})}),", ",(0,r.jsx)(i.a,{href:"/building/tinyorm#build_shared_drivers",children:(0,r.jsx)(i.code,{children:"build_shared_drivers"})}),", and ",(0,r.jsx)(i.a,{href:"/building/tinyorm#build_static_drivers",children:(0,r.jsx)(i.code,{children:"build_static_drivers"})})]}),"\n",(0,r.jsxs)(i.p,{children:["To control shared and static build use ",(0,r.jsx)(i.a,{href:"/building/tinyorm#qmake-static",children:(0,r.jsx)(i.code,{children:"static"})})," ",(0,r.jsx)(i.code,{children:"qmake"})," ",(0,r.jsx)(i.a,{href:"https://doc.qt.io/qt/qmake-variable-reference.html#config",children:"configuration option"}),"."]}),"\n",(0,r.jsx)(i.h3,{id:"performance",children:"Performance"}),"\n",(0,r.jsxs)(i.p,{children:["Performance is several milliseconds faster compared to ",(0,r.jsx)(i.code,{children:"QtSql"})," with the ",(0,r.jsx)(i.code,{children:"QMYSQL"})," driver. It was tuned using the ",(0,r.jsx)(i.code,{children:"KCacheGrind"})," to be so. It's ~40ms faster on ",(0,r.jsx)(i.a,{href:"https://github.com/silverqx/TinyOrmPlayground",children:(0,r.jsx)(i.code,{children:"TinyOrmPlayground"})})," project with ",(0,r.jsx)(i.strong,{children:"620"})," database queries compiled using ",(0,r.jsx)(i.code,{children:"GCC v13.2.1"})," Debug build on Linux. Similar results can be expected on other platforms but it's not guaranteed."]}),"\n",(0,r.jsxs)(i.p,{children:["This means performance is very similar to ",(0,r.jsx)(i.code,{children:"QtSql"}),". There is not much to speed up because ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," code is swift and 90% of the time is spent inside the ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/en/",children:(0,r.jsx)(i.code,{children:"MySQL C API"})})," because we always have to wait for the database server, especially when creating database connections using eg. ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/en/mysql-real-connect.html",children:(0,r.jsx)(i.code,{children:"mysql_real_connect()"})})," (this function is king among the slowest functions \ud83d\ude0e, which is understandable of course)."]}),"\n",(0,r.jsx)(i.h2,{id:"internals",children:"Internals"}),"\n",(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," internal design can be divided into 3 different layers:"]}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsx)(i.li,{children:"Driver layer"}),"\n",(0,r.jsx)(i.li,{children:"SQL API layer"}),"\n",(0,r.jsx)(i.li,{children:"Public API layer"}),"\n"]}),"\n",(0,r.jsxs)(i.p,{children:["The Driver layer is eg. ",(0,r.jsx)(i.code,{children:"TinyMySql"})," library which is responsible for communicating with the underlying database driver (eg. ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/en/",children:(0,r.jsx)(i.code,{children:"MySQL C API"})}),")."]}),"\n",(0,r.jsx)(i.p,{children:"The SQL API layer is a semi-layer that glues everything up and sits between the Public interface API and the Driver layer."}),"\n",(0,r.jsxs)(i.p,{children:["The Public interface API layer are the end classes like ",(0,r.jsx)(i.code,{children:"SqlDatabase"})," and ",(0,r.jsx)(i.code,{children:"SqlQuery"})," which are exposed to the end user."]}),"\n",(0,r.jsx)(i.h5,{id:"sqldatabase",children:"SqlDatabase"}),"\n",(0,r.jsxs)(i.p,{children:["One more thing worth mentioning is the ",(0,r.jsx)(i.code,{children:"SqlDatabase"})," API. It's one class that has two responsibilities! All static methods act as the database connection manager and an instance of the ",(0,r.jsx)(i.code,{children:"SqlDatabase"})," represents a physical database connection. It's not a good design because it breaks the ",(0,r.jsx)(i.a,{href:"https://en.wikipedia.org/wiki/Single_responsibility_principle",children:"Single Responsibility principle"}),", but it's what it is."]}),"\n",(0,r.jsx)(i.h5,{id:"namespaces",children:"Namespaces"}),"\n",(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," classes are defined in the ",(0,r.jsx)(i.code,{children:"Orm::Drivers"})," namespace and ",(0,r.jsx)(i.code,{children:"TinyMySql"})," classes in the ",(0,r.jsx)(i.code,{children:"Orm::Drivers::MySql"})," namespace."]}),"\n",(0,r.jsx)(i.h5,{id:"documentation",children:"Documentation"}),"\n",(0,r.jsxs)(i.p,{children:["For all other APIs you can follow the ",(0,r.jsx)(i.a,{href:"https://doc.qt.io/qt/qtsql-index.html",children:"QtSql documentation"})," as the API is 1:1. The exception is of course the build system, ",(0,r.jsx)(i.code,{children:"TinyOrm"})," has its own build system that doesn't follow the ",(0,r.jsx)(i.code,{children:"QtSql"})," module."]})]})}function h(e={}){const{wrapper:i}={...(0,s.R)(),...e.components};return i?(0,r.jsx)(i,{...e,children:(0,r.jsx)(o,{...e})}):o(e)}},8453:(e,i,n)=>{n.d(i,{R:()=>t,x:()=>l});var r=n(6540);const s={},d=r.createContext(s);function t(e){const i=r.useContext(d);return r.useMemo((function(){return"function"==typeof e?e(i):{...i,...e}}),[i,e])}function l(e){let i;return i=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:t(e.components),r.createElement(d.Provider,{value:i},e.children)}}}]);
\ No newline at end of file
diff --git a/assets/js/cb1e72f9.f05e497e.js b/assets/js/cb1e72f9.f05e497e.js
new file mode 100644
index 000000000..06b0a8bde
--- /dev/null
+++ b/assets/js/cb1e72f9.f05e497e.js
@@ -0,0 +1 @@
+"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[258],{4028:(e,i,n)=>{n.r(i),n.d(i,{assets:()=>a,contentTitle:()=>t,default:()=>h,frontMatter:()=>d,metadata:()=>l,toc:()=>c});var r=n(4848),s=n(8453);const d={sidebar_position:0,sidebar_label:"Getting Started",description:"The TinyDrivers library is an underlying SQL database layer for TinyORM. It can be used instead of the QtSql module, can be swapped at compile time, and has 1:1 API as the QtSql module. Swapping is controlled by the qmake and CMake build system options. It was designed to drop the QtSql dependency while maintaining backward compatibility and without the need for any code changes after the swap.",keywords:["c++ orm","database","getting started","tinydrivers","sql drivers"]},t="TinyDrivers: Getting Started",l={id:"tinydrivers/getting-started",title:"TinyDrivers: Getting Started",description:"The TinyDrivers library is an underlying SQL database layer for TinyORM. It can be used instead of the QtSql module, can be swapped at compile time, and has 1:1 API as the QtSql module. Swapping is controlled by the qmake and CMake build system options. It was designed to drop the QtSql dependency while maintaining backward compatibility and without the need for any code changes after the swap.",source:"@site/docs/tinydrivers/getting-started.mdx",sourceDirName:"tinydrivers",slug:"/tinydrivers/getting-started",permalink:"/tinydrivers/getting-started",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"Getting Started",description:"The TinyDrivers library is an underlying SQL database layer for TinyORM. It can be used instead of the QtSql module, can be swapped at compile time, and has 1:1 API as the QtSql module. Swapping is controlled by the qmake and CMake build system options. It was designed to drop the QtSql dependency while maintaining backward compatibility and without the need for any code changes after the swap.",keywords:["c++ orm","database","getting started","tinydrivers","sql drivers"]},sidebar:"tinyormSidebar",previous:{title:"Serialization",permalink:"/tinyorm/serialization"},next:{title:"TinyORM",permalink:"/building/tinyorm"}},a={},c=[{value:"Introduction",id:"introduction",level:2},{value:"Features summary",id:"features-summary",level:5},{value:"Differences from QtSql",id:"differences-from-qtsql",level:2},{value:"Naming conventions",id:"naming-conventions",level:5},{value:"MySQL driver",id:"mysql-driver",level:5},{value:"Removed features",id:"removed-features",level:5},{value:"Missing features",id:"missing-features",level:5},{value:"Build system",id:"build-system",level:3},{value:"The Shared library build",id:"the-shared-library-build",level:5},{value:"The Static build",id:"the-static-build",level:5},{value:"The Loadable SQL drivers build",id:"the-loadable-sql-drivers-build",level:5},{value:"CMake/qmake build options",id:"cmakeqmake-build-options",level:4},{value:"For CMake",id:"for-cmake",level:5},{value:"For qmake",id:"for-qmake",level:5},{value:"Performance",id:"performance",level:3},{value:"Internals",id:"internals",level:2},{value:"SqlDatabase",id:"sqldatabase",level:5},{value:"Namespaces",id:"namespaces",level:5},{value:"Documentation",id:"documentation",level:5}];function o(e){const i={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",li:"li",p:"p",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.h1,{id:"tinydrivers-getting-started",children:"TinyDrivers: Getting Started"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsx)(i.li,{children:(0,r.jsx)(i.a,{href:"#introduction",children:"Introduction"})}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"#differences-from-qtsql",children:"Differences from QtSql"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsx)(i.li,{children:(0,r.jsx)(i.a,{href:"#build-system",children:"Build system"})}),"\n",(0,r.jsx)(i.li,{children:(0,r.jsx)(i.a,{href:"#performance",children:"Performance"})}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(i.li,{children:(0,r.jsx)(i.a,{href:"#internals",children:"Internals"})}),"\n"]}),"\n",(0,r.jsx)(i.h2,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsxs)(i.p,{children:["The ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," library is an underlying SQL database layer for ",(0,r.jsx)(i.code,{children:"TinyORM"}),". It can be used instead of the ",(0,r.jsx)(i.code,{children:"QtSql"})," module, can be ",(0,r.jsx)("u",{children:(0,r.jsx)(i.strong,{children:"swapped"})})," at compile time, and has ",(0,r.jsx)(i.strong,{children:"1:1"})," API as the ",(0,r.jsx)(i.code,{children:"QtSql"})," module. \ud83d\ude2e Swapping is controlled by the ",(0,r.jsx)(i.code,{children:"qmake"})," and ",(0,r.jsx)(i.code,{children:"CMake"})," build system options."]}),"\n",(0,r.jsxs)(i.p,{children:["It was designed to drop the ",(0,r.jsx)(i.code,{children:"QtSql"})," dependency while maintaining backward compatibility and without the need for any code changes after the swap."]}),"\n",(0,r.jsx)(i.h5,{id:"features-summary",children:"Features summary"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsx)(i.li,{children:"both, normal and prepared statements are supported"}),"\n",(0,r.jsxs)(i.li,{children:["TLS/SSL connections using ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/8.4/en/mysql-options.html",children:(0,r.jsx)(i.code,{children:"MYSQL_OPT_SSL_MODE"})})," (verify_ca, verify_identity) \ud83d\udd25"]}),"\n",(0,r.jsxs)(i.li,{children:["setting many other connection options (see ",(0,r.jsx)(i.a,{href:"https://github.com/silverqx/TinyORM/blob/main/drivers/mysql/src/orm/drivers/mysql/mysqldriver_p.cpp",children:(0,r.jsx)(i.code,{children:"mysqldriver_p.cpp"})}),")"]}),"\n",(0,r.jsxs)(i.li,{children:["building and linking against the ",(0,r.jsx)(i.a,{href:"https://mariadb.com/kb/en/mariadb-connector-c/",children:(0,r.jsx)(i.code,{children:"MariaDB Connector/C"})})]}),"\n",(0,r.jsx)(i.li,{children:"transactions"}),"\n",(0,r.jsxs)(i.li,{children:["re-using the current ",(0,r.jsx)(i.code,{children:"SqlQuery"})," instance to re-execute the same or another query"]}),"\n",(0,r.jsx)(i.li,{children:"detaching from the result set (associated to release memory)"}),"\n",(0,r.jsxs)(i.li,{children:["query size, number of affected rows, last inserted ID, testing ",(0,r.jsx)(i.code,{children:"isNull()"}),", ..."]}),"\n",(0,r.jsxs)(i.li,{children:["all ",(0,r.jsx)(i.strong,{children:"3366 unit tests"})," passed \ud83d\ude2e"]}),"\n"]}),"\n",(0,r.jsx)(i.admonition,{type:"info",children:(0,r.jsxs)(i.p,{children:["Currently, only the ",(0,r.jsx)(i.code,{children:"MySQL"})," database driver is supported and finished."]})}),"\n",(0,r.jsx)(i.admonition,{type:"info",children:(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," can only be built with ",(0,r.jsx)(i.code,{children:"Qt v6"}),", ",(0,r.jsx)(i.code,{children:"Qt v5.15"})," isn't supported."]})}),"\n",(0,r.jsx)(i.admonition,{type:"note",children:(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," library supports both build systems ",(0,r.jsx)(i.code,{children:"qmake"})," and also ",(0,r.jsx)(i.code,{children:"CMake"}),"."]})}),"\n",(0,r.jsx)(i.h2,{id:"differences-from-qtsql",children:"Differences from QtSql"}),"\n",(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," doesn't return errors the the same way as the ",(0,r.jsx)(i.code,{children:"QtSql"})," module, which means return a ",(0,r.jsx)(i.code,{children:"bool"})," and if it's the result ",(0,r.jsx)(i.code,{children:"false"})," then obtain the ",(0,r.jsx)(i.code,{children:"SqlError"})," instance using the ",(0,r.jsx)(i.code,{children:"lastError()"})," method from ",(0,r.jsx)(i.code,{children:"SqlDatabase"})," or ",(0,r.jsx)(i.code,{children:"SqlQuery"})," instances. Instead, it throws exceptions, and methods returning a ",(0,r.jsx)(i.code,{children:"bool"})," type to report an error state always return ",(0,r.jsx)(i.code,{children:"true"}),"."]}),"\n",(0,r.jsx)(i.h5,{id:"naming-conventions",children:"Naming conventions"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.code,{children:"QtSql"})," ",(0,r.jsx)("small",{children:"module"})," -> ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," ",(0,r.jsx)("small",{children:"library"})]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.code,{children:"QMYSQL"})," ",(0,r.jsx)("small",{children:"driver"})," -> ",(0,r.jsx)(i.code,{children:"TinyMySql"})," ",(0,r.jsx)("small",{children:"driver"})]}),"\n"]}),"\n",(0,r.jsx)(i.h5,{id:"mysql-driver",children:"MySQL driver"}),"\n",(0,r.jsxs)(i.p,{children:["The following describes the differences between ",(0,r.jsx)(i.code,{children:"QMYSQL"})," and ",(0,r.jsx)(i.code,{children:"TinyMySql"})," drivers."]}),"\n",(0,r.jsxs)(i.p,{children:["The ",(0,r.jsx)(i.code,{children:"QMYSQL"})," driver doesn't support setting ",(0,r.jsx)(i.code,{children:"MySQL"})," non-flag ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/8.4/en/mysql-options.html",children:"connection options"})," like ",(0,r.jsx)(i.code,{children:"MYSQL_OPT_RECONNECT"})," without the value, it needs to be defined with value like ",(0,r.jsx)(i.code,{children:"=1"})," or ",(0,r.jsx)(i.code,{children:"=TRUE"})," (case-sensitive), only real flag options like ",(0,r.jsx)(i.code,{children:"CLIENT_INTERACTIVE"})," can be set without the value and ",(0,r.jsx)(i.code,{children:"="})," character."]}),"\n",(0,r.jsxs)(i.p,{children:["On the other hand, the ",(0,r.jsx)(i.code,{children:"TinyMySql"})," driver allows setting non-flag ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/8.4/en/mysql-options.html",children:"connection options"})," options without the value and ",(0,r.jsx)(i.code,{children:"="})," character, which are considered enabled (ON or TRUE)."]}),"\n",(0,r.jsx)(i.h5,{id:"removed-features",children:"Removed features"}),"\n",(0,r.jsxs)(i.p,{children:["Simulation of prepared statements while calling ",(0,r.jsx)(i.code,{children:"SqlQuery::exec(QString)"}),", this functionality is useless because you can call regular prepared statements using ",(0,r.jsx)(i.code,{children:"SqlQuery::prepare(QString)"})," and then ",(0,r.jsx)(i.code,{children:"SqlQuery::exec()"}),"."]}),"\n",(0,r.jsx)(i.h5,{id:"missing-features",children:"Missing features"}),"\n",(0,r.jsxs)(i.p,{children:["Fetching multiple result sets using ",(0,r.jsx)(i.code,{children:"SqlQuery::nextResult()"}),". Multiple statement queries are supported they will be executed correctly (they can return multiple result sets), but only the first result set can be fetched currently. However, destroying multiple result sets is handled correctly."]}),"\n",(0,r.jsx)(i.h3,{id:"build-system",children:"Build system"}),"\n",(0,r.jsxs)(i.p,{children:["Another difference is that you can build the ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," and its SQL drivers (",(0,r.jsx)(i.code,{children:"TinyMySql"}),") in 3 different ways; ",(0,r.jsx)(i.code,{children:"Shared"}),", ",(0,r.jsx)(i.code,{children:"Static"}),", and as a ",(0,r.jsx)(i.code,{children:"Loadable"})," library at runtime using ",(0,r.jsx)(i.code,{children:"LoadLibrary()"})," on Windows or ",(0,r.jsx)(i.code,{children:"dlopen()"})," on Linux."]}),"\n",(0,r.jsxs)(i.h5,{id:"the-shared-library-build",children:["The ",(0,r.jsx)(i.code,{children:"Shared"})," library build"]}),"\n",(0,r.jsxs)(i.p,{children:["It builds two shared libraries, the ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," shared library that contains the core/common code and the ",(0,r.jsx)(i.code,{children:"TinyMySql"})," shared library that contains ",(0,r.jsx)(i.code,{children:"MySQL"})," implementation. The ",(0,r.jsx)(i.code,{children:"TinyOrm"})," links only against the ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," shared library and ",(0,r.jsx)(i.code,{children:"TinyMySql"})," is a private implementation."]}),"\n",(0,r.jsxs)(i.h5,{id:"the-static-build",children:["The ",(0,r.jsx)(i.code,{children:"Static"})," build"]}),"\n",(0,r.jsxs)(i.p,{children:["It builds one ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," static archive that contains the core/common code and SQL drivers (",(0,r.jsx)(i.code,{children:"TinyMySql"}),"). This static library is linked or merged into the ",(0,r.jsx)(i.code,{children:"TinyOrm"})," shared or static library (both variants are supported)."]}),"\n",(0,r.jsxs)(i.h5,{id:"the-loadable-sql-drivers-build",children:["The ",(0,r.jsx)(i.code,{children:"Loadable"})," SQL drivers build"]}),"\n",(0,r.jsxs)(i.p,{children:["It builds two shared libraries, the ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," shared library that contains the core/common code and ",(0,r.jsx)(i.code,{children:"TinyMySql"})," shared library (module) that contains ",(0,r.jsx)(i.code,{children:"MySQL"})," implementation that is loaded at runtime using ",(0,r.jsx)(i.code,{children:"LoadLibrary()"})," on Windows or ",(0,r.jsx)(i.code,{children:"dlopen()"})," on Linux. The SQL driver library loader throws an exception if it cannot find this library at runtime."]}),"\n",(0,r.jsx)(i.admonition,{type:"info",children:(0,r.jsxs)(i.p,{children:["The ",(0,r.jsx)(i.code,{children:"TinyMySql"})," links directly against the ",(0,r.jsx)(i.code,{children:"MySQL C connector"})," (",(0,r.jsx)(i.code,{children:"libmysql"})," or ",(0,r.jsx)(i.code,{children:"mysqlclient"})," library)."]})}),"\n",(0,r.jsxs)(i.h4,{id:"cmakeqmake-build-options",children:[(0,r.jsx)(i.code,{children:"CMake"}),"/",(0,r.jsx)(i.code,{children:"qmake"})," build options"]}),"\n",(0,r.jsxs)(i.h5,{id:"for-cmake",children:["For ",(0,r.jsx)(i.code,{children:"CMake"})]}),"\n",(0,r.jsxs)(i.p,{children:["See ",(0,r.jsx)(i.a,{href:"/building/tinyorm#cmake-build-options",children:"CMake build options"}),", related ",(0,r.jsx)(i.code,{children:"CMake"})," build options are:",(0,r.jsx)("br",{}),(0,r.jsx)(i.a,{href:"/building/tinyorm#BUILD_DRIVERS",children:(0,r.jsx)(i.code,{children:"BUILD_DRIVERS"})}),", ",(0,r.jsx)(i.a,{href:"/building/tinyorm#BUILD_MYSQL_DRIVER",children:(0,r.jsx)(i.code,{children:"BUILD_MYSQL_DRIVER"})}),", and ",(0,r.jsx)(i.a,{href:"/building/tinyorm#DRIVERS_TYPE",children:(0,r.jsx)(i.code,{children:"DRIVERS_TYPE"})})]}),"\n",(0,r.jsxs)(i.p,{children:["To control shared and static build use ",(0,r.jsx)(i.a,{href:"https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html",children:(0,r.jsx)(i.code,{children:"BUILD_SHARED_LIBS"})})," ",(0,r.jsx)(i.code,{children:"CMake"})," configuration option."]}),"\n",(0,r.jsxs)(i.h5,{id:"for-qmake",children:["For ",(0,r.jsx)(i.code,{children:"qmake"})]}),"\n",(0,r.jsxs)(i.p,{children:["See ",(0,r.jsx)(i.a,{href:"/building/tinyorm#qmake-build-options",children:"qmake build options"}),", related ",(0,r.jsx)(i.code,{children:"qmake"})," configuration options are:",(0,r.jsx)("br",{}),(0,r.jsx)(i.a,{href:"/building/tinyorm#build_loadable_drivers",children:(0,r.jsx)(i.code,{children:"build_loadable_drivers"})}),", ",(0,r.jsx)(i.a,{href:"/building/tinyorm#build_mysql_driver",children:(0,r.jsx)(i.code,{children:"build_mysql_driver"})}),", ",(0,r.jsx)(i.a,{href:"/building/tinyorm#build_shared_drivers",children:(0,r.jsx)(i.code,{children:"build_shared_drivers"})}),", and ",(0,r.jsx)(i.a,{href:"/building/tinyorm#build_static_drivers",children:(0,r.jsx)(i.code,{children:"build_static_drivers"})})]}),"\n",(0,r.jsxs)(i.p,{children:["To control shared and static build use ",(0,r.jsx)(i.a,{href:"/building/tinyorm#qmake-static",children:(0,r.jsx)(i.code,{children:"static"})})," ",(0,r.jsx)(i.code,{children:"qmake"})," ",(0,r.jsx)(i.a,{href:"https://doc.qt.io/qt/qmake-variable-reference.html#config",children:"configuration option"}),"."]}),"\n",(0,r.jsx)(i.h3,{id:"performance",children:"Performance"}),"\n",(0,r.jsxs)(i.p,{children:["Performance is several milliseconds faster compared to ",(0,r.jsx)(i.code,{children:"QtSql"})," with the ",(0,r.jsx)(i.code,{children:"QMYSQL"})," driver. It was tuned using the ",(0,r.jsx)(i.code,{children:"KCacheGrind"})," to be so. It's ~40ms faster on ",(0,r.jsx)(i.a,{href:"https://github.com/silverqx/TinyOrmPlayground",children:(0,r.jsx)(i.code,{children:"TinyOrmPlayground"})})," project with ",(0,r.jsx)(i.strong,{children:"620"})," database queries compiled using ",(0,r.jsx)(i.code,{children:"GCC v13.2.1"})," Debug build on Linux. Similar results can be expected on other platforms but it's not guaranteed."]}),"\n",(0,r.jsxs)(i.p,{children:["This means performance is very similar to ",(0,r.jsx)(i.code,{children:"QtSql"}),". There is not much to speed up because ",(0,r.jsx)(i.code,{children:"TinyDrivers"})," code is swift and 90% of the time is spent inside the ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/8.4/en/",children:(0,r.jsx)(i.code,{children:"MySQL C API"})})," because we always have to wait for the database server, especially when creating database connections using eg. ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/8.4/en/mysql-real-connect.html",children:(0,r.jsx)(i.code,{children:"mysql_real_connect()"})})," (this function is king among the slowest functions \ud83d\ude0e, which is understandable of course)."]}),"\n",(0,r.jsx)(i.h2,{id:"internals",children:"Internals"}),"\n",(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," internal design can be divided into 3 different layers:"]}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsx)(i.li,{children:"Driver layer"}),"\n",(0,r.jsx)(i.li,{children:"SQL API layer"}),"\n",(0,r.jsx)(i.li,{children:"Public API layer"}),"\n"]}),"\n",(0,r.jsxs)(i.p,{children:["The Driver layer is eg. ",(0,r.jsx)(i.code,{children:"TinyMySql"})," library which is responsible for communicating with the underlying database driver (eg. ",(0,r.jsx)(i.a,{href:"https://dev.mysql.com/doc/c-api/8.4/en/",children:(0,r.jsx)(i.code,{children:"MySQL C API"})}),")."]}),"\n",(0,r.jsx)(i.p,{children:"The SQL API layer is a semi-layer that glues everything up and sits between the Public interface API and the Driver layer."}),"\n",(0,r.jsxs)(i.p,{children:["The Public interface API layer are the end classes like ",(0,r.jsx)(i.code,{children:"SqlDatabase"})," and ",(0,r.jsx)(i.code,{children:"SqlQuery"})," which are exposed to the end user."]}),"\n",(0,r.jsx)(i.h5,{id:"sqldatabase",children:"SqlDatabase"}),"\n",(0,r.jsxs)(i.p,{children:["One more thing worth mentioning is the ",(0,r.jsx)(i.code,{children:"SqlDatabase"})," API. It's one class that has two responsibilities! All static methods act as the database connection manager and an instance of the ",(0,r.jsx)(i.code,{children:"SqlDatabase"})," represents a physical database connection. It's not a good design because it breaks the ",(0,r.jsx)(i.a,{href:"https://en.wikipedia.org/wiki/Single_responsibility_principle",children:"Single Responsibility principle"}),", but it's what it is."]}),"\n",(0,r.jsx)(i.h5,{id:"namespaces",children:"Namespaces"}),"\n",(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.code,{children:"TinyDrivers"})," classes are defined in the ",(0,r.jsx)(i.code,{children:"Orm::Drivers"})," namespace and ",(0,r.jsx)(i.code,{children:"TinyMySql"})," classes in the ",(0,r.jsx)(i.code,{children:"Orm::Drivers::MySql"})," namespace."]}),"\n",(0,r.jsx)(i.h5,{id:"documentation",children:"Documentation"}),"\n",(0,r.jsxs)(i.p,{children:["For all other APIs you can follow the ",(0,r.jsx)(i.a,{href:"https://doc.qt.io/qt/qtsql-index.html",children:"QtSql documentation"})," as the API is 1:1. The exception is of course the build system, ",(0,r.jsx)(i.code,{children:"TinyOrm"})," has its own build system that doesn't follow the ",(0,r.jsx)(i.code,{children:"QtSql"})," module."]})]})}function h(e={}){const{wrapper:i}={...(0,s.R)(),...e.components};return i?(0,r.jsx)(i,{...e,children:(0,r.jsx)(o,{...e})}):o(e)}},8453:(e,i,n)=>{n.d(i,{R:()=>t,x:()=>l});var r=n(6540);const s={},d=r.createContext(s);function t(e){const i=r.useContext(d);return r.useMemo((function(){return"function"==typeof e?e(i):{...i,...e}}),[i,e])}function l(e){let i;return i=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:t(e.components),r.createElement(d.Provider,{value:i},e.children)}}}]);
\ No newline at end of file
diff --git a/assets/js/cbe663fe.ff133091.js b/assets/js/cbe663fe.160e49aa.js
similarity index 99%
rename from assets/js/cbe663fe.ff133091.js
rename to assets/js/cbe663fe.160e49aa.js
index f7fb97062..3701384b7 100644
--- a/assets/js/cbe663fe.ff133091.js
+++ b/assets/js/cbe663fe.160e49aa.js
@@ -1 +1 @@
-"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[995],{4380:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>u,frontMatter:()=>i,metadata:()=>d,toc:()=>c});var r=s(4848),t=s(8453),a=s(8774);const i={sidebar_position:1,sidebar_label:"Query Builder",description:"TinyORM's database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application. The query builder uses QSqlQuery parameter binding to protect your application against SQL injection attacks. There is no need to clean or sanitize strings passed to the query builder as query bindings.",keywords:["c++ orm","sql","c++ sql","c++ query builder","database","query builder","tinyorm"]},o="Database: Query Builder",d={id:"database/query-builder",title:"Database: Query Builder",description:"TinyORM's database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application. The query builder uses QSqlQuery parameter binding to protect your application against SQL injection attacks. There is no need to clean or sanitize strings passed to the query builder as query bindings.",source:"@site/docs/database/query-builder.mdx",sourceDirName:"database",slug:"/database/query-builder",permalink:"/database/query-builder",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:1,frontMatter:{sidebar_position:1,sidebar_label:"Query Builder",description:"TinyORM's database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application. The query builder uses QSqlQuery parameter binding to protect your application against SQL injection attacks. There is no need to clean or sanitize strings passed to the query builder as query bindings.",keywords:["c++ orm","sql","c++ sql","c++ query builder","database","query builder","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Getting Started",permalink:"/database/getting-started"},next:{title:"Migrations",permalink:"/database/migrations"}},l={},c=[{value:"Introduction",id:"introduction",level:2},{value:"Running Database Queries",id:"running-database-queries",level:2},{value:"Retrieving All Rows From A Table",id:"retrieving-all-rows-from-a-table",level:4},{value:"Retrieving A Single Row / Column From A Table",id:"retrieving-a-single-row--column-from-a-table",level:4},{value:"Retrieving A List Of Column Values",id:"retrieving-a-list-of-column-values",level:4},{value:"Concatenate column values",id:"concatenate-column-values",level:4},{value:"Chunking Results",id:"chunking-results",level:3},{value:"Aggregates",id:"aggregates",level:3},{value:"Determining If Records Exist",id:"determining-if-records-exist",level:4},{value:"Select Statements",id:"select-statements",level:2},{value:"Specifying A Select Clause",id:"specifying-a-select-clause",level:4},{value:"Raw Expressions",id:"raw-expressions",level:2},{value:"Raw Methods",id:"raw-methods",level:3},{value:"selectRaw",id:"selectraw",level:4},{value:"fromRaw",id:"fromraw",level:4},{value:"whereRaw / orWhereRaw",id:"whereraw--orwhereraw",level:4},{value:"groupByRaw",id:"groupbyraw",level:3},{value:"havingRaw / orHavingRaw",id:"havingraw--orhavingraw",level:4},{value:"orderByRaw",id:"orderbyraw",level:4},{value:"Joins",id:"joins",level:2},{value:"Inner Join Clause",id:"inner-join-clause",level:4},{value:"Left Join / Right Join Clause",id:"left-join--right-join-clause",level:4},{value:"Cross Join Clause",id:"cross-join-clause",level:4},{value:"Advanced Join Clauses",id:"advanced-join-clauses",level:4},{value:"Subquery Joins",id:"subquery-joins",level:4},{value:"Basic Where Clauses",id:"basic-where-clauses",level:2},{value:"Where Clauses",id:"where-clauses",level:3},{value:"Or Where Clauses",id:"or-where-clauses",level:3},{value:"Condition Operator Overriding",id:"condition-operator-overriding",level:3},{value:"Where Not Clauses",id:"where-not-clauses",level:3},{value:"Additional Where Clauses",id:"additional-where-clauses",level:3},{value:"Logical Grouping",id:"logical-grouping",level:3},{value:"Advanced Where Clauses",id:"advanced-where-clauses",level:2},{value:"Where Exists Clauses",id:"where-exists-clauses",level:3},{value:"Subquery Where Clauses",id:"subquery-where-clauses",level:3},{value:"Ordering, Grouping, Limit & Offset",id:"ordering-grouping-limit-and-offset",level:2},{value:"Ordering",id:"ordering",level:3},{value:"The orderBy Method",id:"the-orderby-method",level:4},{value:"The latest & oldest Methods",id:"the-latest--oldest-methods",level:4},{value:"Random Ordering",id:"random-ordering",level:4},{value:"Removing Existing Orderings",id:"removing-existing-orderings",level:4},{value:"Grouping",id:"grouping",level:3},{value:"The groupBy & having Methods",id:"the-groupby--having-methods",level:4},{value:"Limit & Offset",id:"limit-and-offset",level:3},{value:"The skip & take Methods",id:"the-skip--take-methods",level:4},{value:"Insert Statements",id:"insert-statements",level:2},{value:"Auto-Incrementing IDs",id:"auto-incrementing-ids",level:4},{value:"Upserts",id:"upserts",level:3},{value:"Update Statements",id:"update-statements",level:2},{value:"Update Or Insert",id:"update-or-insert",level:4},{value:"Increment & Decrement",id:"increment-and-decrement",level:3},{value:"Delete Statements",id:"delete-statements",level:2},{value:"Truncate Statement",id:"truncate-statement",level:3},{value:"Table Truncation & PostgreSQL",id:"table-truncation--postgresql",level:4},{value:"Pessimistic Locking",id:"pessimistic-locking",level:2},{value:"Debugging",id:"debugging",level:2}];function h(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h1,{id:"database-query-builder",children:"Database: Query Builder"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#introduction",children:"Introduction"})}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"#running-database-queries",children:"Running Database Queries"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#chunking-results",children:"Chunking Results"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#aggregates",children:"Aggregates"})}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#select-statements",children:"Select Statements"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#raw-expressions",children:"Raw Expressions"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#joins",children:"Joins"})}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"#basic-where-clauses",children:"Basic Where Clauses"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#where-clauses",children:"Where Clauses"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#or-where-clauses",children:"Or Where Clauses"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#where-not-clauses",children:"Where Not Clauses"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#additional-where-clauses",children:"Additional Where Clauses"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#condition-operator-overriding",children:"Condition Operator Overriding"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#logical-grouping",children:"Logical Grouping"})}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"#advanced-where-clauses",children:"Advanced Where Clauses"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#where-exists-clauses",children:"Where Exists Clauses"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#subquery-where-clauses",children:"Subquery Where Clauses"})}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"#ordering-grouping-limit-and-offset",children:"Ordering, Grouping, Limit & Offset"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#ordering",children:"Ordering"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#grouping",children:"Grouping"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#limit-and-offset",children:"Limit & Offset"})}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"#insert-statements",children:"Insert Statements"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#upserts",children:"Upserts"})}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"#update-statements",children:"Update Statements"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#increment-and-decrement",children:"Increment & Decrement"})}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"#delete-statements",children:"Delete Statements"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#truncate-statement",children:"Truncate Statement"})}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#pessimistic-locking",children:"Pessimistic Locking"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"#debugging",children:"Debugging"})}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,r.jsx)(n.p,{children:"TinyORM's database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application."}),"\n",(0,r.jsxs)(n.p,{children:["The TinyORM query builder uses ",(0,r.jsx)(n.code,{children:"QSqlQuery"})," parameter binding to protect your application against SQL injection attacks. There is no need to clean or sanitize strings passed to the query builder as query bindings."]}),"\n",(0,r.jsx)(n.admonition,{type:"danger",children:(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"QSqlQuery"}),' does not support binding column names. Therefore, you should never allow user input to dictate the column names referenced by your queries, including "order by" columns.']})}),"\n",(0,r.jsx)(n.admonition,{type:"danger",children:(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"QMYSQL"})," Qt driver contains a bug, if your table contains a ",(0,r.jsx)(n.code,{children:"json"})," column type, then you must explicitly name columns other than ",(0,r.jsx)(n.code,{children:"json"})," columns instead of the ",(0,r.jsx)(n.code,{children:"*"})," shorthand, otherwise, you will get an empty result, or all column values will be invalid QVariant-s, or it may even return half of the columns. The ",(0,r.jsx)(n.code,{children:"QPSQL"})," driver returns correct results and doesn't have problem with ",(0,r.jsx)(n.code,{children:"json"})," columns. It was fixed in the Qt 5.15.12, 6.2.7, 6.5.0 ",(0,r.jsx)(n.a,{href:"https://bugreports.qt.io/browse/QTBUG-101680",children:"QTBUG-101680"}),"."]})}),"\n",(0,r.jsx)(n.h2,{id:"running-database-queries",children:"Running Database Queries"}),"\n",(0,r.jsx)(n.h4,{id:"retrieving-all-rows-from-a-table",children:"Retrieving All Rows From A Table"}),"\n",(0,r.jsxs)(n.p,{children:["You may use the ",(0,r.jsx)(n.code,{children:"table"})," method provided by the ",(0,r.jsx)(n.code,{children:"DB"})," facade to begin a query. The ",(0,r.jsx)(n.code,{children:"table"})," method returns a fluent query builder instance for the given table, allowing you to chain more constraints onto the query and then finally retrieve the results of the query using the ",(0,r.jsx)(n.code,{children:"get"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include \n\n// Log a list of all of the application\'s users\nauto query = DB::table("users")->get();\n\nwhile (query.next())\n qDebug() << "id :" << query.value("id").toULongLong() << ";"\n << "name :" << query.value("name").toString();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"get"})," method returns a ",(0,r.jsx)(n.code,{children:"QSqlQuery"})," containing the results of the query where each result can be accessed by ",(0,r.jsx)(n.code,{children:"QSqlQuery::next"})," method, look into the ",(0,r.jsx)(n.code,{children:"QSqlQuery"}),' documentation how to obtain results from the "query". You may access each column\'s value by ',(0,r.jsx)(n.code,{children:"QSqlQuery::value"})," method. The first ",(0,r.jsx)(n.code,{children:"bool"})," return value is the value returned from ",(0,r.jsx)(n.code,{children:"QSqlQuery::exec"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include \n\nauto users = DB::table("users")->get();\n\nwhile(users.next())\n qDebug() << users.value("name").toString();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"retrieving-a-single-row--column-from-a-table",children:"Retrieving A Single Row / Column From A Table"}),"\n",(0,r.jsxs)(n.p,{children:["If you just need to retrieve a single row from a database table, you may use the ",(0,r.jsx)(n.code,{children:"QueryBuilder::first"})," method. This method will return a ",(0,r.jsx)(n.code,{children:"QSqlQuery"})," object, on which was internally called ",(0,r.jsx)(n.code,{children:"QSqlQuery::first"})," method. This method retrieves the first record in the result, if available, and positions the query on the retrieved record:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto user = DB::table("users")->whereEq("name", "John").first();\n\nuser.value("email").toString();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["If you don't need an entire row, you may extract a single value from a record using the ",(0,r.jsx)(n.code,{children:"value"})," method. This method will return the value of the column directly as ",(0,r.jsx)(n.code,{children:"QVariant"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto email = DB::table("users")->whereEq("name", "John").value("email").toString();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["To retrieve a single row by its ",(0,r.jsx)(n.code,{children:"id"})," column value, use the ",(0,r.jsx)(n.code,{children:"find"})," method. This method retrieves the first record in the result, if available, and positions the query on the retrieved record:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto user = DB::table("users")->find(3);\n\nuser.value("email").toString();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"retrieving-a-list-of-column-values",children:"Retrieving A List Of Column Values"}),"\n",(0,r.jsxs)(n.p,{children:["If you would like to retrieve the ",(0,r.jsx)(n.code,{children:"QVector"})," instance containing the values of a single column, you may use the ",(0,r.jsx)(n.code,{children:"pluck"})," method. In this example, we'll retrieve a collection of user titles:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include \n\n#include \n\nconst auto titles = DB::table("users")->pluck("title");\n\nfor (const auto &title : titles)\n qDebug() << title.value();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may specify the column that the resulting collection should use as its keys by providing a second argument to the ",(0,r.jsx)(n.code,{children:"pluck"})," method, following example returns the ",(0,r.jsx)(n.code,{children:"std::map"}),' of "titles" keyed by "names":']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto titles = DB::table("users")->pluck("title", "name");\n\nfor (auto &&[name, title] : titles)\n qDebug() << name << ":" << title.value();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may also use ",(0,r.jsx)(n.code,{children:'pluck("name", "id")'}),", it returns the ",(0,r.jsx)(n.code,{children:"std::map"}),' of "names" keyed by its "ids".']}),"\n",(0,r.jsx)(n.admonition,{type:"note",children:(0,r.jsxs)(n.p,{children:["This second ",(0,r.jsx)(n.code,{children:"pluck"})," overload returns ",(0,r.jsx)(n.code,{children:"std::map"})," so you have to provide a template argument for the key type."]})}),"\n",(0,r.jsx)(n.h4,{id:"concatenate-column-values",children:"Concatenate column values"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"implode"})," method can be used to join column values. For example, you may use this method to concatenate prices with the ",(0,r.jsx)(n.code,{children:", "})," character as the glue:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("orders")->where("price", ">", 100).implode("price", ", ");\n'})}),"\n",(0,r.jsx)(n.h3,{id:"chunking-results",children:"Chunking Results"}),"\n",(0,r.jsxs)(n.p,{children:["If you need to work with thousands of database records, consider using the ",(0,r.jsx)(n.code,{children:"chunk"})," method provided by the ",(0,r.jsx)(n.code,{children:"DB"})," facade. This method retrieves a small chunk of results at a time and feeds each chunk into a lambda expression for processing. For example, let's retrieve the entire ",(0,r.jsx)(n.code,{children:"users"})," table in chunks of 100 records at a time:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")->orderBy("id").chunk(100, [](QSqlQuery &users, const int page)\n{\n while (users.next()) {\n //\n }\n\n return true;\n});\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may stop further chunks from being processed by returning ",(0,r.jsx)(n.code,{children:"false"})," from the closure:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")->orderBy("id").chunk(100, [](QSqlQuery &users, const int page)\n{\n // Process the records...\n\n return false;\n});\n'})}),"\n",(0,r.jsxs)(n.p,{children:["If you are updating database records while chunking results, your chunk results could change in unexpected ways. If you plan to update the retrieved records while chunking, it is always best to use the ",(0,r.jsx)(n.code,{children:"chunkById"})," method instead. This method will automatically paginate the results based on the record's primary key:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")\n ->whereEq("active", false)\n .orderBy("id")\n .chunkById(100, [](QSqlQuery &users, const int /*unused*/)\n {\n while (users.next())\n DB::table("users")\n ->whereEq("id", users.value("id"))\n .update({{"active", true}});\n\n return true;\n });\n'})}),"\n",(0,r.jsx)(n.admonition,{type:"caution",children:(0,r.jsxs)(n.p,{children:["When updating or deleting records inside the chunk lambda expression, any changes to the primary key or foreign keys could affect the chunk query. This could potentially result in records not being included in the chunked results, it can be avoided using the ",(0,r.jsx)(n.code,{children:"chunkById"})," method."]})}),"\n",(0,r.jsx)(n.h3,{id:"aggregates",children:"Aggregates"}),"\n",(0,r.jsxs)(n.p,{children:["The query builder also provides a variety of methods for retrieving aggregate values like ",(0,r.jsx)(n.code,{children:"count"}),", ",(0,r.jsx)(n.code,{children:"max"}),", ",(0,r.jsx)(n.code,{children:"min"}),", ",(0,r.jsx)(n.code,{children:"avg"}),", and ",(0,r.jsx)(n.code,{children:"sum"}),". You may call any of these methods after constructing your query:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto users = DB::table("users")->count();\n\nauto price = DB::table("orders")->max("price");\n'})}),"\n",(0,r.jsx)(n.p,{children:"Of course, you may combine these methods with other clauses to fine-tune how your aggregate value is calculated:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto price = DB::table("orders")\n ->whereEq("finalized", 1)\n .avg("price");\n'})}),"\n",(0,r.jsx)(n.h4,{id:"determining-if-records-exist",children:"Determining If Records Exist"}),"\n",(0,r.jsxs)(n.p,{children:["Instead of using the ",(0,r.jsx)(n.code,{children:"count"})," method to determine if any records exist that match your query's constraints, you may use the ",(0,r.jsx)(n.code,{children:"exists"})," and ",(0,r.jsx)(n.code,{children:"doesntExist"})," methods:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'if (DB::table("orders")->whereEq("finalized", 1).exists()) {\n // ...\n}\n\nif (DB::table("orders")->whereEq("finalized", 1).doesntExist()) {\n // ...\n}\n'})}),"\n",(0,r.jsx)(n.h2,{id:"select-statements",children:"Select Statements"}),"\n",(0,r.jsx)(n.h4,{id:"specifying-a-select-clause",children:"Specifying A Select Clause"}),"\n",(0,r.jsxs)(n.p,{children:["You may not always want to select all columns from a database table. Using the ",(0,r.jsx)(n.code,{children:"select"}),' method, you can specify a custom "select" clause for the query:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto users = DB::table("users")\n ->select({"name", "email as user_email"})\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"distinct"})," method allows you to force the query to return distinct results:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")->distinct().get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["If you already have a query builder instance and you wish to add a column to its existing select clause, you may use the ",(0,r.jsx)(n.code,{children:"addSelect"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto query = DB::table("users")->select("name");\n\nauto users = query.addSelect("age").get();\n'})}),"\n",(0,r.jsx)(n.admonition,{type:"note",children:(0,r.jsxs)(n.p,{children:["You can also pass subqueries to the ",(0,r.jsx)(n.code,{children:"select"})," and ",(0,r.jsx)(n.code,{children:"addSelect"})," methods. A subquery can be a lambda expression, raw string, or the ",(0,r.jsx)(n.code,{children:"QueryBuilder"})," instance."]})}),"\n",(0,r.jsx)(n.h2,{id:"raw-expressions",children:"Raw Expressions"}),"\n",(0,r.jsxs)(n.p,{children:["Sometimes you may need to insert an arbitrary string into a query. To create a raw string expression, you may use the ",(0,r.jsx)(n.code,{children:"raw"})," method provided by the ",(0,r.jsx)(n.code,{children:"DB"})," facade:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->select(DB::raw("count(*) as user_count, status"))\n .where("status", "<>", 1)\n .groupBy("status")\n .get();\n'})}),"\n",(0,r.jsx)(n.admonition,{type:"danger",children:(0,r.jsx)(n.p,{children:"Raw statements will be injected into the query as strings, so you should be extremely careful to avoid creating SQL injection vulnerabilities."})}),"\n",(0,r.jsx)(n.h3,{id:"raw-methods",children:"Raw Methods"}),"\n",(0,r.jsxs)(n.p,{children:["Instead of using the ",(0,r.jsx)(n.code,{children:"DB::raw"})," method, you may also use the following methods to insert a raw expression into various parts of your query. ",(0,r.jsx)(n.strong,{children:"Remember, TinyORM can not guarantee that any query using raw expressions is protected against SQL injection vulnerabilities."})]}),"\n",(0,r.jsx)(n.h4,{id:"selectraw",children:(0,r.jsx)(n.code,{children:"selectRaw"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"selectRaw"})," method can be used in place of ",(0,r.jsx)(n.code,{children:"addSelect(DB::raw(...))"}),". This method accepts an optional vector of bindings as its second argument:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto orders = DB::table("orders")\n ->selectRaw("price * ? as price_with_tax", {1.0825})\n .get();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"fromraw",children:(0,r.jsx)(n.code,{children:"fromRaw"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"fromRaw"}),' method may be used to provide a raw string as the value of the "from" clause:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::connection("postgres").query()\n ->fromRaw("(select id, name from users where id < ?) as u", {5})\n .where("id", "<", 3)\n .get();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"whereraw--orwhereraw",children:(0,r.jsx)(n.code,{children:"whereRaw / orWhereRaw"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereRaw"})," and ",(0,r.jsx)(n.code,{children:"orWhereRaw"}),' methods can be used to inject a raw "where" clause into your query. These methods accept an optional vector of bindings as their second argument:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto orders = DB::table("orders")\n ->whereRaw("price > IF(state = \\"TX\\", ?, 100)", {200})\n .get();\n'})}),"\n",(0,r.jsx)(n.h3,{id:"groupbyraw",children:(0,r.jsx)(n.code,{children:"groupByRaw"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"groupByRaw"})," method may be used to provide a raw string as the value of the ",(0,r.jsx)(n.code,{children:"group by"})," clause:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto orders = DB::table("orders")\n ->select({"city", "state"})\n .groupByRaw("city, state")\n .get();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"havingraw--orhavingraw",children:(0,r.jsx)(n.code,{children:"havingRaw / orHavingRaw"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"havingRaw"})," and ",(0,r.jsx)(n.code,{children:"orHavingRaw"}),' methods may be used to provide a raw string as the value of the "having" clause. These methods accept an optional vector of bindings as their second argument:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto orders = DB::table("orders")\n ->select({"department", DB::raw("SUM(price) as total_sales")})\n .groupBy("department")\n .havingRaw("SUM(price) > ?", {2500})\n .get();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"orderbyraw",children:(0,r.jsx)(n.code,{children:"orderByRaw"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"orderByRaw"}),' method may be used to provide a raw string as the value of the "order by" clause:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto orders = DB::table("orders")\n ->orderByRaw("updated_at - created_at DESC")\n .get();\n'})}),"\n",(0,r.jsx)(n.h2,{id:"joins",children:"Joins"}),"\n",(0,r.jsx)(n.h4,{id:"inner-join-clause",children:"Inner Join Clause"}),"\n",(0,r.jsxs)(n.p,{children:['The query builder may also be used to add join clauses to your queries. To perform a basic "inner join", you may use the ',(0,r.jsx)(n.code,{children:"join"})," method on a query builder instance. The first argument passed to the ",(0,r.jsx)(n.code,{children:"join"})," method is the name of the table you need to join to, while the remaining arguments specify the column constraints for the join. You may even join multiple tables in a single query:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include \n\nauto users = DB::table("users")\n ->join("contacts", "users.id", "=", "contacts.user_id")\n .join("orders", "users.id", "=", "orders.user_id")\n .select({"users.*", "contacts.phone", "orders.price"})\n .get();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"left-join--right-join-clause",children:"Left Join / Right Join Clause"}),"\n",(0,r.jsxs)(n.p,{children:['If you would like to perform a "left join" or "right join" instead of an "inner join", use the ',(0,r.jsx)(n.code,{children:"leftJoin"})," or ",(0,r.jsx)(n.code,{children:"rightJoin"})," methods. These methods have the same signature as the ",(0,r.jsx)(n.code,{children:"join"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->leftJoin("posts", "users.id", "=", "posts.user_id")\n .get();\n\nauto users = DB::table("users")\n ->rightJoin("posts", "users.id", "=", "posts.user_id")\n .get();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"cross-join-clause",children:"Cross Join Clause"}),"\n",(0,r.jsxs)(n.p,{children:["You may use the ",(0,r.jsx)(n.code,{children:"crossJoin"}),' method to perform a "cross join". Cross joins generate a cartesian product between the first table and the joined table:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto sizes = DB::table("sizes")\n ->crossJoin("colors")\n .get();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"advanced-join-clauses",children:"Advanced Join Clauses"}),"\n",(0,r.jsxs)(n.p,{children:["You may also specify more advanced join clauses. To get started, pass a lambda expression as the second argument to the ",(0,r.jsx)(n.code,{children:"join"})," method. The lambda expression will receive a ",(0,r.jsx)(n.code,{children:"Orm::Query::JoinClause"}),' instance which allows you to specify constraints on the "join" clause:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include \n#include \n\nDB::table("users")\n ->join("contacts", [](auto &join)\n {\n join.on("users.id", "=", "contacts.user_id")\n .orOn(...);\n })\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:['If you would like to use a "where" clause on your joins, you may use the ',(0,r.jsx)(n.code,{children:"where"})," and ",(0,r.jsx)(n.code,{children:"orWhere"})," methods provided by the ",(0,r.jsx)(n.code,{children:"Orm::Query::JoinClause"})," instance. Instead of comparing two columns, these methods will compare the column against a value:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")\n ->join("contacts", [](auto &join)\n {\n join.on("users.id", "=", "contacts.user_id")\n .where("contacts.user_id", ">", 5);\n })\n .get();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"subquery-joins",children:"Subquery Joins"}),"\n",(0,r.jsxs)(n.p,{children:["You may use the ",(0,r.jsx)(n.code,{children:"joinSub"}),", ",(0,r.jsx)(n.code,{children:"leftJoinSub"}),", and ",(0,r.jsx)(n.code,{children:"rightJoinSub"})," methods to join a query to a subquery. Each of these methods receives three arguments: the subquery, its table alias, and a lambda expression that defines the related columns. In this example, we will retrieve a collection of users where each user record also contains the ",(0,r.jsx)(n.code,{children:"created_at"})," timestamp of the user's most recently published blog post:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto latestPosts = DB::table("posts")\n ->select({"user_id", DB::raw("MAX(created_at) as last_post_created_at")})\n .whereEq("is_published", true)\n .groupBy("user_id");\n\nauto users = DB::table("users")\n ->joinSub(latestPosts, "latest_posts", [](auto &join)\n {\n join.on("users.id", "=", "latest_posts.user_id");\n }).get();\n'})}),"\n",(0,r.jsx)(n.h2,{id:"basic-where-clauses",children:"Basic Where Clauses"}),"\n",(0,r.jsx)(n.h3,{id:"where-clauses",children:"Where Clauses"}),"\n",(0,r.jsxs)(n.p,{children:["You may use the query builder's ",(0,r.jsx)(n.code,{children:"where"}),' method to add "where" clauses to the query. The most basic call to the ',(0,r.jsx)(n.code,{children:"where"})," method requires three arguments. The first argument is the name of the column. The second argument is an operator, which can be any of the database's supported operators. The third argument is the value to compare against the column's value."]}),"\n",(0,r.jsxs)(n.p,{children:["For example, the following query retrieves users where the value of the ",(0,r.jsx)(n.code,{children:"votes"})," column is equal to ",(0,r.jsx)(n.code,{children:"100"})," and the value of the ",(0,r.jsx)(n.code,{children:"age"})," column is greater than ",(0,r.jsx)(n.code,{children:"35"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where("votes", "=", 100)\n .where("age", ">", 35)\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["For convenience, if you want to verify that a column is ",(0,r.jsx)(n.code,{children:"="})," to a given value, you may call ",(0,r.jsx)(n.code,{children:"whereEq"})," method. Similar ",(0,r.jsx)(n.code,{children:"XxxEq"})," methods are also defined for other commands:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")->whereEq("votes", 100).get();\n'})}),"\n",(0,r.jsx)(n.p,{children:"As previously mentioned, you may use any operator that is supported by your database system:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where("votes", ">=", 100)\n .get();\n\nauto users = DB::table("users")\n ->where("votes", "<>", 100)\n .get();\n\nauto users = DB::table("users")\n ->where("name", "like", "T%")\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may also pass a ",(0,r.jsx)(n.code,{children:"QVector"})," of conditions to the ",(0,r.jsx)(n.code,{children:"where"})," function. Each ",(0,r.jsx)(n.code,{children:"Orm::WhereItem"})," structure should contain the four arguments typically passed to the ",(0,r.jsx)(n.code,{children:"where"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where({\n {"status", 1}, // "=" by default\n {"subscribed", 1, "<>"},\n }).get();\n'})}),"\n",(0,r.jsx)(n.h3,{id:"or-where-clauses",children:"Or Where Clauses"}),"\n",(0,r.jsxs)(n.p,{children:["When chaining together calls to the query builder's ",(0,r.jsx)(n.code,{children:"where"}),' method, the "where" clauses will be joined together using the ',(0,r.jsx)(n.code,{children:"and"})," operator. However, you may use the ",(0,r.jsx)(n.code,{children:"orWhere"})," or ",(0,r.jsx)(n.code,{children:"orWhereEq"})," method to join a clause to the query using the ",(0,r.jsx)(n.code,{children:"or"})," operator. The ",(0,r.jsx)(n.code,{children:"orWhere"})," method accepts the same arguments as the ",(0,r.jsx)(n.code,{children:"where"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where("votes", ">", 100)\n .orWhere("name", "=", "John")\n .orWhereEq("name", "Jack")\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:['If you need to group an "or" condition within parentheses, you may pass a lambda expression as the first argument to the ',(0,r.jsx)(n.code,{children:"orWhere"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where("votes", ">", 100)\n .orWhere([](auto &query)\n {\n query.whereEq("name", "Abigail")\n .where("votes", ">", 50);\n })\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:"The example above will produce the following SQL:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-sql",children:'select * from users where votes > 100 or (name = "Abigail" and votes > 50)\n'})}),"\n",(0,r.jsx)(n.h3,{id:"condition-operator-overriding",children:"Condition Operator Overriding"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"where"})," method overload with a ",(0,r.jsx)(n.code,{children:"QVector"})," as the first argument joins conditions using the ",(0,r.jsx)(n.code,{children:"and"})," operator by default:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"votes", 50, ">"},\n }).get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Conditions operator can be overridden by the fourth argument in the ",(0,r.jsx)(n.code,{children:"Orm::WhereItem"})," structure:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"votes", 50, ">", "or"},\n }).get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Or by the second ",(0,r.jsx)(n.code,{children:"where"})," argument, in this case all conditions will be joined by this condition, but it is still possible to override them by the fourth argument in the ",(0,r.jsx)(n.code,{children:"Orm::WhereItem"})," structure:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"last_name", "Smith"},\n {"votes", 50, ">", "and"},\n }, "or")\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:"The example above will produce the following SQL:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-sql",children:'select * from users where (first_name = "John" or last_name = "Smith" and votes > 50)\n'})}),"\n",(0,r.jsx)(n.admonition,{type:"tip",children:(0,r.jsxs)(n.p,{children:["Still, it is a better idea to use ",(0,r.jsx)(n.a,{href:"#logical-grouping",children:"Logical Grouping"})," described few lines below, which allows better control of the parentheses."]})}),"\n",(0,r.jsx)(n.h3,{id:"where-not-clauses",children:"Where Not Clauses"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereNot"})," and ",(0,r.jsx)(n.code,{children:"orWhereNot"})," methods may be used to negate a given group of query constraints. For example, the following query excludes products that are on clearance or which have a price that is less than ten:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto products = DB::table("products")\n ->whereNot([](auto &query) {\n query.whereEq("clearance", true)\n .orWhere("price", "<", 10);\n })\n .get();\n'})}),"\n",(0,r.jsx)(n.h3,{id:"additional-where-clauses",children:"Additional Where Clauses"}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"whereBetween / orWhereBetween"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereBetween"})," method verifies that a column's value is between two values:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereBetween("votes", {1, 100})\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"whereNotBetween / orWhereNotBetween"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereNotBetween"})," method verifies that a column's value lies outside of two values:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereNotBetween("votes", {1, 100})\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"whereBetweenColumns / orWhereBetweenColumns"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereBetweenColumns"})," method verifies that a column's value is between two values in given columns:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto files = DB::table("files")\n ->whereBetweenColumns("quota", {"min_allowed_quota", "max_allowed_quota"})\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"whereNotBetweenColumns / orWhereNotBetweenColumns"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereNotBetweenColumns"})," method verifies that a column's value lies outside of two values in given columns:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto files = DB::table("files")\n ->whereNotBetweenColumns("quota", {"min_allowed_quota", "max_allowed_quota"})\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"whereIn / whereNotIn / orWhereIn / orWhereNotIn"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereIn"})," method verifies that a given column's value is contained within the given ",(0,r.jsx)(n.code,{children:"QVector"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereIn("id", {1, 2, 3})\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereNotIn"})," method verifies that the given column's value is not contained in the given ",(0,r.jsx)(n.code,{children:"QVector"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereNotIn("id", {1, 2, 3})\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"whereNull / whereNotNull / orWhereNull / orWhereNotNull"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereNull"})," method verifies that the value of the given column is ",(0,r.jsx)(n.code,{children:"NULL"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereNull("updated_at")\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereNotNull"})," method verifies that the column's value is not ",(0,r.jsx)(n.code,{children:"NULL"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereNotNull("updated_at")\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"whereDate / whereTime / whereDay / whereMonth / whereYear"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereDate"})," method may be used to compare a column's value against a date:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereDate("created_at", EQ, QDate(2022, 11, 18))\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereTime"})," method may be used to compare a column's value against a specific time:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereTime("created_at", "=", QTime(11, 14, 23))\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereDay"})," method may be used to compare a column's value against a specific day of the month:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereDay("created_at", "<=", 15)\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereMonth"})," method may be used to compare a column's value against a specific month:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereEqMonth("created_at", 12)\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereYear"})," method may be used to compare a column's value against a specific year:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereEqYear("created_at", 2016)\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereDate"})," and ",(0,r.jsx)(n.code,{children:"whereTime"})," methods also accept a ",(0,r.jsx)(n.code,{children:"QDateTime"})," instance or you can pass values as a ",(0,r.jsx)(n.code,{children:"QString"})," in ",(0,r.jsx)(n.code,{children:"2022-12-31"})," or ",(0,r.jsx)(n.code,{children:"09:15:11"})," formats."]}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereDay"}),", ",(0,r.jsx)(n.code,{children:"whereMoth"}),", and ",(0,r.jsx)(n.code,{children:"whereYear"})," accept ",(0,r.jsx)(n.code,{children:"QDate"})," or ",(0,r.jsx)(n.code,{children:"QDateTime"})," instances, an integral number or a ",(0,r.jsx)(n.code,{children:"QString"})," that contains an integral number."]}),"\n",(0,r.jsx)(n.admonition,{type:"info",children:(0,r.jsxs)(n.p,{children:["All the above methods offer ",(0,r.jsx)(n.code,{children:"whereEqXyz"})," and ",(0,r.jsx)(n.code,{children:"orWhereXyz"})," shortcut methods."]})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"whereColumn / orWhereColumn"})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereColumnEq"})," method may be used to verify that two columns are equal:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereColumnEq("first_name", "last_name")\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may also pass a comparison operator to the ",(0,r.jsx)(n.code,{children:"whereColumn"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereColumn("updated_at", ">", "created_at")\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may also pass a ",(0,r.jsx)(n.code,{children:"QVector"})," of column comparisons to the ",(0,r.jsx)(n.code,{children:"whereColumn"})," method. These conditions will be joined using the ",(0,r.jsx)(n.code,{children:"and"})," operator:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">"},\n }).get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Conditions operator can also be overridden by the fourth argument in the ",(0,r.jsx)(n.code,{children:"Orm::WhereColumnItem"})," structure:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">", "or"},\n }).get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Or by the second ",(0,r.jsx)(n.code,{children:"whereColumn"})," argument:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">"},\n }, "or")\n .get();\n'})}),"\n",(0,r.jsx)(n.h3,{id:"logical-grouping",children:"Logical Grouping"}),"\n",(0,r.jsxs)(n.p,{children:['Sometimes you may need to group several "where" clauses within parentheses in order to achieve your query\'s desired logical grouping. In fact, you should generally always group calls to the ',(0,r.jsx)(n.code,{children:"orWhere"})," method in parentheses in order to avoid unexpected query behavior. To accomplish this, you may pass a lambda expression to the ",(0,r.jsx)(n.code,{children:"where"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->where("name", "=", "John")\n .where([](auto &query)\n {\n query.where("votes", ">", 100)\n .orWhere("title", "=", "Admin");\n })\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["As you can see, passing a lambda expression into the ",(0,r.jsx)(n.code,{children:"where"})," method instructs the query builder to begin a constraint group. The lambda expression will receive a query builder instance which you can use to set the constraints that should be contained within the parenthesis group. The example above will produce the following SQL:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-sql",children:'select * from users where name = "John" and (votes > 100 or title = "Admin")\n'})}),"\n",(0,r.jsx)(n.h2,{id:"advanced-where-clauses",children:"Advanced Where Clauses"}),"\n",(0,r.jsx)(n.h3,{id:"where-exists-clauses",children:"Where Exists Clauses"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"whereExists"}),' method allows you to write "where exists" SQL clauses. The ',(0,r.jsx)(n.code,{children:"whereExists"}),' method accepts a lambda expression which will receive a query builder instance, allowing you to define the query that should be placed inside of the "exists" clause:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereExists([](auto &query)\n {\n query.select(DB::raw(1))\n .from("orders")\n .whereColumnEq("orders.user_id", "users.id");\n })\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Alternatively, you may provide a query object to the ",(0,r.jsx)(n.code,{children:"whereExists"})," method instead of a lambda expression:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'// Ownership of the std::shared_ptr\nauto builder = DB::table("orders");\nauto orders = builder->select(DB::raw(1))\n .whereColumnEq("orders.user_id", "users.id");\n\nauto users = DB::table("users")\n ->whereExists(orders)\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:"Or directly:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->whereExists(DB::table("orders")\n ->select(DB::raw(1))\n .whereColumnEq("orders.user_id", "users.id"))\n .get();\n'})}),"\n",(0,r.jsx)(n.p,{children:"All of the examples above will produce the following SQL:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-sql",children:"select * from users\nwhere exists (\n select 1\n from orders\n where orders.user_id = users.id\n)\n"})}),"\n",(0,r.jsx)(n.h3,{id:"subquery-where-clauses",children:"Subquery Where Clauses"}),"\n",(0,r.jsxs)(n.p,{children:['Sometimes you may need to construct a "where" clause that compares the results of a subquery to a given value. You may accomplish this by passing a lambda expression and a value to the ',(0,r.jsx)(n.code,{children:"where"}),' method. For example, the following query will retrieve all users who have a recent "membership" of a given type:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include "models/user.hpp"\n\nauto users = User::whereEq([](auto &query)\n{\n query.select("type")\n .from("membership")\n .whereColumnEq("membership.user_id", "users.id")\n .orderByDesc("membership.start_date")\n .limit(1);\n}, "Pro")->get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:['Or, you may need to construct a "where" clause that compares a column to the results of a subquery. You may accomplish this by passing a column, operator, and lambda expression to the ',(0,r.jsx)(n.code,{children:"where"})," method. For example, the following query will retrieve all income records where the amount is less than average;"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'#include "models/income.hpp"\n\nauto incomes = Income::where("amount", "<", [](auto &query)\n{\n query.selectRaw("avg(i.amount)").from("incomes as i");\n})->get();\n'})}),"\n",(0,r.jsx)(n.h2,{id:"ordering-grouping-limit-and-offset",children:"Ordering, Grouping, Limit & Offset"}),"\n",(0,r.jsx)(n.h3,{id:"ordering",children:"Ordering"}),"\n",(0,r.jsxs)(n.h4,{id:"the-orderby-method",children:["The ",(0,r.jsx)(n.code,{children:"orderBy"})," Method"]}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"orderBy"})," method allows you to sort the results of the query by a given column. The first argument accepted by the ",(0,r.jsx)(n.code,{children:"orderBy"})," method should be the column you wish to sort by, while the second argument determines the direction of the sort and may be either ",(0,r.jsx)(n.code,{children:"asc"})," or ",(0,r.jsx)(n.code,{children:"desc"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->orderBy("name", "desc")\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["To sort by multiple columns, you may simply invoke ",(0,r.jsx)(n.code,{children:"orderBy"})," as many times as necessary:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->orderBy("name", "desc")\n .orderBy("email", "asc")\n .get();\n'})}),"\n",(0,r.jsxs)(n.h4,{id:"the-latest--oldest-methods",children:["The ",(0,r.jsx)(n.code,{children:"latest"})," & ",(0,r.jsx)(n.code,{children:"oldest"})," Methods"]}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"latest"})," and ",(0,r.jsx)(n.code,{children:"oldest"})," methods allow you to easily order results by date. By default, the result will be ordered by the table's ",(0,r.jsx)(n.code,{children:"created_at"})," column. Or, you may pass the column name that you wish to sort by:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto user = DB::table("users")\n ->latest()\n .first();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"random-ordering",children:"Random Ordering"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"inRandomOrder"})," method may be used to sort the query results randomly. For example, you may use this method to fetch a random user:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto randomUser = DB::table("users")\n ->inRandomOrder()\n .first();\n'})}),"\n",(0,r.jsx)(n.h4,{id:"removing-existing-orderings",children:"Removing Existing Orderings"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"reorder"}),' method removes all of the "order by" clauses that have previously been applied to the query:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto &query = DB::table("users")->orderBy("name");\n\nauto unorderedUsers = query.reorder().get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may pass a column and direction when calling the ",(0,r.jsx)(n.code,{children:"reorder"}),' method in order to remove all existing "order by" clauses and apply an entirely new order to the query:']}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto &query = DB::table("users")->orderBy("name");\n\nauto usersOrderedByEmail = query.reorder("email", "desc").get();\n'})}),"\n",(0,r.jsx)(n.h3,{id:"grouping",children:"Grouping"}),"\n",(0,r.jsxs)(n.h4,{id:"the-groupby--having-methods",children:["The ",(0,r.jsx)(n.code,{children:"groupBy"})," & ",(0,r.jsx)(n.code,{children:"having"})," Methods"]}),"\n",(0,r.jsxs)(n.p,{children:["As you might expect, the ",(0,r.jsx)(n.code,{children:"groupBy"})," and ",(0,r.jsx)(n.code,{children:"having"})," methods may be used to group the query results. The ",(0,r.jsx)(n.code,{children:"having"})," method's signature is similar to that of the ",(0,r.jsx)(n.code,{children:"where"})," method:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->groupBy("account_id")\n .having("account_id", ">", 100)\n .get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may pass multiple items to the ",(0,r.jsx)(n.code,{children:"groupBy"})," method to group by multiple columns:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->groupBy({"first_name", "status"})\n .having("account_id", ">", 100)\n .get();\n'})}),"\n",(0,r.jsx)(n.h3,{id:"limit-and-offset",children:"Limit & Offset"}),"\n",(0,r.jsxs)(n.h4,{id:"the-skip--take-methods",children:["The ",(0,r.jsx)(n.code,{children:"skip"})," & ",(0,r.jsx)(n.code,{children:"take"})," Methods"]}),"\n",(0,r.jsxs)(n.p,{children:["You may use the ",(0,r.jsx)(n.code,{children:"skip"})," and ",(0,r.jsx)(n.code,{children:"take"})," methods to limit the number of results returned from the query or to skip a given number of results in the query:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")->skip(10).take(5).get();\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Alternatively, you may use the ",(0,r.jsx)(n.code,{children:"limit"})," and ",(0,r.jsx)(n.code,{children:"offset"})," methods. These methods are functionally equivalent to the ",(0,r.jsx)(n.code,{children:"take"})," and ",(0,r.jsx)(n.code,{children:"skip"})," methods, respectively:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto users = DB::table("users")\n ->offset(10)\n .limit(5)\n .get();\n'})}),"\n",(0,r.jsx)(n.h2,{id:"insert-statements",children:"Insert Statements"}),"\n",(0,r.jsxs)(n.p,{children:["The query builder also provides an ",(0,r.jsx)(n.code,{children:"insert"})," method that may be used to insert records into the database table. The ",(0,r.jsx)(n.code,{children:"insert"})," method accepts the ",(0,r.jsx)(n.code,{children:"QVariantMap"})," of column names and values:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")->insert({\n {"email", "kayla@example.com"},\n {"votes", 0},\n});\n'})}),"\n",(0,r.jsx)(a.A,{id:"multi-insert-overload"}),"\n",(0,r.jsxs)(n.p,{children:["You may insert several records at once by passing a ",(0,r.jsx)(n.code,{children:"QVector"})," for column names as the first argument and ",(0,r.jsx)(n.code,{children:"QVector>"})," for values as the second argument. Each ",(0,r.jsx)(n.code,{children:"QVector"})," represents a record that should be inserted into the table. This overload is useful for multi-insert and allows to specify column names only once:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")->insert({"email", "votes"},\n{\n {"picard@example.com", 0},\n {"janeway@example.com", 0},\n});\n'})}),"\n",(0,r.jsxs)(n.p,{children:["You may also insert several records at once by passing a ",(0,r.jsx)(n.code,{children:"QVector"}),". Each ",(0,r.jsx)(n.code,{children:"QVariantMap"})," represents a record that should be inserted into the table:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")->insert({\n {{"email", "picard@example.com"}, {"votes", 0}},\n {{"email", "janeway@example.com"}, {"votes", 0}},\n});\n'})}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"insertOrIgnore"})," method will ignore duplicate record errors while inserting records into the database and also provides the same overloads like the ",(0,r.jsx)(n.code,{children:"insert"})," method. When using this method, you should be aware that duplicate record errors will be ignored and other types of errors may also be ignored depending on the database engine. For example, ",(0,r.jsx)(n.code,{children:"insertOrIgnore"})," will ",(0,r.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/en/sql-mode.html#ignore-effect-on-execution",children:"bypass MySQL's strict mode"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")->insertOrIgnore({"id", "email"},\n{\n {1, "sisko@example.com"},\n {2, "archer@example.com"},\n});\n\nDB::table("users")->insertOrIgnore({\n {{"id", 1}, {"email", "sisko@example.com"}},\n {{"id", 2}, {"email", "archer@example.com"}},\n});\n'})}),"\n",(0,r.jsx)(n.h4,{id:"auto-incrementing-ids",children:"Auto-Incrementing IDs"}),"\n",(0,r.jsxs)(n.p,{children:["If the table has an auto-incrementing id, use the ",(0,r.jsx)(n.code,{children:"insertGetId"})," method to insert a record and then retrieve the ID:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto id = DB::table("users")->insertGetId({\n {"email", "john@example.com"},\n {"votes", 0},\n});\n'})}),"\n",(0,r.jsx)(n.h3,{id:"upserts",children:"Upserts"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"upsert"})," method will insert records that do not exist and update the records that already exist with new values that you may specify. The method's first argument consists of the values to insert or update, while the second argument lists the column(s) that uniquely identify records within the associated table. The method's third and final argument is a vector of columns that should be updated if a matching record already exists in the database:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("flights")->upsert(\n {{{"departure", "Oakland"}, {"destination", "San Diego"}, {"price", 99}},\n {{"departure", "Chicago"}, {"destination", "New York"}, {"price", 150}}},\n {"departure", "destination"},\n {"price"}\n);\n'})}),"\n",(0,r.jsxs)(n.p,{children:["In the example above, TinyORM will attempt to insert two records. If a record already exists with the same ",(0,r.jsx)(n.code,{children:"departure"})," and ",(0,r.jsx)(n.code,{children:"destination"})," column values, TinyORM will update that record's ",(0,r.jsx)(n.code,{children:"price"})," column."]}),"\n",(0,r.jsx)(n.admonition,{type:"caution",children:(0,r.jsxs)(n.p,{children:["All databases except SQL Server require the columns in the second argument of the ",(0,r.jsx)(n.code,{children:"upsert"}),' method to have a "primary" or "unique" index. In addition, the MySQL database driver ignores the second argument of the ',(0,r.jsx)(n.code,{children:"upsert"}),' method and always uses the "primary" and "unique" indexes of the table to detect existing records.']})}),"\n",(0,r.jsx)(n.admonition,{type:"info",children:(0,r.jsxs)(n.p,{children:["Row and column aliases will be used with the MySQL server >=8.0.19 instead of the VALUES() function as is described in the MySQL ",(0,r.jsx)(n.a,{href:"https://dev.mysql.com/doc/refman/8.3/en/insert-on-duplicate.html",children:"documentation"}),". The MySQL server version is auto-detected and can be overridden in the ",(0,r.jsx)(n.a,{href:"/database/getting-started#configuration",children:"configuration"}),"."]})}),"\n",(0,r.jsx)(n.h2,{id:"update-statements",children:"Update Statements"}),"\n",(0,r.jsxs)(n.p,{children:["In addition to inserting records into the database, the query builder can also update existing records using the ",(0,r.jsx)(n.code,{children:"update"})," method. The ",(0,r.jsx)(n.code,{children:"update"})," method, accepts a ",(0,r.jsx)(n.code,{children:"QVector"})," of column and value pairs, indicating the columns to be updated and returns a ",(0,r.jsx)(n.code,{children:"std::tuple"})," . You may constrain the ",(0,r.jsx)(n.code,{children:"update"})," query using ",(0,r.jsx)(n.code,{children:"where"})," clauses:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'auto [affected, query] = DB::table("users")\n ->whereEq("id", 1)\n .update({{"votes", 1}});\n'})}),"\n",(0,r.jsx)(n.admonition,{type:"note",children:(0,r.jsxs)(n.p,{children:["An ",(0,r.jsx)(n.code,{children:"update"})," and ",(0,r.jsx)(n.code,{children:"delete"})," are affecting statements, so they return ",(0,r.jsx)(n.code,{children:"std::tuple"}),"."]})}),"\n",(0,r.jsx)(n.h4,{id:"update-or-insert",children:"Update Or Insert"}),"\n",(0,r.jsxs)(n.p,{children:["Sometimes you may want to update an existing record in the database or create it if no matching record exists. In this scenario, the ",(0,r.jsx)(n.code,{children:"updateOrInsert"})," method may be used. The ",(0,r.jsx)(n.code,{children:"updateOrInsert"})," method accepts two arguments: a vector of conditions by which to find the record, and a vector of column and value pairs indicating the columns to be updated."]}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"updateOrInsert"})," method will attempt to locate a matching database record using the first argument's column and value pairs. If the record exists, it will be updated with the values in the second argument. If the record can not be found, a new record will be inserted with the merged attributes of both arguments:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")\n ->updateOrInsert(\n {{"email", "john@example.com"}, {"name", "John"}},\n {{"votes", 2}}\n );\n'})}),"\n",(0,r.jsx)(n.h3,{id:"increment-and-decrement",children:"Increment & Decrement"}),"\n",(0,r.jsx)(n.p,{children:"The query builder also provides convenient methods for incrementing or decrementing the value of a given column. Both of these methods accept at least one argument: the column to modify. A second argument may be provided to specify the amount by which the column should be incremented or decremented:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cpp",children:'DB::table("users")->increment("votes");\n\nDB::table("users")->increment("votes", 5);\n\nDB::table("users")->decrement