From 8ee14e4489dabf3d52f712699c979e93292ca353 Mon Sep 17 00:00:00 2001 From: silverqx Date: Sun, 21 Apr 2024 18:24:17 +0200 Subject: [PATCH] Deploy website - based on ea29ecc007c9cf570ba025f5f5a0bf0c14724577 --- 404.html | 10 +++---- assets/js/0ab078a9.34078f5e.js | 1 + assets/js/0ab078a9.6ef4dbfd.js | 1 - assets/js/1222ea4e.93c74363.js | 1 + assets/js/1222ea4e.f70dc92d.js | 1 - assets/js/21dc2778.8476e46c.js | 1 - assets/js/21dc2778.c3cad2a2.js | 1 + assets/js/3dd307b5.7b464df0.js | 1 + assets/js/3dd307b5.94a0d662.js | 1 - ...1a96c.def9b0a5.js => 59b1a96c.6afbbfdf.js} | 2 +- assets/js/5b254f70.287f094d.js | 1 + assets/js/5b254f70.a04863b0.js | 1 - ...1276f.b50a0dc6.js => 62a1276f.732e44fe.js} | 2 +- ...faf8d.c6447040.js => 8a8faf8d.3f5122a9.js} | 2 +- assets/js/935f2afb.1589d25f.js | 1 + assets/js/935f2afb.15ecbd85.js | 1 - assets/js/ba3d4959.86bd32f7.js | 1 + assets/js/ba3d4959.a82789dd.js | 1 - assets/js/cb1e72f9.fa14ee96.js | 1 + ...663fe.0aaaebcb.js => cbe663fe.8fc7d46f.js} | 2 +- ...9b1c4.adf683bd.js => d459b1c4.5ad4f430.js} | 2 +- ...c288b.c1091e7e.js => e19c288b.8ce43523.js} | 2 +- ...c21cb.058c6bdf.js => e3ac21cb.f62ee0b6.js} | 2 +- ...13d4e.1faf534f.js => fb313d4e.246c2a2a.js} | 2 +- ...ee7f3.f93bb419.js => feaee7f3.d9eea7da.js} | 2 +- assets/js/main.b1605669.js | 2 ++ ...CENSE.txt => main.b1605669.js.LICENSE.txt} | 0 assets/js/main.b991ae83.js | 2 -- assets/js/runtime~main.72160521.js | 1 + assets/js/runtime~main.90af5946.js | 1 - building/hello-world.html | 10 +++---- building/migrations.html | 10 +++---- building/tinyorm.html | 16 ++++++------ database/getting-started.html | 10 +++---- database/migrations.html | 15 ++++++----- database/query-builder.html | 10 +++---- database/seeding.html | 10 +++---- dependencies.html | 12 ++++----- features-summary.html | 10 +++---- index.html | 12 ++++----- search.html | 10 +++---- sitemap.xml | 2 +- sponsors.html | 10 +++---- supported-compilers.html | 10 +++---- tinydrivers/getting-started.html | 26 +++++++++++++++++++ tinyorm/casts.html | 12 ++++----- tinyorm/collections.html | 12 ++++----- tinyorm/getting-started.html | 10 +++---- tinyorm/relationships.html | 10 +++---- tinyorm/serialization.html | 10 +++---- 50 files changed, 153 insertions(+), 123 deletions(-) create mode 100644 assets/js/0ab078a9.34078f5e.js delete mode 100644 assets/js/0ab078a9.6ef4dbfd.js create mode 100644 assets/js/1222ea4e.93c74363.js delete mode 100644 assets/js/1222ea4e.f70dc92d.js delete mode 100644 assets/js/21dc2778.8476e46c.js create mode 100644 assets/js/21dc2778.c3cad2a2.js create mode 100644 assets/js/3dd307b5.7b464df0.js delete mode 100644 assets/js/3dd307b5.94a0d662.js rename assets/js/{59b1a96c.def9b0a5.js => 59b1a96c.6afbbfdf.js} (85%) create mode 100644 assets/js/5b254f70.287f094d.js delete mode 100644 assets/js/5b254f70.a04863b0.js rename assets/js/{62a1276f.b50a0dc6.js => 62a1276f.732e44fe.js} (79%) rename assets/js/{8a8faf8d.c6447040.js => 8a8faf8d.3f5122a9.js} (99%) create mode 100644 assets/js/935f2afb.1589d25f.js delete mode 100644 assets/js/935f2afb.15ecbd85.js create mode 100644 assets/js/ba3d4959.86bd32f7.js delete mode 100644 assets/js/ba3d4959.a82789dd.js create mode 100644 assets/js/cb1e72f9.fa14ee96.js rename assets/js/{cbe663fe.0aaaebcb.js => cbe663fe.8fc7d46f.js} (99%) rename assets/js/{d459b1c4.adf683bd.js => d459b1c4.5ad4f430.js} (99%) rename assets/js/{e19c288b.c1091e7e.js => e19c288b.8ce43523.js} (96%) rename assets/js/{e3ac21cb.058c6bdf.js => e3ac21cb.f62ee0b6.js} (99%) rename assets/js/{fb313d4e.1faf534f.js => fb313d4e.246c2a2a.js} (77%) rename assets/js/{feaee7f3.f93bb419.js => feaee7f3.d9eea7da.js} (98%) create mode 100644 assets/js/main.b1605669.js rename assets/js/{main.b991ae83.js.LICENSE.txt => main.b1605669.js.LICENSE.txt} (100%) delete mode 100644 assets/js/main.b991ae83.js create mode 100644 assets/js/runtime~main.72160521.js delete mode 100644 assets/js/runtime~main.90af5946.js create mode 100644 tinydrivers/getting-started.html diff --git a/404.html b/404.html index f470acac3..b65636493 100644 --- a/404.html +++ b/404.html @@ -14,13 +14,13 @@ - - + +
-
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

- - +
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

+ + \ No newline at end of file diff --git a/assets/js/0ab078a9.34078f5e.js b/assets/js/0ab078a9.34078f5e.js new file mode 100644 index 000000000..cdb586c89 --- /dev/null +++ b/assets/js/0ab078a9.34078f5e.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[969],{5162:(e,t,n)=>{n.d(t,{Z:()=>r});var a=n(7294),i=n(6010);const l={tabItem:"tabItem_Ymn6"};function r(e){let{children:t,hidden:n,className:r}=e;return a.createElement("div",{role:"tabpanel",className:(0,i.Z)(l.tabItem,r),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>f});var a=n(7462),i=n(7294),l=n(6010),r=n(2466),o=n(6550),d=n(1980),p=n(7392),m=n(12);function s(e){return function(e){return i.Children.map(e,(e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:i}}=e;return{value:t,label:n,attributes:a,default:i}}))}function k(e){const{values:t,children:n}=e;return(0,i.useMemo)((()=>{const e=t??s(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function u(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function N(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,d._X)(l),(0,i.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function c(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=k(e),[r,o]=(0,i.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!u({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[d,p]=N({queryString:n,groupId:a}),[s,c]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,m.Nk)(n);return[a,(0,i.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),h=(()=>{const e=d??s;return u({value:e,tabValues:l})?e:null})();(0,i.useLayoutEffect)((()=>{h&&o(h)}),[h]);return{selectedValue:r,selectValue:(0,i.useCallback)((e=>{if(!u({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),p(e),c(e)}),[p,c,l]),tabValues:l}}var h=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:n,selectedValue:o,selectValue:d,tabValues:p}=e;const m=[],{blockElementScrollPositionUntilNextRender:s}=(0,r.o5)(),k=e=>{const t=e.currentTarget,n=m.indexOf(t),a=p[n].value;a!==o&&(s(t),d(a))},u=e=>{let t=null;switch(e.key){case"Enter":k(e);break;case"ArrowRight":{const n=m.indexOf(e.currentTarget)+1;t=m[n]??m[0];break}case"ArrowLeft":{const n=m.indexOf(e.currentTarget)-1;t=m[n]??m[m.length-1];break}}t?.focus()};return i.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},p.map((e=>{let{value:t,label:n,attributes:r}=e;return i.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>m.push(e),onKeyDown:u,onClick:k},r,{className:(0,l.Z)("tabs__item",b.tabItem,r?.className,{"tabs__item--active":o===t})}),n??t)})))}function C(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,i.cloneElement)(e,{className:"margin-top--md"}):null}return i.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,i.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function y(e){const t=c(e);return i.createElement("div",{className:(0,l.Z)("tabs-container",b.tabList)},i.createElement(g,(0,a.Z)({},e,t)),i.createElement(C,(0,a.Z)({},e,t)))}function f(e){const t=(0,h.Z)();return i.createElement(y,(0,a.Z)({key:String(t)},e))}},5178:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(7294),i=n(6550);const l={apiTable:"apiTable_flxF"};const r=(0,a.forwardRef)(((e,t)=>{let{name:n,children:l}=e;const r=function(e){let t=e;for(;(0,a.isValidElement)(t);)[t]=a.Children.toArray(t.props.children);return t}(l),o=n?`#${n}-${r}`:`#${r}`,d=(0,i.k6)();return a.createElement("tr",{id:r,tabIndex:0,ref:d.location.hash===o?t:void 0,onClick:()=>{d.push(o)},onKeyDown:e=>{"Enter"===e.key&&d.push(o)}},l.props.children)}));function o(e){let{children:t,name:n}=e;const[i,o]=a.Children.toArray(t.props.children),d=(0,a.useRef)(null);(0,a.useEffect)((()=>{d.current?.focus()}),[d]);const p=a.Children.map(o.props.children,(e=>a.createElement(r,{name:n,ref:d},e)));return a.createElement("table",{className:l.apiTable},i,a.createElement("tbody",null,p))}},2044:(e,t,n)=>{n.d(t,{$t:()=>s,Ae:()=>h,C:()=>N,DK:()=>b,Fo:()=>o,Fs:()=>i,IM:()=>c,IZ:()=>a,RS:()=>_,VE:()=>g,Wg:()=>y,_A:()=>p,al:()=>T,jk:()=>u,js:()=>d,of:()=>m,q5:()=>r,qb:()=>f,vk:()=>k,wU:()=>l,zg:()=>C});const a="shell",i="database",l="application",r="bash",o="pwsh",d="zsh",p="maria",m="mysql",s="postgres",k="sqlite",u="application",N="bash",c="pwsh",h="zsh",b="MariaDB",g="MySQL",C="PostgreSQL",y="SQLite",f="tinyorm.org",T="$HOME/Code/c/",_="$env:USERPROFILE\\Code\\c\\"},4355:(e,t,n)=>{n.d(t,{Z:()=>l});var a=n(7294),i=n(9482);function l(){const e=(0,a.useContext)(i.Z);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6005:(e,t,n)=>{n.d(t,{AE:()=>o,EA:()=>r,em:()=>p,go:()=>d,mT:()=>m,we:()=>s});var a=n(4355),i=n(2389),l=n(2044);const r=function(e,t){return void 0===t&&(t=!0),k((0,a.Z)().rootFolder[e]??p(e),e,t)},o=()=>(0,a.Z)().rootFolder[l.wU]??p(l.wU),d=function(e,t){if(void 0===t&&(t=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const n=t||e!==l.Fo?"/":"\\";return k(r(e)+n+o(),e,t)};function p(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,i.Z)())return"";switch(e){case l.Fo:return l.RS;case l.q5:return l.al;case l.wU:return l.qb;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function m(e){return e===l.wU}function s(e,t){if(null==t||""===t)return t;const n="$ENV{$1}$2";switch(e){case l.Fo:return N(t).replace(/\$env:(.+?)(\/.*)/,n);case l.q5:return t.replace(/\$(.+?)(\/.*)/,n);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function k(e,t,n){if(void 0===n&&(n=!0),null==e||""===e)return e;if(t!==l.Fo)return u(e);const a=u(e);return n?N(a):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(a)}function u(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function N(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},4040:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>v,contentTitle:()=>T,default:()=>R,frontMatter:()=>f,metadata:()=>_,toc:()=>O});var a=n(7462),i=n(7294),l=n(3905),r=n(5178),o=n(7693),d=n(5162),p=n(4866),m=n(5697),s=n.n(m),k=n(6005);function u(e){let{groupId:t}=e;return i.createElement("span",null,(0,k.go)(t))}u.propTypes={groupId:s().string.isRequired};const N=u;var c=n(6010),h=n(4355);const b={rootFolderInput:"rootFolderInput_ottS",input:"input_OR7e",application:"application_fjej"};function g(e){let{groupId:t,label:n}=e;const{rootFolder:a,setRootFolder:l}=(0,h.Z)(),r=(0,k.mT)(t),o=r?"application":"root",d=r?"\nThis folder name is common for all shells (eg. pwsh, bash, ...)":"";return i.createElement("form",{name:"tinyorm-root-folder-form",className:(0,c.Z)(b.rootFolderInput,b[t],t),onSubmit:e=>{e.preventDefault(),e.stopPropagation()}},i.createElement("input",{name:"tinyorm-root-folder-input",className:(0,c.Z)(b.input,b[t],t),placeholder:`Enter ${o} folder...`,title:`This ${o} folder will be used in all ${n} examples at tinyorm.org${d}`,onChange:e=>{l(t,e.target.value)},value:a[t]??(0,k.em)(t)}))}g.propTypes={groupId:s().string.isRequired,label:s().string.isRequired};const C=g;var y=n(2044);const f={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"]},T="Building: TinyORM",_={unversionedId:"building/tinyorm",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,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/building/tinyorm.mdx",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"}},v={},O=[{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}],I={toc:O},M="wrapper";function R(e){let{components:t,...i}=e;return(0,l.kt)(M,(0,a.Z)({},I,i,{components:t,mdxType:"MDXLayout"}),(0,l.kt)("h1",{id:"building-tinyorm"},"Building: TinyORM"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#introduction"},"Introduction"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#common-prerequisites"},"Common Prerequisites")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#windows-prerequisites"},"Windows Prerequisites")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#folders-structure"},"Folders structure")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#getting-started"},"Getting started")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#vcpkg"},"vcpkg")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#c-preprocessor-macros"},"C preprocessor macros")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#building-with-cmake"},"Building with CMake"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#configure-and-build-cmake"},"Configure & Build")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#cmake-build-options"},"CMake build options")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#consume-tinyorm-library-cmake"},"Consume TinyOrm library")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#building-with-qmake"},"Building with qmake"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#install-dependencies"},"Install dependencies")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#configure-and-build-qmake"},"Configure & Build")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#qmake-build-options"},"qmake build options")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#consume-tinyorm-library-qmake"},"Consume TinyOrm library")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#auto-configuration-internals"},"Auto-configuration internals"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#environment-files"},"Environment files")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#manual-configuration-internals"},"Manual configuration internals")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#ccache-support"},"Ccache support"))),(0,l.kt)("h2",{id:"introduction"},"Introduction"),(0,l.kt)("p",null,"The build systems supported out of the box are ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake"),"."),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"All examples below assume that ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh")," runs on ",(0,l.kt)("inlineCode",{parentName:"p"},"Windows")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"bash")," runs on ",(0,l.kt)("inlineCode",{parentName:"p"},"Linux"),".")),(0,l.kt)("h4",{id:"common-prerequisites"},"Common Prerequisites"),(0,l.kt)("p",null,"Install the required ",(0,l.kt)("a",{parentName:"p",href:"/dependencies"},"dependencies")," before starting."),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"QSqlDatabase")," depends on ",(0,l.kt)("inlineCode",{parentName:"p"},"QCoreApplication")," from ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt v6.5.3")," so you must create the ",(0,l.kt)("inlineCode",{parentName:"p"},"QCoreApplication")," instance before you will call anything from the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. \ud83e\udee4 The change was made ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/qt/qtbase/commit/8d2bdc9cd5482eace12ba7e45304857bd24db0e6#diff-1d355c25c0b0eddec2be48253407780c4dc510d986739aec61e1ec892ccaf86e"},"here"),".")),(0,l.kt)("h4",{id:"windows-prerequisites"},"Windows Prerequisites"),(0,l.kt)("h5",{id:"build-environment-scripts"},"Build environment scripts"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Visual Studio")," does not provide ",(0,l.kt)("inlineCode",{parentName:"p"},"vcvars")," scripts for ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh"),", you can use ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/tools/vcvars64.ps1"},(0,l.kt)("inlineCode",{parentName:"a"},"vcvars64.ps1"))," provided by ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," in the ",(0,l.kt)("inlineCode",{parentName:"p"},"tools/")," folder. Place them on the ",(0,l.kt)("inlineCode",{parentName:"p"},"$env:Path")," user/system path and they will be available system-wide."),(0,l.kt)("p",null,"The same is true for the ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt Framework"),", it doesn't provide ",(0,l.kt)("inlineCode",{parentName:"p"},"qtenv")," scripts for ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh")," too. You can create your own script, place it on the ",(0,l.kt)("inlineCode",{parentName:"p"},"$env:Path")," user/system path and it will be available system-wide."),(0,l.kt)("p",null,"Here is one simple example for ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh"),"."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:"qtenv6.ps1",label:"qtenv6.ps1",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},"Write-Host 'Setting up environment for Qt 6.7.0 usage...' -ForegroundColor Magenta\n$env:Path = 'C:\\Qt\\6.7.0\\msvc2019_64\\bin;' + $env:Path\n. E:\\dotfiles\\bin\\vcvars64.ps1\n"))),(0,l.kt)(d.Z,{value:"qtenv5.ps1",label:"qtenv5.ps1",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},"Write-Host 'Setting up environment for Qt 5.15.2 usage...' -ForegroundColor Magenta\n$env:Path = 'C:\\Qt\\5.15.2\\msvc2019_64\\bin;' + $env:Path\n. E:\\dotfiles\\bin\\vcvars64.ps1\n")))),(0,l.kt)("p",null,"And here for ",(0,l.kt)("inlineCode",{parentName:"p"},"Linux"),"."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:"qtenv6",label:"qtenv6",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"echo 'Setting up environment for Qt 6.7.0 usage...'\n\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,l.kt)(d.Z,{value:"qtenv5",label:"qtenv5",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"echo 'Setting up environment for Qt 5.15.2 usage...'\n\nexport PATH=/opt/Qt/5.15.2/gcc_64/bin${PATH:+:}$PATH\nexport LD_LIBRARY_PATH=/opt/Qt/5.15.2/gcc_64/lib${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH\n")))),(0,l.kt)("h5",{id:"allow-symbolic-links-unprivileged"},"Allow symbolic links unprivileged"),(0,l.kt)("p",null,"Open ",(0,l.kt)("inlineCode",{parentName:"p"},"Local Security Policy"),", go to ",(0,l.kt)("inlineCode",{parentName:"p"},"Local Policies - User Rights Assignment"),", open ",(0,l.kt)("inlineCode",{parentName:"p"},"Create symbolic links")," and add your user account or user group, restart when it doesn't apply immediately."),(0,l.kt)("h2",{id:"folders-structure"},"Folders structure"),(0,l.kt)("p",null,"All ",(0,l.kt)("inlineCode",{parentName:"p"},"tinyorm.org")," examples are based on the following folders structure. The ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," folder will contain a ",(0,l.kt)("a",{parentName:"p",href:"/building/migrations"},"migrations console application"),"."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can set the root and application folder paths in the form below and they will be used across the whole ",(0,l.kt)("a",{parentName:"p",href:"http://www.tinyorm.org"},"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.")),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,className:"tiny-tree",mdxType:"TabItem"},(0,l.kt)("div",{className:"tiny-root-folder-info-wrapper"},(0,l.kt)("span",{className:"tiny-root-folder-info-prefix"},"Current pwsh path"),"\xa0",(0,l.kt)(N,{groupId:y.Fo,mdxType:"RootFolder"})),(0,l.kt)(C,{groupId:y.Fo,label:y.IM,mdxType:"RootFolderInput"}),(0,l.kt)(C,{groupId:y.wU,label:y.jk,mdxType:"RootFolderInput"}),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-text"},"\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,l.kt)(d.Z,{value:y.q5,label:y.C,className:"tiny-tree",mdxType:"TabItem"},(0,l.kt)("div",{className:"tiny-root-folder-info-wrapper"},(0,l.kt)("span",{className:"tiny-root-folder-info-prefix"},"Current bash path"),"\xa0",(0,l.kt)(N,{groupId:y.q5,mdxType:"RootFolder"})),(0,l.kt)(C,{groupId:y.q5,label:y.C,mdxType:"RootFolderInput"}),(0,l.kt)(C,{groupId:y.wU,label:y.wU,mdxType:"RootFolderInput"}),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-text"},"\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")))),(0,l.kt)("admonition",{type:"danger"},(0,l.kt)("p",{parentName:"admonition"},"Avoid paths with spaces with the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system, it will not compile.")),(0,l.kt)("a",{id:"qtcreator-default-build-directory"}),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can force the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator")," to generate a build folders structure as is described above."),(0,l.kt)("p",{parentName:"admonition"},"To generate the required folders structure set the ",(0,l.kt)("inlineCode",{parentName:"p"},"Settings")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Build & Run")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Default Build Properties")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Default build directory")," to:",(0,l.kt)("br",null),"\n",(0,l.kt)("inlineCode",{parentName:"p"},'../%{Project:Name}-builds-%{BuildSystem:Name}/%{JS: Util.asciify("build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name}")}'))),(0,l.kt)("h2",{id:"getting-started"},"Getting started"),(0,l.kt)("p",null,"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,l.kt)("inlineCode",{parentName:"p"},"PATH")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," for Qt Framework, or use our ",(0,l.kt)("inlineCode",{parentName:"p"},"qtenvX")," scripts described above."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`mkdir ${(0,k.EA)(y.Fo)}\ncd ${(0,k.EA)(y.Fo)}\n$env:Path = 'C:\\Qt\\6.7.0\\msvc2019_64\\bin;' + $env:Path\nvcvars64.ps1`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`mkdir -p ${(0,k.EA)(y.q5)}\ncd ${(0,k.EA)(y.q5)}\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`))),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can also use the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tools/Add-FolderOnPath.ps1"},(0,l.kt)("inlineCode",{parentName:"a"},"tools/Add-FolderOnPath.ps1"))," pwsh script to fastly prepend a path or ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd")," on the system ",(0,l.kt)("inlineCode",{parentName:"p"},"PATH"),".")),(0,l.kt)("h2",{id:"vcpkg"},"vcpkg"),(0,l.kt)("p",null,"Installing the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," is highly recommended, it simplifies installation of the ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," dependencies."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},"git clone git@github.com:microsoft/vcpkg.git\ncd vcpkg\n.\\bootstrap-vcpkg.bat\n"))),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"git clone git@github.com:microsoft/vcpkg.git\ncd vcpkg\n./bootstrap-vcpkg.sh\n")))),(0,l.kt)("p",null,"Add ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," on the system path, add the following to the ",(0,l.kt)("inlineCode",{parentName:"p"},".bashrc")," or ",(0,l.kt)("inlineCode",{parentName:"p"},".zshrc")," on Linux."),(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export PATH=${(0,k.EA)(y.q5)}/vcpkg\${PATH:+:}$PATH`),(0,l.kt)("p",null,"On Windows, open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Environment variables")," dialog and add ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," on the user ",(0,l.kt)("inlineCode",{parentName:"p"},"PATH"),"."),(0,l.kt)("p",null,"Or you can export it for the current session only."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,k.EA)(y.Fo,!1)}\\vcpkg;" + $env:Path`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export PATH=${(0,k.EA)(y.q5)}/vcpkg\${PATH:+:}$PATH`))),(0,l.kt)("h4",{id:"set-up-vcpkg-environment"},"Set up ",(0,l.kt)("inlineCode",{parentName:"h4"},"vcpkg")," environment"),(0,l.kt)("p",null,"To export ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," environment variables globally, add it to the ",(0,l.kt)("inlineCode",{parentName:"p"},".bashrc")," or ",(0,l.kt)("inlineCode",{parentName:"p"},".zshrc")," on Linux, and you can use the ",(0,l.kt)("inlineCode",{parentName:"p"},"Environment variables")," dialog on Windows."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash",metastring:"title='Linux'",title:"'Linux'"},'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')),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"It is recommended to define these variables globally because the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system are able to detect the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," installation from them so you don't have to configure them manually to detect the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," installation.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"On Windows, it's always better to create these types of variables as user variables instead of system variables in the ",(0,l.kt)("inlineCode",{parentName:"p"},"Environment variables")," dialog.")),(0,l.kt)("h2",{id:"c-preprocessor-macros"},"C preprocessor macros"),(0,l.kt)("p",null,"The following table summarizes all the C preprocessor macros defined in the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. These C macros are configured by ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build systems. They are not sorted alphabetically, but they are sorted by how significant they are."),(0,l.kt)("p",null,"In the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," build system, all the C macros are auto-detected / auto-configured or controlled by ",(0,l.kt)("a",{parentName:"p",href:"#cmake-build-options"},(0,l.kt)("inlineCode",{parentName:"a"},"CMake build options")),", so you don't have to care too much about them."),(0,l.kt)("p",null,"In the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build is important whether you are building ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library or you are building your application and linking against ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. When you are building the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library, all the C macros are auto-detected / auto-configured or controlled by ",(0,l.kt)("a",{parentName:"p",href:"#qmake-build-options"},(0,l.kt)("inlineCode",{parentName:"a"},"qmake build options")),", so you don't have to care too much about them."),(0,l.kt)("p",null,"But a special situation is when you are building your application / library and you are linking against ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. In this particular case, you must configure all these C macros manually! For this reason, the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/qmake/TinyOrm.pri"},(0,l.kt)("inlineCode",{parentName:"a"},"TinyOrm.pri"))," has been created, so that's not a big deal either. Little more info ",(0,l.kt)("a",{parentName:"p",href:"#consume-tinyorm-library-qmake"},"here"),"."),(0,l.kt)("div",{id:"apitable-c-macros"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"C Macro Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_LINKING_SHARED")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("u",null,(0,l.kt)("strong",{parentName:"td"},"Must"))," be defined when you are linking against ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," shared build (",(0,l.kt)("inlineCode",{parentName:"td"},"dll")," library), exported classes and functions will be tagged with ",(0,l.kt)("inlineCode",{parentName:"td"},"__declspec(dllimport)")," on ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc")," and ",(0,l.kt)("inlineCode",{parentName:"td"},'visibility("default")')," on ",(0,l.kt)("inlineCode",{parentName:"td"},"GCC >= 4"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_BUILDING_SHARED")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined when ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," is built as a ",(0,l.kt)("inlineCode",{parentName:"td"},"dll")," library (shared build).")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_DEBUG")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined in the debug build.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_NO_DEBUG")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined in the release build.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_DEBUG_SQL")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined in the debug build.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_NO_DEBUG_SQL")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined in the release build.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_MYSQL_PING")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable ",(0,l.kt)("inlineCode",{parentName:"td"},"Orm::MySqlConnection::pingDatabase()")," method.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#mysql_ping"},(0,l.kt)("inlineCode",{parentName:"a"},"mysql_ping"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#MYSQL_PING"},(0,l.kt)("inlineCode",{parentName:"a"},"MYSQL_PING"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_DISABLE_ORM")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," source code, when this macro is ",(0,l.kt)("inlineCode",{parentName:"td"},"defined"),", then only the ",(0,l.kt)("inlineCode",{parentName:"td"},"query builder")," without ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM")," is compiled. Also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," unit tests.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#disable_orm"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_orm"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#ORM"},(0,l.kt)("inlineCode",{parentName:"a"},"ORM"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled ",(0,l.kt)("small",null,"(qmake)")," / disabled ",(0,l.kt)("small",null,"(cmake)"),"."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_EXTERN_CONSTANTS")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined when extern constants are used. Extern constants are enabled by default for shared builds and disabled for static builds.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Described at ",(0,l.kt)("a",{parentName:"td",href:"#extern_constants"},(0,l.kt)("inlineCode",{parentName:"a"},"qmake"))," / ",(0,l.kt)("a",{parentName:"td",href:"#INLINE_CONSTANTS"},(0,l.kt)("inlineCode",{parentName:"a"},"CMake"))," how it works."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_INLINE_CONSTANTS")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined when global inline constants are used.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#inline_constants"},(0,l.kt)("inlineCode",{parentName:"a"},"inline_constants"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#INLINE_CONSTANTS"},(0,l.kt)("inlineCode",{parentName:"a"},"INLINE_CONSTANTS"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_TESTS_CODE")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable code needed by unit tests, eg. connection overriding in the ",(0,l.kt)("inlineCode",{parentName:"td"},"Orm::Tiny::Model"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#build_tests"},(0,l.kt)("inlineCode",{parentName:"a"},"build_tests"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#BUILD_TESTS"},(0,l.kt)("inlineCode",{parentName:"a"},"BUILD_TESTS"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_DISABLE_THREAD_LOCAL")),(0,l.kt)("td",{parentName:"tr",align:null},"Remove all ",(0,l.kt)("a",{parentName:"td",href:"https://en.cppreference.com/w/c/language/storage_duration"},(0,l.kt)("inlineCode",{parentName:"a"},"thread_local"))," storage duration specifiers, it disables multi-threading support.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#disable_thread_local"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_thread_local"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#DISABLE_THREAD_LOCAL"},(0,l.kt)("inlineCode",{parentName:"a"},"DISABLE_THREAD_LOCAL"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYTOM_MIGRATIONS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},"Default migrations path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:migration")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/migrations")," ",(0,l.kt)("small",null,"(relative to the pwd)")),(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined by ",(0,l.kt)("a",{parentName:"td",href:"#TOM_MIGRATIONS_DIR"},(0,l.kt)("inlineCode",{parentName:"a"},"TOM_MIGRATIONS_DIR"))," ",(0,l.kt)("small",null,"(cmake)")," configuration build option.",(0,l.kt)("br",null),(0,l.kt)("small",null,"(qmake note) You can use ",(0,l.kt)("inlineCode",{parentName:"td"},'DEFINES += TINYTOM_MIGRATIONS_DIR="\\"database/migrations\\""')," on the command-line or set it in the ",(0,l.kt)("strong",{parentName:"td"},"main")," ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L65-L70"},(0,l.kt)("inlineCode",{parentName:"a"},"conf.pri"))," file.")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYTOM_MODELS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},"Default models path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:model")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/models")," ",(0,l.kt)("small",null,"(relative to the pwd)")),(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined by ",(0,l.kt)("a",{parentName:"td",href:"#TOM_MODELS_DIR"},(0,l.kt)("inlineCode",{parentName:"a"},"TOM_MODELS_DIR"))," ",(0,l.kt)("small",null,"(cmake)")," configuration build option.",(0,l.kt)("br",null),(0,l.kt)("small",null,"(qmake note) You can use ",(0,l.kt)("inlineCode",{parentName:"td"},'DEFINES += TINYTOM_MODELS_DIR="\\"database/models\\""')," on the command-line or set it in the ",(0,l.kt)("strong",{parentName:"td"},"main")," ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L72-L73"},(0,l.kt)("inlineCode",{parentName:"a"},"conf.pri"))," file.")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYTOM_SEEDERS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},"Default seeders path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:seeder")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/seeders")," ",(0,l.kt)("small",null,"(relative to the pwd)")),(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined by ",(0,l.kt)("a",{parentName:"td",href:"#TOM_SEEDERS_DIR"},(0,l.kt)("inlineCode",{parentName:"a"},"TOM_SEEDERS_DIR"))," ",(0,l.kt)("small",null,"(cmake)")," configuration build option.",(0,l.kt)("br",null),(0,l.kt)("small",null,"(qmake note) You can use ",(0,l.kt)("inlineCode",{parentName:"td"},'DEFINES += TINYTOM_SEEDERS_DIR="\\"database/seeders\\""')," on the command-line or set it in the ",(0,l.kt)("strong",{parentName:"td"},"main")," ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L75-L76"},(0,l.kt)("inlineCode",{parentName:"a"},"conf.pri"))," file.")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_USING_PCH")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined if building with precompiled headers.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Controlled by ",(0,l.kt)("a",{parentName:"td",href:"#precompile_header"},(0,l.kt)("inlineCode",{parentName:"a"},"qmake"))," / ",(0,l.kt)("a",{parentName:"td",href:"#CMAKE_DISABLE_PRECOMPILE_HEADERS"},(0,l.kt)("inlineCode",{parentName:"a"},"CMake")),"."))))))),(0,l.kt)("h2",{id:"building-with-cmake"},"Building with CMake"),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"If something is not clear, you can still look at GitHub Action ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/.github/workflows"},(0,l.kt)("inlineCode",{parentName:"a"},"workflows"))," how a building is done.")),(0,l.kt)("p",null,"First, create a basic folder structure and then clone the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,k.EA)(y.Fo)}\nmkdir ${(0,k.AE)()}/TinyORM/TinyORM-builds-cmake/build-debug\n\ncd ${(0,k.AE)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,k.EA)(y.q5)}\nmkdir -p ${(0,k.AE)()}/TinyORM/TinyORM-builds-cmake/build-debug\n\ncd ${(0,k.AE)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`))),(0,l.kt)("h3",{id:"configure-and-build-cmake"},"Configure & Build ",(0,l.kt)("small",null,"(cmake)")),(0,l.kt)("p",null,"Now you are ready to configure the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd TinyORM-builds-cmake/build-debug\n")),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cmake.exe \`\n-S "${(0,k.go)(y.Fo)}/TinyORM/TinyORM" \`\n-B "${(0,k.go)(y.Fo)}/TinyORM/TinyORM-builds-cmake/build-debug" \`\n-G 'Ninja' \`\n-D CMAKE_BUILD_TYPE:STRING='Debug' \`\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,k.EA)(y.Fo)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \`\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,k.EA)(y.Fo)}/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,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cmake \\\n-S "${(0,k.go)(y.q5)}/TinyORM/TinyORM" \\\n-B "${(0,k.go)(y.q5)}/TinyORM/TinyORM-builds-cmake/build-debug" \\\n-G 'Ninja' \\\n-D CMAKE_BUILD_TYPE:STRING='Debug' \\\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,k.EA)(y.q5)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \\\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,k.EA)(y.q5)}/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`))),(0,l.kt)("h5",{id:"cmake-strict_mode-option"},"CMake ",(0,l.kt)("inlineCode",{parentName:"h5"},"STRICT_MODE")," option"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"STRICT_MODE")," ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," configuration option was added in ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.37.0"),". This option was added to avoid the propagation of aggressive strict warning compiler/linker options and Qt definitions from the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library to user code through the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/cmake/CommonModules/TinyCommon.cmake"},(0,l.kt)("inlineCode",{parentName:"a"},"TinyOrm::CommonConfig"))," interface library."),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"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,l.kt)("inlineCode",{parentName:"p"},"ISOCPP")," ",(0,l.kt)("a",{parentName:"p",href:"https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines"},"C++ Core Guidelines")," standards."),(0,l.kt)("p",null,"If you want to enable these strict warning options in your code, you can enable the ",(0,l.kt)("inlineCode",{parentName:"p"},"STRICT_MODE")," ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," configuration option and they will be propagated to your code. You can also enabled it globally using the ",(0,l.kt)("inlineCode",{parentName:"p"},"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,l.kt)("inlineCode",{parentName:"p"},"STRICT_MODE")," ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," configuration option."),(0,l.kt)("p",null,"You can achieve the same result by manually linking against the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm::CommonConfig")," interface library when the ",(0,l.kt)("inlineCode",{parentName:"p"},"STRICT_MODE")," is set to ",(0,l.kt)("inlineCode",{parentName:"p"},"OFF"),"."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-cmake"},"target_link_libraries( PRIVATE TinyOrm::CommonConfig)\n")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"The recommended way is to set the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_STRICT_MODE")," environment variable to ",(0,l.kt)("inlineCode",{parentName:"p"},"1")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"ON"),".")),(0,l.kt)("h4",{id:"build-tinyorm"},"Build TinyORM"),(0,l.kt)("p",null,"And build. You don't have to install it, you can use the build tree directly if you want."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cmake --build . --target all\ncmake --install .\n")),(0,l.kt)("p",null,"Or build and install in one step."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cmake --build . --target install\n")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"CMake multi-config generators like ",(0,l.kt)("inlineCode",{parentName:"p"},"Ninja Multi-Config")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"Visual Studio 16 2019")," are also supported.")),(0,l.kt)("h3",{id:"cmake-build-options"},"CMake build options"),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Option Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_DRIVERS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build ",(0,l.kt)("a",{parentName:"td",href:"/tinydrivers/getting-started"},(0,l.kt)("inlineCode",{parentName:"a"},"TinyDrivers"))," SQL database drivers (core/common code; replaces QtSql module).")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_MYSQL_DRIVERS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyDrivers")," MySQL database driver.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_DRIVERS")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_SHARED_LIBS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Build as a shared/static library.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_TESTS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build TinyORM unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_TREE_DEPLOY")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Copy ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyDrivers")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyMySql")," libraries to the root of the build tree.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"DRIVERS_TYPE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"Shared")),(0,l.kt)("td",{parentName:"tr",align:null},"How to build and link against ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyDrivers")," SQL database drivers.",(0,l.kt)("br",null),(0,l.kt)("small",null,"The ",(0,l.kt)("inlineCode",{parentName:"td"},"Static")," value will be select by default when the ",(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_SHARED_LIBS")," is ",(0,l.kt)("inlineCode",{parentName:"td"},"OFF"),".",(0,l.kt)("br",null),"Supported values: ",(0,l.kt)("inlineCode",{parentName:"td"},"Shared"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"Loadable"),", and ",(0,l.kt)("inlineCode",{parentName:"td"},"Static"),(0,l.kt)("br",null),"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_DRIVERS AND BUILD_SHARED_LIBS")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"INLINE_CONSTANTS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Use inline constants instead of extern constants in the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),".",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"OFF")," is highly recommended for the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),";",(0,l.kt)("br",null),"is always ",(0,l.kt)("inlineCode",{parentName:"td"},"ON")," for the ",(0,l.kt)("inlineCode",{parentName:"td"},"static build"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_SHARED_LIBS")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"MSVC_RUNTIME_DYNAMIC")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Use MSVC dynamic runtime library (",(0,l.kt)("inlineCode",{parentName:"td"},"-MD"),") instead of static (",(0,l.kt)("inlineCode",{parentName:"td"},"-MT"),"), also considers a Debug configuration (",(0,l.kt)("inlineCode",{parentName:"td"},"-MTd"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"-MDd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"MYSQL_PING")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable ",(0,l.kt)("inlineCode",{parentName:"td"},"Orm::MySqlConnection::pingDatabase()")," method.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ORM")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," source code, when this option is ",(0,l.kt)("inlineCode",{parentName:"td"},"disabled"),", then only the ",(0,l.kt)("inlineCode",{parentName:"td"},"query builder")," without ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM")," is compiled. Also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"STRICT_MODE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls propagation of strict compiler/linker options and Qt definitions using the ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyOrm::CommonConfig")," interface library to the user code.",(0,l.kt)("br",null),(0,l.kt)("small",null,"(highly recommended; can also be set with the ",(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_STRICT_MODE")," environment variable; described ",(0,l.kt)("a",{parentName:"td",href:"#cmake-strict_mode-option"},"here"),")"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"Tom-related")," source code, when this option is ",(0,l.kt)("inlineCode",{parentName:"td"},"disabled"),", then it also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"Tom-related")," unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM_EXAMPLE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build the ",(0,l.kt)("abbr",{title:"TinyORM Migrations"},(0,l.kt)("inlineCode",{parentName:"td"},"tom"))," console application example.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM_MIGRATIONS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Default migrations path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:migration")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/migrations")," ",(0,l.kt)("small",null,"(relative to the pwd)")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM_MODELS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Default models path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:model")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/models")," ",(0,l.kt)("small",null,"(relative to the pwd)")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM_SEEDERS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Default seeders path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:seeder")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/seeders")," ",(0,l.kt)("small",null,"(relative to the pwd)")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"VERBOSE_CONFIGURE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Show information about ",(0,l.kt)("inlineCode",{parentName:"td"},"PACKAGES_FOUND")," / ",(0,l.kt)("inlineCode",{parentName:"td"},"PACKAGES_NOT_FOUND")," in the CMake configure output.")))))),(0,l.kt)("p",null,"Advanced ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," options."),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Option Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"DISABLE_THREAD_LOCAL")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Remove all ",(0,l.kt)("a",{parentName:"td",href:"https://en.cppreference.com/w/c/language/storage_duration"},(0,l.kt)("inlineCode",{parentName:"a"},"thread_local"))," storage duration specifiers, it disables multi-threading support.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("small",null,(0,l.kt)("inlineCode",{parentName:"td"},"MATCH_EQUAL_EXPORTED_BUILDTREE"))),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Exported package configuration from the build tree is considered to match only when ",(0,l.kt)("inlineCode",{parentName:"td"},"the build type")," of application/library that is linking against the TinyORM library ",(0,l.kt)("strong",{parentName:"td"},"is equal"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when:",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_EXPORT_PACKAGE_REGISTRY AND NOT TINY_IS_MULTI_CONFIG")))))))),(0,l.kt)("p",null,"Important ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," options."),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Option Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_DISABLE_PRECOMPILE_HEADERS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Disable precompiled headers.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_CXX_COMPILER")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"auto")),(0,l.kt)("td",{parentName:"tr",align:null},"The full path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"C++")," compiler.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_CXX_COMPILER_LAUNCHER")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Default compiler launcher to use for the ",(0,l.kt)("inlineCode",{parentName:"td"},"C++")," compiler.",(0,l.kt)("br",null),"Can be used to enable ",(0,l.kt)("inlineCode",{parentName:"td"},"ccache"),", eg. ",(0,l.kt)("inlineCode",{parentName:"td"},"ccache.exe")," on ",(0,l.kt)("inlineCode",{parentName:"td"},"MinGW")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"/usr/bin/ccache")," on ",(0,l.kt)("inlineCode",{parentName:"td"},"Linux"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_EXPORT_PACKAGE_REGISTRY")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable the ",(0,l.kt)("inlineCode",{parentName:"td"},"export(TinyOrm)")," command.",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," sets this variable to ",(0,l.kt)("inlineCode",{parentName:"td"},"ON")," by default.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_VERBOSE_MAKEFILE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable verbose output from Makefile builds.")))))),(0,l.kt)("h3",{id:"consume-tinyorm-library-cmake"},"Consume TinyOrm library ",(0,l.kt)("small",null,"(cmake)")),(0,l.kt)("p",null,"In your application or library ",(0,l.kt)("inlineCode",{parentName:"p"},"CMakeLists.txt")," file add following ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package()")," call."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-cmake",metastring:"title='CMakeLists.txt'",title:"'CMakeLists.txt'"},"find_package(TinyOrm 0.37.0 CONFIG REQUIRED)\n")),(0,l.kt)("p",null,"If the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build tree is not exported to the CMake's ",(0,l.kt)("a",{parentName:"p",href:"https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#user-package-registry"},(0,l.kt)("inlineCode",{parentName:"a"},"User Package Registry"))," then also add the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build tree or ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_INSTALL_PREFIX")," folder to the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_PREFIX_PATH"),", so CMake can find TinyORM's package configuration file during ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package(TinyOrm)")," call."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:`cmake (${y.Fo})`,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,k.we)(y.Fo,(0,k.go)(y.Fo))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\n# installation folder - CMAKE_INSTALL_PREFIX\nlist(APPEND CMAKE_PREFIX_PATH "${(0,k.we)(y.Fo,(0,k.EA)(y.Fo))}/tmp/TinyORM")`)),(0,l.kt)(d.Z,{value:y.q5,label:`cmake (${y.q5})`,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,k.we)(y.q5,(0,k.go)(y.q5))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\n# installation folder - CMAKE_INSTALL_PREFIX\nlist(APPEND CMAKE_PREFIX_PATH "${(0,k.we)(y.q5,(0,k.EA)(y.q5))}/tmp/TinyORM")`))),(0,l.kt)("p",null,"Or as an alternative, you can set ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_PREFIX_PATH")," environment variable."),(0,l.kt)("a",{id:"tinyorm-on-path-cmake"}),(0,l.kt)("p",null,"As the last thing, do not forget to add ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm0d.dll")," on the path on Windows and on the ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux, so your application can find it during execution."),(0,l.kt)(p.Z,{groupId:y.IZ,name:"tinyorm-on-path",mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,k.go)(y.Fo,!1)}\\TinyORM\\TinyORM-builds-cmake\\build-debug;" + $env:Path`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export LD_LIBRARY_PATH=${(0,k.go)(y.q5)}/TinyORM/TinyORM-builds-cmake/build-debug\${PATH:+:}$PATH`))),(0,l.kt)("p",null,"Now you can try the ",(0,l.kt)("a",{parentName:"p",href:"/building/hello-world#hello-world-with-cmake"},(0,l.kt)("inlineCode",{parentName:"a"},"HelloWorld CMake"))," example."),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"You can also try the ",(0,l.kt)("a",{parentName:"p",href:"/building/hello-world#fetchcontent"},(0,l.kt)("inlineCode",{parentName:"a"},"FetchContent"))," method to fastly link against the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library.")),(0,l.kt)("h2",{id:"building-with-qmake"},"Building with qmake"),(0,l.kt)("p",null,"First, create a basic folder structure and then clone the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,k.EA)(y.Fo)}\nmkdir ${(0,k.AE)()}/TinyORM/TinyORM-builds-qmake\n\ncd ${(0,k.AE)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,k.EA)(y.q5)}\nmkdir -p ${(0,k.AE)()}/TinyORM/TinyORM-builds-qmake\n\ncd ${(0,k.AE)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`))),(0,l.kt)("h3",{id:"install-dependencies"},"Install dependencies"),(0,l.kt)("p",null,"With the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system, you have to install ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," dependencies manually. We will use the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," package manager."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../../vcpkg\n\nvcpkg search range-v3\nvcpkg search tabulate\nvcpkg install range-v3 tabulate\nvcpkg list\n")),(0,l.kt)("p",null,"On ",(0,l.kt)("inlineCode",{parentName:"p"},"Linux"),", you can install the ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," library and some other ",(0,l.kt)("a",{parentName:"p",href:"/dependencies#install-dependencies"},"dependencies")," with the package manager."),(0,l.kt)("h3",{id:"configure-and-build-qmake"},"Configure & Build ",(0,l.kt)("small",null,"(qmake)")),(0,l.kt)("h4",{id:"open-qtcreator-ide"},"Open QtCreator IDE"),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"I recommend creating a new ",(0,l.kt)("a",{parentName:"p",href:"https://doc.qt.io/qtcreator/creator-project-managing-sessions.html"},(0,l.kt)("inlineCode",{parentName:"a"},"Session"))," in the ",(0,l.kt)("inlineCode",{parentName:"p"},"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,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),". You can name it ",(0,l.kt)("inlineCode",{parentName:"p"},"tinyorm.org")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM examples"),", it is up to you.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"If you are using sessions, you can use a single ",(0,l.kt)("inlineCode",{parentName:"p"},"clangd")," instance for all projects in this session in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),". One significant advantage of this method is that the ",(0,l.kt)("inlineCode",{parentName:"p"},".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,l.kt)("inlineCode",{parentName:"p"},"Settings")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"C++")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Clangd")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Sessions with a single clangd instance"),".")),(0,l.kt)("h4",{id:"configure-tinyorm"},"Configure TinyORM"),(0,l.kt)("p",null,"Now you are ready to configure the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. There are two ways how to configure the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library and it's the new ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configure")," feature added in ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0")," using the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files and the old way using the ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files."),(0,l.kt)("h5",{id:"auto-configuration-and-tiny_dotenv"},"Auto-configuration and tiny_dotenv"),(0,l.kt)("p",null,"This is the new recommended method to auto-configure TinyORM's ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system and also the dependencies, it was added in ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0"),". You need to copy the prepared ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw).example")," file to the ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw)"),". One ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," example file is prepared for each supported platform."),(0,l.kt)("p",null,"All prepared ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw).example")," files are simple and clear. You can also create a common ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," file that is included before the platform-specific ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw)")," files."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,k.go)(y.Fo)}/TinyORM/TinyORM\n\ncp .env.win32.example .env.win32`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,k.go)(y.q5)}/TinyORM/TinyORM\n\ncp .env.unix.example .env.unix`))),(0,l.kt)("p",null,"And that is all, if you have correctly set all ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," variables in this ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw)")," file or you have correctly set environment variables, then the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system should be able to ",(0,l.kt)("inlineCode",{parentName:"p"},"auto-detect")," all dependencies . \ud83d\udd25"),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("a",{parentName:"p",href:"#auto-configuration-internals"},(0,l.kt)("inlineCode",{parentName:"a"},"Auto-configuration"))," and ",(0,l.kt)("a",{parentName:"p",href:"#environment-files"},(0,l.kt)("inlineCode",{parentName:"a"},"Environment files"))," internals are described at the end to make this section more clear.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature can be turned off using the ",(0,l.kt)("a",{parentName:"p",href:"#disable_autoconf"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_autoconf"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_autoconf"),").")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," feature can be turned off using the ",(0,l.kt)("a",{parentName:"p",href:"#disable_dotenv"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_dotenv"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_dotenv"),").")),(0,l.kt)("h5",{id:"manual-configuration-confpri"},"Manual configuration (conf.pri)"),(0,l.kt)("p",null,"This is the old method used before ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0"),". You need to copy the ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri.example")," files to ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," (there are four, one for every project or sub-project) and manually update the ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"LIBS")," to configure TinyORM's ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build dependencies. This way you can override any ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build options or variables."),(0,l.kt)("p",null,"To disable the ",(0,l.kt)("a",{parentName:"p",href:"#auto-configuration-internals"},(0,l.kt)("inlineCode",{parentName:"a"},"Auto-configuration"))," feature you must define the ",(0,l.kt)("a",{parentName:"p",href:"#disable_autoconf"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_autoconf"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_autoconf"),") because from ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0")," is the ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature enabled by default."),(0,l.kt)("p",null,"You can also remove all ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files or turn off the ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," feature using ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_dotenv"),". You can use them all at once if you want, ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," and also ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files."),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files are nicely commented on, so you can see what needs to be modified."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,k.go)(y.Fo)}/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,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,k.go)(y.q5)}/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,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("a",{parentName:"p",href:"#manual-configuration-internals"},(0,l.kt)("inlineCode",{parentName:"a"},"Manual configuration"))," internals are described at the end to make this section more clear.")),(0,l.kt)("admonition",{type:"note"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Manual configuration")," is still relevant if you have any non-standard installation of the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"MySQL")," and the ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature fails.")),(0,l.kt)("h5",{id:"opening-tinyormpro-main-project-file"},"Opening TinyORM.pro (main project file)"),(0,l.kt)("p",null,"Now you can open the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM.pro")," project in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),"."),(0,l.kt)("p",null,"This will open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Configure Project")," tab, select some kit and update build folder paths to meet our ",(0,l.kt)("a",{parentName:"p",href:"#folders-structure"},"folders structure")," or like you want."),(0,l.kt)("img",{src:n(6874).Z,alt:"TinyORM - QtCreator - Configure Project",width:"760"}),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can force the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator")," to generate a build folders structure as is described ",(0,l.kt)("a",{parentName:"p",href:"#qtcreator-default-build-directory"},"above"),".")),(0,l.kt)("p",null,"You are ready to configure build options, hit ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"5")," to open ",(0,l.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,l.kt)("inlineCode",{parentName:"p"},"Build")," in the left sidebar to open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Build Settings"),", it should look similar to the following picture."),(0,l.kt)("p",null,"Disable ",(0,l.kt)("inlineCode",{parentName:"p"},"QML debugging and profiling")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt Quick Compiler"),", they are not used."),(0,l.kt)("img",{src:n(7066).Z,alt:"TinyORM - QtCreator - Build Settings",width:"760"}),(0,l.kt)("p",null,"If you want to change some ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build options, you can pass them to the ",(0,l.kt)("inlineCode",{parentName:"p"},"Build Steps")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake TinyORM.pro")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Additional arguments")," input field. It can look like this."),(0,l.kt)("img",{src:n(5705).Z,alt:"TinyORM - QtCreator - Build Settings - Additional arguments",width:"660"}),(0,l.kt)("h4",{id:"build-tinyorm-1"},"Build TinyORM"),(0,l.kt)("p",null,"Everything is ready for build, you can press ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"b")," to build the project."),(0,l.kt)("h3",{id:"qmake-build-options"},"qmake build options"),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"th"},"CONFIG")," ",(0,l.kt)("small",null,"Option Name")),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"build_loadable_drivers")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyDrivers")," as a shared library and SQL database drivers (eg. ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyMySql"),") as shared libraries (",(0,l.kt)("a",{parentName:"td",href:"/tinydrivers/getting-started#the-loadable-sql-drivers-build"},(0,l.kt)("inlineCode",{parentName:"a"},"Loadable"))," modules) that are loaded at runtime using ",(0,l.kt)("inlineCode",{parentName:"td"},"LoadLibrary()")," on Windows or ",(0,l.kt)("inlineCode",{parentName:"td"},"dlopen()")," on Linux.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"build_mysql_driver")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyDrivers")," MySQL database driver.",(0,l.kt)("br",null),(0,l.kt)("small",null,"It's enabled by default when ",(0,l.kt)("inlineCode",{parentName:"td"},"build_shared_drivers"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"build_loadable_drivers"),", or ",(0,l.kt)("inlineCode",{parentName:"td"},"build_static_drivers")," is enabled.",(0,l.kt)("br",null),"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"build_shared_drivers")," OR ",(0,l.kt)("inlineCode",{parentName:"td"},"build_loadable_drivers")," OR ",(0,l.kt)("inlineCode",{parentName:"td"},"build_static_drivers")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"build_shared_drivers")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyDrivers")," as a ",(0,l.kt)("a",{parentName:"td",href:"/tinydrivers/getting-started#the-shared-library-build"},(0,l.kt)("inlineCode",{parentName:"a"},"Shared"))," library.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"build_static_drivers")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyDrivers")," as a ",(0,l.kt)("a",{parentName:"td",href:"/tinydrivers/getting-started#the-static-build"},(0,l.kt)("inlineCode",{parentName:"a"},"Static"))," library archive.",(0,l.kt)("br",null),(0,l.kt)("small",null,"The ",(0,l.kt)("inlineCode",{parentName:"td"},"build_static_drivers")," ",(0,l.kt)("inlineCode",{parentName:"td"},"qmake")," configuration option will be select by default when the ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG*=staticlib")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"build_tests")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build TinyORM unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_autoconf")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Disable the ",(0,l.kt)("a",{parentName:"td",href:"#auto-configuration-internals"},(0,l.kt)("inlineCode",{parentName:"a"},"Auto-configuration"))," feature ",(0,l.kt)("small",null,"(auto-configuration is enabled by default from ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"td"},"v0.34.0"),")"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_dotenv")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Disable the ",(0,l.kt)("a",{parentName:"td",href:"#environment-files"},(0,l.kt)("inlineCode",{parentName:"a"},"tiny_dotenv"))," feature ",(0,l.kt)("small",null,"(environment files are enabled by default from ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"td"},"v0.34.0"),")"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_thread_local")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Remove all ",(0,l.kt)("a",{parentName:"td",href:"https://en.cppreference.com/w/c/language/storage_duration"},(0,l.kt)("inlineCode",{parentName:"a"},"thread_local"))," storage duration specifiers, it disables multi-threading support.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_orm")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," source code, when this option is ",(0,l.kt)("inlineCode",{parentName:"td"},"enabled"),", then only the ",(0,l.kt)("inlineCode",{parentName:"td"},"query builder")," without ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM")," is compiled. Also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_tom")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"Tom-related")," source code, when this option is ",(0,l.kt)("inlineCode",{parentName:"td"},"disabled"),", then it also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"Tom-related")," unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"extern_constants")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Use ",(0,l.kt)("inlineCode",{parentName:"td"},"extern")," constants instead of ",(0,l.kt)("inlineCode",{parentName:"td"},"inline")," constants in the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),".",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"ON")," is highly recommended for the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build")," ",(0,l.kt)("small",null,"(by default)"),";",(0,l.kt)("br",null),"is always ",(0,l.kt)("inlineCode",{parentName:"td"},"OFF")," for the ",(0,l.kt)("inlineCode",{parentName:"td"},"static build"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("code",null,"CONFIG(shared","|","dll):!inline_constants")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"inline_constants")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Use ",(0,l.kt)("inlineCode",{parentName:"td"},"inline")," constants instead of ",(0,l.kt)("inlineCode",{parentName:"td"},"extern")," constants in the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),".",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"OFF")," is highly recommended for the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),";",(0,l.kt)("br",null),"is always ",(0,l.kt)("inlineCode",{parentName:"td"},"ON")," for the ",(0,l.kt)("inlineCode",{parentName:"td"},"static build"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"link_pkgconfig_off")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Link against ",(0,l.kt)("inlineCode",{parentName:"td"},"mysqlclient")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"libmariadb")," with ",(0,l.kt)("inlineCode",{parentName:"td"},"PKGCONFIG"),".",(0,l.kt)("br",null),"Used only in the ",(0,l.kt)("inlineCode",{parentName:"td"},"Unix")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"MinGW")," ",(0,l.kt)("strong",{parentName:"td"},"shared")," build ",(0,l.kt)("small",null,"(exactly ",(0,l.kt)("code",null,"win32-g++","|","win32-clang-g++"),")")," and when ",(0,l.kt)("inlineCode",{parentName:"td"},"mysql_ping")," is also defined to link against ",(0,l.kt)("inlineCode",{parentName:"td"},"mysqlclient")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"libmariadb"),", ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L132"},"source code"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"unix:mysql_ping")," or ",(0,l.kt)("code",null,"(win32-g++","|","win32-clang-g++):mysql_ping:!static:!staticlib")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"mysql_ping")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable ",(0,l.kt)("inlineCode",{parentName:"td"},"Orm::MySqlConnection::pingDatabase()")," method.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"tiny_ccache_win32")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable compiler cache. ",(0,l.kt)("a",{parentName:"td",href:"https://ccache.dev/"},"Homepage"),(0,l.kt)("br",null),(0,l.kt)("small",null,"It works only on Windows systems. It works well with the MSYS2 ",(0,l.kt)("inlineCode",{parentName:"td"},"g++"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"clang++"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc"),", and ",(0,l.kt)("inlineCode",{parentName:"td"},"clang-cl")," with ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc"),". It disables ",(0,l.kt)("inlineCode",{parentName:"td"},"precompile_header")," as they are not supported on Windows and changes the ",(0,l.kt)("inlineCode",{parentName:"td"},"-Zi")," compiler option to the ",(0,l.kt)("inlineCode",{parentName:"td"},"-Z7")," for debug builds as the ",(0,l.kt)("inlineCode",{parentName:"td"},"-Zi")," compiler option is not supported (",(0,l.kt)("a",{parentName:"td",href:"https://github.com/ccache/ccache/issues/1040"},"link")," to the issue)."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"tom_example")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build the ",(0,l.kt)("abbr",{title:"TinyORM Migrations"},(0,l.kt)("inlineCode",{parentName:"td"},"tom"))," console application example.")))))),(0,l.kt)("p",null,"Advanced ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," options."),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Option Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ubsan")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Allows to enable ",(0,l.kt)("a",{parentName:"td",href:"https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html"},"UBSan")," sanitizer (Clang only).")))))),(0,l.kt)("p",null,"Important ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," options."),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"th"},"CONFIG")," ",(0,l.kt)("small",null,"Option Name")),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ccache")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable compiler cache. ",(0,l.kt)("a",{parentName:"td",href:"https://ccache.dev/"},"Homepage"),(0,l.kt)("br",null),(0,l.kt)("small",null,"It works only on the Unix systems. It works well with the ",(0,l.kt)("inlineCode",{parentName:"td"},"g++")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"clang++")," and also supports precompiled headers."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"precompile_header")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable precompiled headers, you can disable them with:",(0,l.kt)("br",null)," ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG-=precompile_header"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"The ",(0,l.kt)("inlineCode",{parentName:"td"},"precompile_header")," is enabled by default on ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"g++"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"clang++"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"clang-cl")," on ",(0,l.kt)("inlineCode",{parentName:"td"},"Windows")," and disabled by default on ",(0,l.kt)("inlineCode",{parentName:"td"},"linux"),"."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"static"),(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"staticlib")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build as a ",(0,l.kt)("inlineCode",{parentName:"td"},"static")," library (lib only).",(0,l.kt)("br",null),(0,l.kt)("small",null,"If you want to build all libraries in the ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," project as static library archives and link against static libraries use the ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG += static"),". Don't use the ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG += staticlib"),".",(0,l.kt)("br",null),"See ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/NOTES.txt"},"NOTES.txt")," for more information (search ",(0,l.kt)("inlineCode",{parentName:"td"},"static vs staticlib"),")."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"static_runtime")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Link against the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared")," (dynamic) or ",(0,l.kt)("inlineCode",{parentName:"td"},"static")," run-time library.",(0,l.kt)("br",null),(0,l.kt)("small",null,"The ",(0,l.kt)("inlineCode",{parentName:"td"},"-MD")," becomes ",(0,l.kt)("inlineCode",{parentName:"td"},"-MT")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"-MDd")," becomes ",(0,l.kt)("inlineCode",{parentName:"td"},"-MTd"),". It works only on ",(0,l.kt)("inlineCode",{parentName:"td"},"MSVC")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"MinGW")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"MSYS2"),".",(0,l.kt)("br",null),"Please ",(0,l.kt)("u",null,"don't use")," this option.",(0,l.kt)("br",null),"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"mingw")))))))),(0,l.kt)("h3",{id:"consume-tinyorm-library-qmake"},"Consume TinyOrm library ",(0,l.kt)("small",null,"(qmake)")),(0,l.kt)("p",null,"The ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/qmake/TinyOrm.pri"},(0,l.kt)("inlineCode",{parentName:"a"},"TinyOrm.pri"))," file is available to simplify the integration of the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library into your application. It sets up and configures the ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"DEFINES")," qmake variables, adds the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM"),", ",(0,l.kt)("abbr",{title:"TinyORM Migrations"},(0,l.kt)("inlineCode",{parentName:"p"},"tom")),", and ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," header files on the system ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," (cross-platform using the ",(0,l.kt)("inlineCode",{parentName:"p"},"-isystem")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"-imsvc"),"), links against the TinyORM ",(0,l.kt)("inlineCode",{parentName:"p"},"shared")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"static")," library using the ",(0,l.kt)("inlineCode",{parentName:"p"},"LIBS"),"."),(0,l.kt)("p",null,"You can use it to configure the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library when you are linking against it. It does a very similar thing like the CMake's ",(0,l.kt)("inlineCode",{parentName:"p"},"Find Modules")," feature."),(0,l.kt)("h4",{id:"requirements"},"Requirements"),(0,l.kt)("p",null,"It has a few requirements, you need to:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"specify path to the ",(0,l.kt)("inlineCode",{parentName:"li"},"TinyORM")," qmake features (",(0,l.kt)("inlineCode",{parentName:"li"},".prf")," files) using the ",(0,l.kt)("inlineCode",{parentName:"li"},"QMAKEFEATURES")," variable that can only be set in the ",(0,l.kt)("inlineCode",{parentName:"li"},".qmake.conf")," file"),(0,l.kt)("li",{parentName:"ul"},"specify ",(0,l.kt)("inlineCode",{parentName:"li"},"qmake")," or ",(0,l.kt)("inlineCode",{parentName:"li"},"environment")," variables to find the ",(0,l.kt)("inlineCode",{parentName:"li"},"vcpkg")," installation ",(0,l.kt)("small",null,"(",(0,l.kt)("inlineCode",{parentName:"li"},"TINY_VCPKG_ROOT")," and ",(0,l.kt)("inlineCode",{parentName:"li"},"TINY_VCPKG_TRIPLET"),")")),(0,l.kt)("li",{parentName:"ul"},"specify path to the ",(0,l.kt)("inlineCode",{parentName:"li"},"TinyORM")," build folder ",(0,l.kt)("small",null,"(",(0,l.kt)("inlineCode",{parentName:"li"},"TINYORM_BUILD_TREE"),")"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},"you can specify it ",(0,l.kt)("strong",{parentName:"li"},"manually")),(0,l.kt)("li",{parentName:"ul"},"or you can use ",(0,l.kt)("a",{parentName:"li",href:"#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))))),(0,l.kt)("li",{parentName:"ul"},"build your application with the same ",(0,l.kt)("inlineCode",{parentName:"li"},"CONFIG")," ",(0,l.kt)("inlineCode",{parentName:"li"},"qmake")," variables that were used when building the ",(0,l.kt)("inlineCode",{parentName:"li"},"TinyORM")," library")),(0,l.kt)("p",null,"Let's explain one by one."),(0,l.kt)("h5",{id:"qmakefeatures"},(0,l.kt)("inlineCode",{parentName:"h5"},"QMAKEFEATURES")),(0,l.kt)("p",null,"Create the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file in your application root folder with the following content."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# 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")),(0,l.kt)("p",null,"You can move all ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," variables that are part of the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration process to the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," file if you want (recommended), this is possible because the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," enables the ",(0,l.kt)("a",{parentName:"p",href:"#environment-files"},(0,l.kt)("inlineCode",{parentName:"a"},"Environment files"))," feature by default."),(0,l.kt)("p",null,"You can look at the ",(0,l.kt)("a",{parentName:"p",href:"/building/hello-world#auto-configure-using-qmake_conf-and-env"},"Auto-configure using .qmake.conf and .env")," example for ",(0,l.kt)("inlineCode",{parentName:"p"},"Hello world")," project of what must stay in the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake.conf")," file and what can be moved to the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can use the ",(0,l.kt)("a",{parentName:"p",href:"#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," if you don't like to specify it manually.")),(0,l.kt)("h5",{id:"variables-affecting-tinyormpri"},"Variables affecting ",(0,l.kt)("inlineCode",{parentName:"h5"},"TinyOrm.pri")),(0,l.kt)("p",null,"You must define the following variables before the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," is included:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_BUILD_TREE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," build folder.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_ROOT")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," installation folder.",(0,l.kt)("br",null),"If not defined, then it tries to use the ",(0,l.kt)("inlineCode",{parentName:"td"},"VCPKG_ROOT")," environment variable.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_TRIPLET")),(0,l.kt)("td",{parentName:"tr",align:null},"The ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"triplet")," to use ",(0,l.kt)("small",null,"(vcpkg/installed/$$TINY_VCPKG_TRIPLET/)"),".",(0,l.kt)("br",null),"If not defined, then it tries to guess the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"triplet")," based on the current compiler and OS (based on the ",(0,l.kt)("inlineCode",{parentName:"td"},"QMAKESPEC"),"), and as the last thing, it tries to use the ",(0,l.kt)("inlineCode",{parentName:"td"},"VCPKG_DEFAULT_TRIPLET")," environment variable.")))),(0,l.kt)("p",null,"These variables will be set after the configuration is done:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_BUILD_SUBFOLDER")),(0,l.kt)("td",{parentName:"tr",align:null},"Folder by release type if ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG+=debug_and_release")," is defined ",(0,l.kt)("small",null,"(/debug, /release, or an empty string)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_CCACHE_BUILD")),(0,l.kt)("td",{parentName:"tr",align:null},"To correctly link ",(0,l.kt)("inlineCode",{parentName:"td"},"ccache")," build against a ",(0,l.kt)("inlineCode",{parentName:"td"},"ccache")," build ",(0,l.kt)("small",null,"(_ccache or an empty string)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MSVC_VERSION")),(0,l.kt)("td",{parentName:"tr",align:null},"The ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc")," compiler string ",(0,l.kt)("small",null,"(MSVC2022 or MSVC2019)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_QT_VERSION_UNDERSCORED")),(0,l.kt)("td",{parentName:"tr",align:null},"Underscored ",(0,l.kt)("inlineCode",{parentName:"td"},"Qt")," version ",(0,l.kt)("small",null,"(eg. 6_7_0)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_RELEASE_TYPE_CAMEL")),(0,l.kt)("td",{parentName:"tr",align:null},"Build type string ",(0,l.kt)("small",null,"(Debug, Profile, or Release)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_INCLUDE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"include")," folder ",(0,l.kt)("small",null,"(vcpkg/installed/","<","triplet",">","/include/)"),".")))),(0,l.kt)("p",null,"Then you simply include the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," in your project file."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='AnyProject.pro'",title:"'AnyProject.pro'"},"include($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n")),(0,l.kt)("p",null,"And that is all, now you should be able to link against the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. \ud83d\udc4c"),(0,l.kt)("h5",{id:"manual-configuration-examples"},"Manual configuration examples"),(0,l.kt)("p",null,"Frankly, there is no reason to use the Manual configuration (define the variables described below before the ",(0,l.kt)("inlineCode",{parentName:"p"},"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."),(0,l.kt)("p",null,"You will have to link against the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library manually if you don't set the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," variable before the inclusion of the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," file. The ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," is auto-detected every time."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"{9}","{9}":!0},"# 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,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"{9}","{9}":!0},"# 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")))),(0,l.kt)("p",null,"The same is true for the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," include path. If you don't set the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_VCPKG_ROOT")," or have not defined the ",(0,l.kt)("inlineCode",{parentName:"p"},"VCPKG_ROOT")," environment variable, then you need to set up the ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," for the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," that provides the ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," header files."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# vcpkg - range-v3 and tabulate\n# ---\nINCLUDEPATH += $$quote(/vcpkg/installed/x64-windows/include/)\n"))),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# vcpkg - range-v3 and tabulate\n# ---\nQMAKE_CXXFLAGS += -isystem $$shell_quote(/vcpkg/installed/x64-linux/include/)\n")))),(0,l.kt)("p",null,"You can also use TinyORM's ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," function ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_add_system_includepath()")," which handles ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," in a cross-platform way."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# vcpkg - range-v3 and tabulate\n# ---\nload(tiny_system_includepath)\ntiny_add_system_includepath(/vcpkg/installed/x64-linux/include/)\n")),(0,l.kt)("p",null,"Do not forget to add ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm0.dll")," on the path on Windows and on the ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux, so your application can find it during execution."),(0,l.kt)(p.Z,{groupId:y.IZ,name:"tinyorm-on-path",mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,k.go)(y.Fo,!1)}\\TinyORM\\TinyORM-builds-qmake\\build-debug;" + $env:Path`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export LD_LIBRARY_PATH=${(0,k.go)(y.q5)}/TinyORM/TinyORM-builds-qmake/build-debug\${PATH:+:}$PATH`))),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"On Linux ",(0,l.kt)("inlineCode",{parentName:"p"},"-isystem")," marks the directory as a system directory, it prevents warnings."),(0,l.kt)("p",{parentName:"admonition"},"On Windows you can use ",(0,l.kt)("inlineCode",{parentName:"p"},"QMAKE_CXXFLAGS_WARN_ON = -external:anglebrackets -external:W0"),", it applies a warning level 0 to the angel bracket includes; ",(0,l.kt)("inlineCode",{parentName:"p"},"#include "),"."),(0,l.kt)("p",{parentName:"admonition"},"With the ",(0,l.kt)("inlineCode",{parentName:"p"},"clang-cl")," with ",(0,l.kt)("inlineCode",{parentName:"p"},"MSVC")," you can use ",(0,l.kt)("inlineCode",{parentName:"p"},"-imsvc"),".")),(0,l.kt)("h3",{id:"auto-configuration-internals"},"Auto-configuration internals"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system does not support ",(0,l.kt)("inlineCode",{parentName:"p"},"auto-configuration")," of dependencies out of the box but ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," from ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0")," added its own ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature along with the ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," qmake feature. These new features allow us to ",(0,l.kt)("inlineCode",{parentName:"p"},"auto-configure")," ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project, and with their help, the ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files can be ",(0,l.kt)("u",null,"skipped entirely"),"."),(0,l.kt)("p",null,"While it adds additional complexity to the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration process, the benefits are significant."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature is designed to find the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"MySQL")," installations, and ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," to include the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," and ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw)")," files in the project's root folder. These new features can be configured using ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"environment")," variables, and they also contain some guessing logic if these variables are not defined."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature can be turned off using the ",(0,l.kt)("a",{parentName:"p",href:"#disable_autoconf"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_autoconf"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_autoconf"),")."),(0,l.kt)("p",null,"These are ",(0,l.kt)("u",null,(0,l.kt)("inlineCode",{parentName:"p"},"qmake"))," and ",(0,l.kt)("u",null,(0,l.kt)("inlineCode",{parentName:"p"},"environment"))," variables that affect the ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_ROOT")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," installation folder.",(0,l.kt)("br",null),"If not defined, then it tries to use the ",(0,l.kt)("inlineCode",{parentName:"td"},"VCPKG_ROOT")," environment variable.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_TRIPLET")),(0,l.kt)("td",{parentName:"tr",align:null},"The ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"triplet")," to use ",(0,l.kt)("small",null,"(vcpkg/installed/$$TINY_VCPKG_TRIPLET/)"),".",(0,l.kt)("br",null),"If not defined, then it tries to guess the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"triplet")," based on the current compiler and OS (based on the ",(0,l.kt)("inlineCode",{parentName:"td"},"QMAKESPEC"),"), and as the last thing, it tries to use the ",(0,l.kt)("inlineCode",{parentName:"td"},"VCPKG_DEFAULT_TRIPLET")," environment variable.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MYSQL_ROOT")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"MySQL")," installation folder.",(0,l.kt)("br",null),"If not defined, then it tries to guess the ",(0,l.kt)("inlineCode",{parentName:"td"},"MySQL")," installation folder (",(0,l.kt)("inlineCode",{parentName:"td"},"win32")," only): ",(0,l.kt)("code",null,"$$(ProgramFiles)/MySQL/MySQL Server (8.3","|","8.2","|","8.1","|","8.0","|","5.7)/"))))),(0,l.kt)("p",null,"You can set these variables in the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," (recommended) or ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files, in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file (or wherever you want), or as environment variables."),(0,l.kt)("p",null,"These variables will be set after ",(0,l.kt)("inlineCode",{parentName:"p"},"auto-configuration")," is done:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_INCLUDE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"include")," folder ",(0,l.kt)("small",null,"(vcpkg/installed/","<","triplet",">","/include/)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MYSQL_INCLUDE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"MySQL")," ",(0,l.kt)("inlineCode",{parentName:"td"},"include")," folder ",(0,l.kt)("small",null,"(MySQL Server 8.3/include/)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MYSQL_LIB")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"MySQL")," ",(0,l.kt)("inlineCode",{parentName:"td"},"lib")," folder ",(0,l.kt)("small",null,"(MySQL Server 8.3/lib/)"),".")))),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_MYSQL_INCLUDE")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_MYSQL_LIB")," are only set on ",(0,l.kt)("inlineCode",{parentName:"p"},"win32")," platform except ",(0,l.kt)("inlineCode",{parentName:"p"},"mingw"),"."),(0,l.kt)("h4",{id:"environment-files"},"Environment files"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," feature allows us to define the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," and ",(0,l.kt)("inlineCode",{parentName:"p"},".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,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration process. On the other hand, the ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files are loaded as late as possible, and they can be used to override the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," file is included ",(0,l.kt)("u",null,"first")," and is included on all platforms."),(0,l.kt)("p",null,"There is only one requirement for this feature to work correctly, and that is to set the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_DOTENV_ROOT")," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," variable to the project's root folder. This variable is ",(0,l.kt)("strong",{parentName:"p"},"already")," set in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file for the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project."),(0,l.kt)("p",null,"Then the following names are taken into account: .env, .env.win32, .env.unix, .env.mingw"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# To find .env and .env.$$QMAKE_PLATFORM files\nTINY_DOTENV_ROOT = $$PWD\n")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," feature can be turned off using the ",(0,l.kt)("a",{parentName:"p",href:"#disable_dotenv"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_dotenv"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_dotenv"),")."),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},(0,l.kt)("inlineCode",{parentName:"p"},"Environment files")," don't work in the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," builds.")),(0,l.kt)("h4",{id:"partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"h4"},"TINYORM_BUILD_TREE")),(0,l.kt)("p",null,"You don't have to manually define the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," in ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," or ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," files. The ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," absolute path can be put together for you (this is happening inside the ",(0,l.kt)("inlineCode",{parentName:"p"},"variables.pri")," file) and ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build folder name can be guessed for you too."),(0,l.kt)("p",null,"You must define the following variables before the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," will be included to make this real (set them in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf"),"):"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MAIN_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("strong",{parentName:"td"},"PARENT")," folder of the ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," source folder.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_BUILD_TREE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("strong",{parentName:"td"},"current")," build tree - ",(0,l.kt)("inlineCode",{parentName:"td"},"TINY_BUILD_TREE = $$shadowed($$PWD)"),".")))),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"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,l.kt)("inlineCode",{parentName:"p"},"TINY_BUILD_TREE"),"."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# Path to the current build tree (used to guess the TinyORM build tree)\nTINY_BUILD_TREE = $$shadowed($$PWD)\n")),(0,l.kt)("p",null,"If you will follow this pattern or logic then you can switch ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator Kits")," and the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," will be ",(0,l.kt)("strong",{parentName:"p"},"auto-generated")," correctly and will always point to the correct ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build tree."),(0,l.kt)("p",null,"It works this way, all is happening inside the ",(0,l.kt)("inlineCode",{parentName:"p"},"variables.pri"),", it takes a build folder name for the ",(0,l.kt)("strong",{parentName:"p"},"current")," project eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"build-HelloWorld-Desktop_Qt_6_7_0_MSVC2022_64bit-Debug"),", replaces the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," with the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," and as we already know the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build folder location we can simply concatenate these paths like ",(0,l.kt)("inlineCode",{parentName:"p"},"$$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSVC2022_64bit-Debug"),"."),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"This will only work if you follow the recommended ",(0,l.kt)("a",{parentName:"p",href:"#folders-structure"},(0,l.kt)("inlineCode",{parentName:"a"},"Folders structure")),".")),(0,l.kt)("h3",{id:"manual-configuration-internals"},"Manual configuration internals"),(0,l.kt)("p",null,"There is not much to say about the ",(0,l.kt)("inlineCode",{parentName:"p"},"Manual configuration")," feature. It uses ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files (there are four, one for every project or sub-project), and every project has prepared its own ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri.example")," file for faster initial configuration."),(0,l.kt)("p",null,"These ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri.example")," files are nicely commented on, so you can see what needs to be modified. The ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files are loaded as late as possible, and they can be used to override the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration."),(0,l.kt)("p",null,"If the ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature is disabled and there are no ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files, then the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration or build will fail at 100%."),(0,l.kt)("p",null,"These ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files are intended for configuring qmake's ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"LIBS"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG")," or eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"QMAKE_LFLAGS"),", or any other ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," options or variables."),(0,l.kt)("h2",{id:"ccache-support"},"Ccache support"),(0,l.kt)("p",null,"The TinyORM supports the ",(0,l.kt)("a",{parentName:"p",href:"https://ccache.dev/"},(0,l.kt)("inlineCode",{parentName:"a"},"ccache"))," out of the box for all ",(0,l.kt)("a",{parentName:"p",href:"/supported-compilers"},"supported compilers"),". For qmake you can enable it using the ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG+=ccache")," on Linux or ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG+=tiny_ccache_win32")," on Windows. For CMake you can set the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_CXX_COMPILER_LAUNCHER=ccache"),"."),(0,l.kt)("p",null,"On ",(0,l.kt)("inlineCode",{parentName:"p"},"Linux")," it's clear, the ccache is fully supported and works also with the ",(0,l.kt)("inlineCode",{parentName:"p"},"precompiled headers"),". But was necessary to add some workarounds to the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake"),"/",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," build systems to make out of the box support on ",(0,l.kt)("inlineCode",{parentName:"p"},"Windows"),". When you enable the ",(0,l.kt)("inlineCode",{parentName:"p"},"ccache")," on ",(0,l.kt)("inlineCode",{parentName:"p"},"Windows")," then the build system disables ",(0,l.kt)("inlineCode",{parentName:"p"},"precompiled headers")," and replaces the ",(0,l.kt)("inlineCode",{parentName:"p"},"-Zi")," compiler option with the ",(0,l.kt)("inlineCode",{parentName:"p"},"-Z7")," (link to the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/ccache/ccache/issues/1040"},"issue"),")."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can install the ccache using the ",(0,l.kt)("inlineCode",{parentName:"p"},"scoop install ccache")," command on Windows.")))}R.isMDXComponent=!0},5705:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-additional_arguments-14d3b6b82ad6d28db5b999a462500a6a.png"},7066:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-build_settings-7caa6d7c86232484b82acb24b5a3a6a7.png"},6874:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-configure_project-0b6821ea0523567dab9f21b3215055a3.png"}}]); \ No newline at end of file diff --git a/assets/js/0ab078a9.6ef4dbfd.js b/assets/js/0ab078a9.6ef4dbfd.js deleted file mode 100644 index 02bbb88c8..000000000 --- a/assets/js/0ab078a9.6ef4dbfd.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[969],{5162:(e,t,n)=>{n.d(t,{Z:()=>r});var a=n(7294),i=n(6010);const l={tabItem:"tabItem_Ymn6"};function r(e){let{children:t,hidden:n,className:r}=e;return a.createElement("div",{role:"tabpanel",className:(0,i.Z)(l.tabItem,r),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>f});var a=n(7462),i=n(7294),l=n(6010),r=n(2466),o=n(6550),d=n(1980),p=n(7392),m=n(12);function s(e){return function(e){return i.Children.map(e,(e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:i}}=e;return{value:t,label:n,attributes:a,default:i}}))}function u(e){const{values:t,children:n}=e;return(0,i.useMemo)((()=>{const e=t??s(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function k(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function N(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,d._X)(l),(0,i.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function c(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=u(e),[r,o]=(0,i.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!k({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[d,p]=N({queryString:n,groupId:a}),[s,c]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,m.Nk)(n);return[a,(0,i.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),h=(()=>{const e=d??s;return k({value:e,tabValues:l})?e:null})();(0,i.useLayoutEffect)((()=>{h&&o(h)}),[h]);return{selectedValue:r,selectValue:(0,i.useCallback)((e=>{if(!k({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);o(e),p(e),c(e)}),[p,c,l]),tabValues:l}}var h=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function g(e){let{className:t,block:n,selectedValue:o,selectValue:d,tabValues:p}=e;const m=[],{blockElementScrollPositionUntilNextRender:s}=(0,r.o5)(),u=e=>{const t=e.currentTarget,n=m.indexOf(t),a=p[n].value;a!==o&&(s(t),d(a))},k=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=m.indexOf(e.currentTarget)+1;t=m[n]??m[0];break}case"ArrowLeft":{const n=m.indexOf(e.currentTarget)-1;t=m[n]??m[m.length-1];break}}t?.focus()};return i.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},p.map((e=>{let{value:t,label:n,attributes:r}=e;return i.createElement("li",(0,a.Z)({role:"tab",tabIndex:o===t?0:-1,"aria-selected":o===t,key:t,ref:e=>m.push(e),onKeyDown:k,onClick:u},r,{className:(0,l.Z)("tabs__item",b.tabItem,r?.className,{"tabs__item--active":o===t})}),n??t)})))}function C(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,i.cloneElement)(e,{className:"margin-top--md"}):null}return i.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,i.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function y(e){const t=c(e);return i.createElement("div",{className:(0,l.Z)("tabs-container",b.tabList)},i.createElement(g,(0,a.Z)({},e,t)),i.createElement(C,(0,a.Z)({},e,t)))}function f(e){const t=(0,h.Z)();return i.createElement(y,(0,a.Z)({key:String(t)},e))}},5178:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(7294),i=n(6550);const l={apiTable:"apiTable_flxF"};const r=(0,a.forwardRef)(((e,t)=>{let{name:n,children:l}=e;const r=function(e){let t=e;for(;(0,a.isValidElement)(t);)[t]=a.Children.toArray(t.props.children);return t}(l),o=n?`#${n}-${r}`:`#${r}`,d=(0,i.k6)();return a.createElement("tr",{id:r,tabIndex:0,ref:d.location.hash===o?t:void 0,onClick:()=>{d.push(o)},onKeyDown:e=>{"Enter"===e.key&&d.push(o)}},l.props.children)}));function o(e){let{children:t,name:n}=e;const[i,o]=a.Children.toArray(t.props.children),d=(0,a.useRef)(null);(0,a.useEffect)((()=>{d.current?.focus()}),[d]);const p=a.Children.map(o.props.children,(e=>a.createElement(r,{name:n,ref:d},e)));return a.createElement("table",{className:l.apiTable},i,a.createElement("tbody",null,p))}},2044:(e,t,n)=>{n.d(t,{$t:()=>s,Ae:()=>h,C:()=>N,DK:()=>b,Fo:()=>o,Fs:()=>i,IM:()=>c,IZ:()=>a,RS:()=>_,VE:()=>g,Wg:()=>y,_A:()=>p,al:()=>T,jk:()=>k,js:()=>d,of:()=>m,q5:()=>r,qb:()=>f,vk:()=>u,wU:()=>l,zg:()=>C});const a="shell",i="database",l="application",r="bash",o="pwsh",d="zsh",p="maria",m="mysql",s="postgres",u="sqlite",k="application",N="bash",c="pwsh",h="zsh",b="MariaDB",g="MySQL",C="PostgreSQL",y="SQLite",f="tinyorm.org",T="$HOME/Code/c/",_="$env:USERPROFILE\\Code\\c\\"},4355:(e,t,n)=>{n.d(t,{Z:()=>l});var a=n(7294),i=n(9482);function l(){const e=(0,a.useContext)(i.Z);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6005:(e,t,n)=>{n.d(t,{AE:()=>o,EA:()=>r,em:()=>p,go:()=>d,mT:()=>m,we:()=>s});var a=n(4355),i=n(2389),l=n(2044);const r=function(e,t){return void 0===t&&(t=!0),u((0,a.Z)().rootFolder[e]??p(e),e,t)},o=()=>(0,a.Z)().rootFolder[l.wU]??p(l.wU),d=function(e,t){if(void 0===t&&(t=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const n=t||e!==l.Fo?"/":"\\";return u(r(e)+n+o(),e,t)};function p(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,i.Z)())return"";switch(e){case l.Fo:return l.RS;case l.q5:return l.al;case l.wU:return l.qb;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function m(e){return e===l.wU}function s(e,t){if(null==t||""===t)return t;const n="$ENV{$1}$2";switch(e){case l.Fo:return N(t).replace(/\$env:(.+?)(\/.*)/,n);case l.q5:return t.replace(/\$(.+?)(\/.*)/,n);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function u(e,t,n){if(void 0===n&&(n=!0),null==e||""===e)return e;if(t!==l.Fo)return k(e);const a=k(e);return n?N(a):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(a)}function k(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function N(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},4040:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>v,contentTitle:()=>T,default:()=>R,frontMatter:()=>f,metadata:()=>_,toc:()=>O});var a=n(7462),i=n(7294),l=n(3905),r=n(5178),o=n(7693),d=n(5162),p=n(4866),m=n(5697),s=n.n(m),u=n(6005);function k(e){let{groupId:t}=e;return i.createElement("span",null,(0,u.go)(t))}k.propTypes={groupId:s().string.isRequired};const N=k;var c=n(6010),h=n(4355);const b={rootFolderInput:"rootFolderInput_ottS",input:"input_OR7e",application:"application_fjej"};function g(e){let{groupId:t,label:n}=e;const{rootFolder:a,setRootFolder:l}=(0,h.Z)(),r=(0,u.mT)(t),o=r?"application":"root",d=r?"\nThis folder name is common for all shells (eg. pwsh, bash, ...)":"";return i.createElement("form",{name:"tinyorm-root-folder-form",className:(0,c.Z)(b.rootFolderInput,b[t],t),onSubmit:e=>{e.preventDefault(),e.stopPropagation()}},i.createElement("input",{name:"tinyorm-root-folder-input",className:(0,c.Z)(b.input,b[t],t),placeholder:`Enter ${o} folder...`,title:`This ${o} folder will be used in all ${n} examples at tinyorm.org${d}`,onChange:e=>{l(t,e.target.value)},value:a[t]??(0,u.em)(t)}))}g.propTypes={groupId:s().string.isRequired,label:s().string.isRequired};const C=g;var y=n(2044);const f={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"]},T="Building: TinyORM",_={unversionedId:"building/tinyorm",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,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/building/tinyorm.mdx",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:"Serialization",permalink:"/tinyorm/serialization"},next:{title:"Hello world",permalink:"/building/hello-world"}},v={},O=[{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}],I={toc:O},M="wrapper";function R(e){let{components:t,...i}=e;return(0,l.kt)(M,(0,a.Z)({},I,i,{components:t,mdxType:"MDXLayout"}),(0,l.kt)("h1",{id:"building-tinyorm"},"Building: TinyORM"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#introduction"},"Introduction"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#common-prerequisites"},"Common Prerequisites")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#windows-prerequisites"},"Windows Prerequisites")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#folders-structure"},"Folders structure")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#getting-started"},"Getting started")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#vcpkg"},"vcpkg")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#c-preprocessor-macros"},"C preprocessor macros")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#building-with-cmake"},"Building with CMake"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#configure-and-build-cmake"},"Configure & Build")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#cmake-build-options"},"CMake build options")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#consume-tinyorm-library-cmake"},"Consume TinyOrm library")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#building-with-qmake"},"Building with qmake"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#install-dependencies"},"Install dependencies")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#configure-and-build-qmake"},"Configure & Build")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#qmake-build-options"},"qmake build options")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#consume-tinyorm-library-qmake"},"Consume TinyOrm library")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#auto-configuration-internals"},"Auto-configuration internals"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#environment-files"},"Environment files")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#manual-configuration-internals"},"Manual configuration internals")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#ccache-support"},"Ccache support"))),(0,l.kt)("h2",{id:"introduction"},"Introduction"),(0,l.kt)("p",null,"The build systems supported out of the box are ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake"),"."),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"All examples below assume that ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh")," runs on ",(0,l.kt)("inlineCode",{parentName:"p"},"Windows")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"bash")," runs on ",(0,l.kt)("inlineCode",{parentName:"p"},"Linux"),".")),(0,l.kt)("h4",{id:"common-prerequisites"},"Common Prerequisites"),(0,l.kt)("p",null,"Install the required ",(0,l.kt)("a",{parentName:"p",href:"/dependencies"},"dependencies")," before starting."),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"QSqlDatabase")," depends on ",(0,l.kt)("inlineCode",{parentName:"p"},"QCoreApplication")," from ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt v6.5.3")," so you must create the ",(0,l.kt)("inlineCode",{parentName:"p"},"QCoreApplication")," instance before you will call anything from the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. \ud83e\udee4 The change was made ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/qt/qtbase/commit/8d2bdc9cd5482eace12ba7e45304857bd24db0e6#diff-1d355c25c0b0eddec2be48253407780c4dc510d986739aec61e1ec892ccaf86e"},"here"),".")),(0,l.kt)("h4",{id:"windows-prerequisites"},"Windows Prerequisites"),(0,l.kt)("h5",{id:"build-environment-scripts"},"Build environment scripts"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Visual Studio")," does not provide ",(0,l.kt)("inlineCode",{parentName:"p"},"vcvars")," scripts for ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh"),", you can use ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/tools/vcvars64.ps1"},(0,l.kt)("inlineCode",{parentName:"a"},"vcvars64.ps1"))," provided by ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," in the ",(0,l.kt)("inlineCode",{parentName:"p"},"tools/")," folder. Place them on the ",(0,l.kt)("inlineCode",{parentName:"p"},"$env:Path")," user/system path and they will be available system-wide."),(0,l.kt)("p",null,"The same is true for the ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt Framework"),", it doesn't provide ",(0,l.kt)("inlineCode",{parentName:"p"},"qtenv")," scripts for ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh")," too. You can create your own script, place it on the ",(0,l.kt)("inlineCode",{parentName:"p"},"$env:Path")," user/system path and it will be available system-wide."),(0,l.kt)("p",null,"Here is one simple example for ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh"),"."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:"qtenv6.ps1",label:"qtenv6.ps1",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},"Write-Host 'Setting up environment for Qt 6.5.3 usage...' -ForegroundColor Magenta\n$env:Path = 'C:\\Qt\\6.5.3\\msvc2019_64\\bin;' + $env:Path\n. E:\\dotfiles\\bin\\vcvars64.ps1\n"))),(0,l.kt)(d.Z,{value:"qtenv5.ps1",label:"qtenv5.ps1",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},"Write-Host 'Setting up environment for Qt 5.15.2 usage...' -ForegroundColor Magenta\n$env:Path = 'C:\\Qt\\5.15.2\\msvc2019_64\\bin;' + $env:Path\n. E:\\dotfiles\\bin\\vcvars64.ps1\n")))),(0,l.kt)("p",null,"And here for ",(0,l.kt)("inlineCode",{parentName:"p"},"Linux"),"."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:"qtenv6",label:"qtenv6",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"echo 'Setting up environment for Qt 6.5.3 usage...'\n\nexport PATH=/opt/Qt/6.5.3/gcc_64/bin${PATH:+:}$PATH\nexport LD_LIBRARY_PATH=/opt/Qt/6.5.3/gcc_64/lib${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH\n"))),(0,l.kt)(d.Z,{value:"qtenv5",label:"qtenv5",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"echo 'Setting up environment for Qt 5.15.2 usage...'\n\nexport PATH=/opt/Qt/5.15.2/gcc_64/bin${PATH:+:}$PATH\nexport LD_LIBRARY_PATH=/opt/Qt/5.15.2/gcc_64/lib${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH\n")))),(0,l.kt)("h5",{id:"allow-symbolic-links-unprivileged"},"Allow symbolic links unprivileged"),(0,l.kt)("p",null,"Open ",(0,l.kt)("inlineCode",{parentName:"p"},"Local Security Policy"),", go to ",(0,l.kt)("inlineCode",{parentName:"p"},"Local Policies - User Rights Assignment"),", open ",(0,l.kt)("inlineCode",{parentName:"p"},"Create symbolic links")," and add your user account or user group, restart when it doesn't apply immediately."),(0,l.kt)("h2",{id:"folders-structure"},"Folders structure"),(0,l.kt)("p",null,"All ",(0,l.kt)("inlineCode",{parentName:"p"},"tinyorm.org")," examples are based on the following folders structure. The ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," folder will contain a ",(0,l.kt)("a",{parentName:"p",href:"/building/migrations"},"migrations console application"),"."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can set the root and application folder paths in the form below and they will be used across the whole ",(0,l.kt)("a",{parentName:"p",href:"http://www.tinyorm.org"},"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.")),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,className:"tiny-tree",mdxType:"TabItem"},(0,l.kt)("div",{className:"tiny-root-folder-info-wrapper"},(0,l.kt)("span",{className:"tiny-root-folder-info-prefix"},"Current pwsh path"),"\xa0",(0,l.kt)(N,{groupId:y.Fo,mdxType:"RootFolder"})),(0,l.kt)(C,{groupId:y.Fo,label:y.IM,mdxType:"RootFolderInput"}),(0,l.kt)(C,{groupId:y.wU,label:y.jk,mdxType:"RootFolderInput"}),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-text"},"\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_5_3_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_5_3_MSVC2019_64bit-Debug/\n\u251c\u2500\u2500 tmp/\n\u2514\u2500\u2500 vcpkg/\n"))),(0,l.kt)(d.Z,{value:y.q5,label:y.C,className:"tiny-tree",mdxType:"TabItem"},(0,l.kt)("div",{className:"tiny-root-folder-info-wrapper"},(0,l.kt)("span",{className:"tiny-root-folder-info-prefix"},"Current bash path"),"\xa0",(0,l.kt)(N,{groupId:y.q5,mdxType:"RootFolder"})),(0,l.kt)(C,{groupId:y.q5,label:y.C,mdxType:"RootFolderInput"}),(0,l.kt)(C,{groupId:y.wU,label:y.wU,mdxType:"RootFolderInput"}),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-text"},"\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_5_3_clang14_64bit_ccache-Debug/\n\u2502 \u2514\u2500\u2500 tom-builds-qmake/\n\u2502 \u251c\u2500\u2500 build-TinyORM-Desktop_Qt_6_5_3_GCC_64bit-Debug/\n\u2502 \u2514\u2500\u2500 build-TinyORM-Desktop_Qt_6_5_3_clang14_64bit_ccache-Release/\n\u251c\u2500\u2500 tmp/\n\u2514\u2500\u2500 vcpkg/\n")))),(0,l.kt)("admonition",{type:"danger"},(0,l.kt)("p",{parentName:"admonition"},"Avoid paths with spaces with the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system, it will not compile.")),(0,l.kt)("a",{id:"qtcreator-default-build-directory"}),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can force the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator")," to generate a build folders structure as is described above."),(0,l.kt)("p",{parentName:"admonition"},"To generate the required folders structure set the ",(0,l.kt)("inlineCode",{parentName:"p"},"Settings")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Build & Run")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Default Build Properties")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Default build directory")," to:",(0,l.kt)("br",null),"\n",(0,l.kt)("inlineCode",{parentName:"p"},'../%{Project:Name}-builds-%{BuildSystem:Name}/%{JS: Util.asciify("build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name}")}'))),(0,l.kt)("h2",{id:"getting-started"},"Getting started"),(0,l.kt)("p",null,"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,l.kt)("inlineCode",{parentName:"p"},"PATH")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," for Qt Framework, or use our ",(0,l.kt)("inlineCode",{parentName:"p"},"qtenvX")," scripts described above."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`mkdir ${(0,u.EA)(y.Fo)}\ncd ${(0,u.EA)(y.Fo)}\n$env:Path = 'C:\\Qt\\6.5.3\\msvc2019_64\\bin;' + $env:Path\nvcvars64.ps1`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`mkdir -p ${(0,u.EA)(y.q5)}\ncd ${(0,u.EA)(y.q5)}\nexport PATH=/opt/Qt/6.5.3/gcc_64/bin\${PATH:+:}$PATH\nexport LD_LIBRARY_PATH=/opt/Qt/6.5.3/gcc_64/lib\${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH`))),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can also use the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tools/Add-FolderOnPath.ps1"},(0,l.kt)("inlineCode",{parentName:"a"},"tools/Add-FolderOnPath.ps1"))," pwsh script to fastly prepend a path or ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd")," on the system ",(0,l.kt)("inlineCode",{parentName:"p"},"PATH"),".")),(0,l.kt)("h2",{id:"vcpkg"},"vcpkg"),(0,l.kt)("p",null,"Installing the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," is highly recommended, it simplifies installation of the ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," dependencies."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},"git clone git@github.com:microsoft/vcpkg.git\ncd vcpkg\n.\\bootstrap-vcpkg.bat\n"))),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"git clone git@github.com:microsoft/vcpkg.git\ncd vcpkg\n./bootstrap-vcpkg.sh\n")))),(0,l.kt)("p",null,"Add ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," on the system path, add the following to the ",(0,l.kt)("inlineCode",{parentName:"p"},".bashrc")," or ",(0,l.kt)("inlineCode",{parentName:"p"},".zshrc")," on Linux."),(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export PATH=${(0,u.EA)(y.q5)}/vcpkg\${PATH:+:}$PATH`),(0,l.kt)("p",null,"On Windows, open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Environment variables")," dialog and add ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," on the user ",(0,l.kt)("inlineCode",{parentName:"p"},"PATH"),"."),(0,l.kt)("p",null,"Or you can export it for the current session only."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,u.EA)(y.Fo,!1)}\\vcpkg;" + $env:Path`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export PATH=${(0,u.EA)(y.q5)}/vcpkg\${PATH:+:}$PATH`))),(0,l.kt)("h4",{id:"set-up-vcpkg-environment"},"Set up ",(0,l.kt)("inlineCode",{parentName:"h4"},"vcpkg")," environment"),(0,l.kt)("p",null,"To export ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," environment variables globally, add it to the ",(0,l.kt)("inlineCode",{parentName:"p"},".bashrc")," or ",(0,l.kt)("inlineCode",{parentName:"p"},".zshrc")," on Linux, and you can use the ",(0,l.kt)("inlineCode",{parentName:"p"},"Environment variables")," dialog on Windows."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash",metastring:"title='Linux'",title:"'Linux'"},'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')),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"It is recommended to define these variables globally because the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system are able to detect the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," installation from them so you don't have to configure them manually to detect the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," installation.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"On Windows, it's always better to create these types of variables as user variables instead of system variables in the ",(0,l.kt)("inlineCode",{parentName:"p"},"Environment variables")," dialog.")),(0,l.kt)("h2",{id:"c-preprocessor-macros"},"C preprocessor macros"),(0,l.kt)("p",null,"The following table summarizes all the C preprocessor macros defined in the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. These C macros are configured by ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build systems. They are not sorted alphabetically, but they are sorted by how significant they are."),(0,l.kt)("p",null,"In the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," build system, all the C macros are auto-detected / auto-configured or controlled by ",(0,l.kt)("a",{parentName:"p",href:"#cmake-build-options"},(0,l.kt)("inlineCode",{parentName:"a"},"CMake build options")),", so you don't have to care too much about them."),(0,l.kt)("p",null,"In the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build is important whether you are building ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library or you are building your application and linking against ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. When you are building the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library, all the C macros are auto-detected / auto-configured or controlled by ",(0,l.kt)("a",{parentName:"p",href:"#qmake-build-options"},(0,l.kt)("inlineCode",{parentName:"a"},"qmake build options")),", so you don't have to care too much about them."),(0,l.kt)("p",null,"But a special situation is when you are building your application / library and you are linking against ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. In this particular case, you must configure all these C macros manually! For this reason, the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/qmake/TinyOrm.pri"},(0,l.kt)("inlineCode",{parentName:"a"},"TinyOrm.pri"))," has been created, so that's not a big deal either. Little more info ",(0,l.kt)("a",{parentName:"p",href:"#consume-tinyorm-library-qmake"},"here"),"."),(0,l.kt)("div",{id:"apitable-c-macros"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"C Macro Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_LINKING_SHARED")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("u",null,(0,l.kt)("strong",{parentName:"td"},"Must"))," be defined when you are linking against ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," shared build (",(0,l.kt)("inlineCode",{parentName:"td"},"dll")," library), exported classes and functions will be tagged with ",(0,l.kt)("inlineCode",{parentName:"td"},"__declspec(dllimport)")," on ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc")," and ",(0,l.kt)("inlineCode",{parentName:"td"},'visibility("default")')," on ",(0,l.kt)("inlineCode",{parentName:"td"},"GCC >= 4"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_BUILDING_SHARED")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined when ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," is built as a ",(0,l.kt)("inlineCode",{parentName:"td"},"dll")," library (shared build).")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_DEBUG")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined in the debug build.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_NO_DEBUG")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined in the release build.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_DEBUG_SQL")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined in the debug build.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_NO_DEBUG_SQL")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined in the release build.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_MYSQL_PING")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable ",(0,l.kt)("inlineCode",{parentName:"td"},"Orm::MySqlConnection::pingDatabase()")," method.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#mysql_ping"},(0,l.kt)("inlineCode",{parentName:"a"},"mysql_ping"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#MYSQL_PING"},(0,l.kt)("inlineCode",{parentName:"a"},"MYSQL_PING"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_DISABLE_ORM")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," source code, when this macro is ",(0,l.kt)("inlineCode",{parentName:"td"},"defined"),", then only the ",(0,l.kt)("inlineCode",{parentName:"td"},"query builder")," without ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM")," is compiled. Also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," unit tests.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#disable_orm"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_orm"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#ORM"},(0,l.kt)("inlineCode",{parentName:"a"},"ORM"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled ",(0,l.kt)("small",null,"(qmake)")," / disabled ",(0,l.kt)("small",null,"(cmake)"),"."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_EXTERN_CONSTANTS")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined when extern constants are used. Extern constants are enabled by default for shared builds and disabled for static builds.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Described at ",(0,l.kt)("a",{parentName:"td",href:"#extern_constants"},(0,l.kt)("inlineCode",{parentName:"a"},"qmake"))," / ",(0,l.kt)("a",{parentName:"td",href:"#INLINE_CONSTANTS"},(0,l.kt)("inlineCode",{parentName:"a"},"CMake"))," how it works."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_INLINE_CONSTANTS")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined when global inline constants are used.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#inline_constants"},(0,l.kt)("inlineCode",{parentName:"a"},"inline_constants"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#INLINE_CONSTANTS"},(0,l.kt)("inlineCode",{parentName:"a"},"INLINE_CONSTANTS"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_TESTS_CODE")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable code needed by unit tests, eg. connection overriding in the ",(0,l.kt)("inlineCode",{parentName:"td"},"Orm::Tiny::Model"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#build_tests"},(0,l.kt)("inlineCode",{parentName:"a"},"build_tests"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#BUILD_TESTS"},(0,l.kt)("inlineCode",{parentName:"a"},"BUILD_TESTS"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_DISABLE_THREAD_LOCAL")),(0,l.kt)("td",{parentName:"tr",align:null},"Remove all ",(0,l.kt)("a",{parentName:"td",href:"https://en.cppreference.com/w/c/language/storage_duration"},(0,l.kt)("inlineCode",{parentName:"a"},"thread_local"))," storage duration specifiers, it disables multi-threading support.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined when ",(0,l.kt)("a",{parentName:"td",href:"#disable_thread_local"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_thread_local"))," ",(0,l.kt)("small",null,"(qmake)")," / ",(0,l.kt)("a",{parentName:"td",href:"#DISABLE_THREAD_LOCAL"},(0,l.kt)("inlineCode",{parentName:"a"},"DISABLE_THREAD_LOCAL"))," ",(0,l.kt)("small",null,"(cmake)")," configuration ",(0,l.kt)("inlineCode",{parentName:"td"},"build option")," is enabled."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYTOM_MIGRATIONS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},"Default migrations path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:migration")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/migrations")," ",(0,l.kt)("small",null,"(relative to the pwd)")),(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined by ",(0,l.kt)("a",{parentName:"td",href:"#TOM_MIGRATIONS_DIR"},(0,l.kt)("inlineCode",{parentName:"a"},"TOM_MIGRATIONS_DIR"))," ",(0,l.kt)("small",null,"(cmake)")," configuration build option.",(0,l.kt)("br",null),(0,l.kt)("small",null,"(qmake note) You can use ",(0,l.kt)("inlineCode",{parentName:"td"},'DEFINES += TINYTOM_MIGRATIONS_DIR="\\"database/migrations\\""')," on the command-line or set it in the ",(0,l.kt)("strong",{parentName:"td"},"main")," ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L65-L70"},(0,l.kt)("inlineCode",{parentName:"a"},"conf.pri"))," file.")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYTOM_MODELS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},"Default models path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:model")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/models")," ",(0,l.kt)("small",null,"(relative to the pwd)")),(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined by ",(0,l.kt)("a",{parentName:"td",href:"#TOM_MODELS_DIR"},(0,l.kt)("inlineCode",{parentName:"a"},"TOM_MODELS_DIR"))," ",(0,l.kt)("small",null,"(cmake)")," configuration build option.",(0,l.kt)("br",null),(0,l.kt)("small",null,"(qmake note) You can use ",(0,l.kt)("inlineCode",{parentName:"td"},'DEFINES += TINYTOM_MODELS_DIR="\\"database/models\\""')," on the command-line or set it in the ",(0,l.kt)("strong",{parentName:"td"},"main")," ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L72-L73"},(0,l.kt)("inlineCode",{parentName:"a"},"conf.pri"))," file.")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYTOM_SEEDERS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},"Default seeders path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:seeder")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/seeders")," ",(0,l.kt)("small",null,"(relative to the pwd)")),(0,l.kt)("br",null),(0,l.kt)("small",null,"Defined by ",(0,l.kt)("a",{parentName:"td",href:"#TOM_SEEDERS_DIR"},(0,l.kt)("inlineCode",{parentName:"a"},"TOM_SEEDERS_DIR"))," ",(0,l.kt)("small",null,"(cmake)")," configuration build option.",(0,l.kt)("br",null),(0,l.kt)("small",null,"(qmake note) You can use ",(0,l.kt)("inlineCode",{parentName:"td"},'DEFINES += TINYTOM_SEEDERS_DIR="\\"database/seeders\\""')," on the command-line or set it in the ",(0,l.kt)("strong",{parentName:"td"},"main")," ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L75-L76"},(0,l.kt)("inlineCode",{parentName:"a"},"conf.pri"))," file.")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_USING_PCH")),(0,l.kt)("td",{parentName:"tr",align:null},"Defined if building with precompiled headers.",(0,l.kt)("br",null),(0,l.kt)("small",null,"Controlled by ",(0,l.kt)("a",{parentName:"td",href:"#precompile_header"},(0,l.kt)("inlineCode",{parentName:"a"},"qmake"))," / ",(0,l.kt)("a",{parentName:"td",href:"#CMAKE_DISABLE_PRECOMPILE_HEADERS"},(0,l.kt)("inlineCode",{parentName:"a"},"CMake")),"."))))))),(0,l.kt)("h2",{id:"building-with-cmake"},"Building with CMake"),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"If something is not clear, you can still look at GitHub Action ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/.github/workflows"},(0,l.kt)("inlineCode",{parentName:"a"},"workflows"))," how a building is done.")),(0,l.kt)("p",null,"First, create a basic folder structure and then clone the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,u.EA)(y.Fo)}\nmkdir ${(0,u.AE)()}/TinyORM/TinyORM-builds-cmake/build-debug\n\ncd ${(0,u.AE)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,u.EA)(y.q5)}\nmkdir -p ${(0,u.AE)()}/TinyORM/TinyORM-builds-cmake/build-debug\n\ncd ${(0,u.AE)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`))),(0,l.kt)("h3",{id:"configure-and-build-cmake"},"Configure & Build ",(0,l.kt)("small",null,"(cmake)")),(0,l.kt)("p",null,"Now you are ready to configure the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd TinyORM-builds-cmake/build-debug\n")),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cmake.exe \`\n-S "${(0,u.go)(y.Fo)}/TinyORM/TinyORM" \`\n-B "${(0,u.go)(y.Fo)}/TinyORM/TinyORM-builds-cmake/build-debug" \`\n-G 'Ninja' \`\n-D CMAKE_BUILD_TYPE:STRING='Debug' \`\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,u.EA)(y.Fo)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \`\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,u.EA)(y.Fo)}/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,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cmake \\\n-S "${(0,u.go)(y.q5)}/TinyORM/TinyORM" \\\n-B "${(0,u.go)(y.q5)}/TinyORM/TinyORM-builds-cmake/build-debug" \\\n-G 'Ninja' \\\n-D CMAKE_BUILD_TYPE:STRING='Debug' \\\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,u.EA)(y.q5)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \\\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,u.EA)(y.q5)}/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`))),(0,l.kt)("h5",{id:"cmake-strict_mode-option"},"CMake ",(0,l.kt)("inlineCode",{parentName:"h5"},"STRICT_MODE")," option"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"STRICT_MODE")," ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," configuration option was added in ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.36.5"),". This option was added to avoid the propagation of aggressive strict warning compiler/linker options and Qt definitions from the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library to user code through the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/cmake/CommonModules/TinyCommon.cmake"},(0,l.kt)("inlineCode",{parentName:"a"},"TinyOrm::CommonConfig"))," interface library."),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"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,l.kt)("inlineCode",{parentName:"p"},"ISOCPP")," ",(0,l.kt)("a",{parentName:"p",href:"https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines"},"C++ Core Guidelines")," standards."),(0,l.kt)("p",null,"If you want to enable these strict warning options in your code, you can enable the ",(0,l.kt)("inlineCode",{parentName:"p"},"STRICT_MODE")," ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," configuration option and they will be propagated to your code. You can also enabled it globally using the ",(0,l.kt)("inlineCode",{parentName:"p"},"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,l.kt)("inlineCode",{parentName:"p"},"STRICT_MODE")," ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," configuration option."),(0,l.kt)("p",null,"You can achieve the same result by manually linking against the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm::CommonConfig")," interface library when the ",(0,l.kt)("inlineCode",{parentName:"p"},"STRICT_MODE")," is set to ",(0,l.kt)("inlineCode",{parentName:"p"},"OFF"),"."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-cmake"},"target_link_libraries( PRIVATE TinyOrm::CommonConfig)\n")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"The recommended way is to set the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_STRICT_MODE")," environment variable to ",(0,l.kt)("inlineCode",{parentName:"p"},"1")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"ON"),".")),(0,l.kt)("h4",{id:"build-tinyorm"},"Build TinyORM"),(0,l.kt)("p",null,"And build. You don't have to install it, you can use the build tree directly if you want."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cmake --build . --target all\ncmake --install .\n")),(0,l.kt)("p",null,"Or build and install in one step."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cmake --build . --target install\n")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"CMake multi-config generators like ",(0,l.kt)("inlineCode",{parentName:"p"},"Ninja Multi-Config")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"Visual Studio 16 2019")," are also supported.")),(0,l.kt)("h3",{id:"cmake-build-options"},"CMake build options"),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Option Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_SHARED_LIBS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Build as a shared/static library.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_TESTS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build TinyORM unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"INLINE_CONSTANTS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Use inline constants instead of extern constants in the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),".",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"OFF")," is highly recommended for the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),";",(0,l.kt)("br",null),"is always ",(0,l.kt)("inlineCode",{parentName:"td"},"ON")," for the ",(0,l.kt)("inlineCode",{parentName:"td"},"static build"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"BUILD_SHARED_LIBS")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"MSVC_RUNTIME_DYNAMIC")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Use MSVC dynamic runtime library (",(0,l.kt)("inlineCode",{parentName:"td"},"-MD"),") instead of static (",(0,l.kt)("inlineCode",{parentName:"td"},"-MT"),"), also considers a Debug configuration (",(0,l.kt)("inlineCode",{parentName:"td"},"-MTd"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"-MDd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"MYSQL_PING")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable ",(0,l.kt)("inlineCode",{parentName:"td"},"Orm::MySqlConnection::pingDatabase()")," method.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ORM")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," source code, when this option is ",(0,l.kt)("inlineCode",{parentName:"td"},"disabled"),", then only the ",(0,l.kt)("inlineCode",{parentName:"td"},"query builder")," without ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM")," is compiled. Also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"STRICT_MODE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls propagation of strict compiler/linker options and Qt definitions using the ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyOrm::CommonConfig")," interface library to the user code.",(0,l.kt)("br",null),(0,l.kt)("small",null,"(highly recommended; can also be set with the ",(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_STRICT_MODE")," environment variable; described ",(0,l.kt)("a",{parentName:"td",href:"#cmake-strict_mode-option"},"here"),")"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"Tom-related")," source code, when this option is ",(0,l.kt)("inlineCode",{parentName:"td"},"disabled"),", then it also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"Tom-related")," unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM_EXAMPLE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build the ",(0,l.kt)("abbr",{title:"TinyORM Migrations"},(0,l.kt)("inlineCode",{parentName:"td"},"tom"))," console application example.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM_MIGRATIONS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Default migrations path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:migration")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/migrations")," ",(0,l.kt)("small",null,"(relative to the pwd)")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM_MODELS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Default models path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:model")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/models")," ",(0,l.kt)("small",null,"(relative to the pwd)")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TOM_SEEDERS_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Default seeders path for the ",(0,l.kt)("inlineCode",{parentName:"td"},"make:seeder")," command, can be an absolute or relative path (to the ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd"),").",(0,l.kt)("br",null),(0,l.kt)("small",null,"Default value: ",(0,l.kt)("inlineCode",{parentName:"td"},"database/seeders")," ",(0,l.kt)("small",null,"(relative to the pwd)")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"VERBOSE_CONFIGURE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Show information about ",(0,l.kt)("inlineCode",{parentName:"td"},"PACKAGES_FOUND")," / ",(0,l.kt)("inlineCode",{parentName:"td"},"PACKAGES_NOT_FOUND")," in the CMake configure output.")))))),(0,l.kt)("p",null,"Advanced ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," options."),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Option Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"DISABLE_THREAD_LOCAL")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Remove all ",(0,l.kt)("a",{parentName:"td",href:"https://en.cppreference.com/w/c/language/storage_duration"},(0,l.kt)("inlineCode",{parentName:"a"},"thread_local"))," storage duration specifiers, it disables multi-threading support.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("small",null,(0,l.kt)("inlineCode",{parentName:"td"},"MATCH_EQUAL_EXPORTED_BUILDTREE"))),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Exported package configuration from the build tree is considered to match only when ",(0,l.kt)("inlineCode",{parentName:"td"},"the build type")," of application/library that is linking against the TinyORM library ",(0,l.kt)("strong",{parentName:"td"},"is equal"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when:",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_EXPORT_PACKAGE_REGISTRY AND NOT TINY_IS_MULTI_CONFIG")))))))),(0,l.kt)("p",null,"Important ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," options."),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Option Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_DISABLE_PRECOMPILE_HEADERS")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Disable precompiled headers.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_CXX_COMPILER")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"auto")),(0,l.kt)("td",{parentName:"tr",align:null},"The full path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"C++")," compiler.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_CXX_COMPILER_LAUNCHER")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Default compiler launcher to use for the ",(0,l.kt)("inlineCode",{parentName:"td"},"C++")," compiler.",(0,l.kt)("br",null),"Can be used to enable ",(0,l.kt)("inlineCode",{parentName:"td"},"ccache"),", eg. ",(0,l.kt)("inlineCode",{parentName:"td"},"ccache.exe")," on ",(0,l.kt)("inlineCode",{parentName:"td"},"MinGW")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"/usr/bin/ccache")," on ",(0,l.kt)("inlineCode",{parentName:"td"},"Linux"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_EXPORT_PACKAGE_REGISTRY")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable the ",(0,l.kt)("inlineCode",{parentName:"td"},"export(TinyOrm)")," command.",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," sets this variable to ",(0,l.kt)("inlineCode",{parentName:"td"},"ON")," by default.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"CMAKE_VERBOSE_MAKEFILE")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable verbose output from Makefile builds.")))))),(0,l.kt)("h3",{id:"consume-tinyorm-library-cmake"},"Consume TinyOrm library ",(0,l.kt)("small",null,"(cmake)")),(0,l.kt)("p",null,"In your application or library ",(0,l.kt)("inlineCode",{parentName:"p"},"CMakeLists.txt")," file add following ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package()")," call."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-cmake",metastring:"title='CMakeLists.txt'",title:"'CMakeLists.txt'"},"find_package(TinyOrm 0.36.5 CONFIG REQUIRED)\n")),(0,l.kt)("p",null,"If the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build tree is not exported to the CMake's ",(0,l.kt)("a",{parentName:"p",href:"https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#user-package-registry"},(0,l.kt)("inlineCode",{parentName:"a"},"User Package Registry"))," then also add the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build tree or ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_INSTALL_PREFIX")," folder to the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_PREFIX_PATH"),", so CMake can find TinyORM's package configuration file during ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package(TinyOrm)")," call."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:`cmake (${y.Fo})`,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,u.we)(y.Fo,(0,u.go)(y.Fo))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\n# installation folder - CMAKE_INSTALL_PREFIX\nlist(APPEND CMAKE_PREFIX_PATH "${(0,u.we)(y.Fo,(0,u.EA)(y.Fo))}/tmp/TinyORM")`)),(0,l.kt)(d.Z,{value:y.q5,label:`cmake (${y.q5})`,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,u.we)(y.q5,(0,u.go)(y.q5))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\n# installation folder - CMAKE_INSTALL_PREFIX\nlist(APPEND CMAKE_PREFIX_PATH "${(0,u.we)(y.q5,(0,u.EA)(y.q5))}/tmp/TinyORM")`))),(0,l.kt)("p",null,"Or as an alternative, you can set ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_PREFIX_PATH")," environment variable."),(0,l.kt)("a",{id:"tinyorm-on-path-cmake"}),(0,l.kt)("p",null,"As the last thing, do not forget to add ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm0d.dll")," on the path on Windows and on the ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux, so your application can find it during execution."),(0,l.kt)(p.Z,{groupId:y.IZ,name:"tinyorm-on-path",mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,u.go)(y.Fo,!1)}\\TinyORM\\TinyORM-builds-cmake\\build-debug;" + $env:Path`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export LD_LIBRARY_PATH=${(0,u.go)(y.q5)}/TinyORM/TinyORM-builds-cmake/build-debug\${PATH:+:}$PATH`))),(0,l.kt)("p",null,"Now you can try the ",(0,l.kt)("a",{parentName:"p",href:"/building/hello-world#hello-world-with-cmake"},(0,l.kt)("inlineCode",{parentName:"a"},"HelloWorld CMake"))," example."),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"You can also try the ",(0,l.kt)("a",{parentName:"p",href:"/building/hello-world#fetchcontent"},(0,l.kt)("inlineCode",{parentName:"a"},"FetchContent"))," method to fastly link against the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library.")),(0,l.kt)("h2",{id:"building-with-qmake"},"Building with qmake"),(0,l.kt)("p",null,"First, create a basic folder structure and then clone the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,u.EA)(y.Fo)}\nmkdir ${(0,u.AE)()}/TinyORM/TinyORM-builds-qmake\n\ncd ${(0,u.AE)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,u.EA)(y.q5)}\nmkdir -p ${(0,u.AE)()}/TinyORM/TinyORM-builds-qmake\n\ncd ${(0,u.AE)()}/TinyORM\ngit clone git@github.com:silverqx/TinyORM.git`))),(0,l.kt)("h3",{id:"install-dependencies"},"Install dependencies"),(0,l.kt)("p",null,"With the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system, you have to install ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," dependencies manually. We will use the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," package manager."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../../vcpkg\n\nvcpkg search range-v3\nvcpkg search tabulate\nvcpkg install range-v3 tabulate\nvcpkg list\n")),(0,l.kt)("p",null,"On ",(0,l.kt)("inlineCode",{parentName:"p"},"Linux"),", you can install the ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," library and some other ",(0,l.kt)("a",{parentName:"p",href:"/dependencies#install-dependencies"},"dependencies")," with the package manager."),(0,l.kt)("h3",{id:"configure-and-build-qmake"},"Configure & Build ",(0,l.kt)("small",null,"(qmake)")),(0,l.kt)("h4",{id:"open-qtcreator-ide"},"Open QtCreator IDE"),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"I recommend creating a new ",(0,l.kt)("a",{parentName:"p",href:"https://doc.qt.io/qtcreator/creator-project-managing-sessions.html"},(0,l.kt)("inlineCode",{parentName:"a"},"Session"))," in the ",(0,l.kt)("inlineCode",{parentName:"p"},"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,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),". You can name it ",(0,l.kt)("inlineCode",{parentName:"p"},"tinyorm.org")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM examples"),", it is up to you.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"If you are using sessions, you can use a single ",(0,l.kt)("inlineCode",{parentName:"p"},"clangd")," instance for all projects in this session in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),". One significant advantage of this method is that the ",(0,l.kt)("inlineCode",{parentName:"p"},".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,l.kt)("inlineCode",{parentName:"p"},"Settings")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"C++")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Clangd")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Sessions with a single clangd instance"),".")),(0,l.kt)("h4",{id:"configure-tinyorm"},"Configure TinyORM"),(0,l.kt)("p",null,"Now you are ready to configure the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. There are two ways how to configure the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library and it's the new ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configure")," feature added in ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0")," using the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files and the old way using the ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files."),(0,l.kt)("h5",{id:"auto-configuration-and-tiny_dotenv"},"Auto-configuration and tiny_dotenv"),(0,l.kt)("p",null,"This is the new recommended method to auto-configure TinyORM's ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system and also the dependencies, it was added in ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0"),". You need to copy the prepared ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw).example")," file to the ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw)"),". One ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," example file is prepared for each supported platform."),(0,l.kt)("p",null,"All prepared ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw).example")," files are simple and clear. You can also create a common ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," file that is included before the platform-specific ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw)")," files."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,u.go)(y.Fo)}/TinyORM/TinyORM\n\ncp .env.win32.example .env.win32`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,u.go)(y.q5)}/TinyORM/TinyORM\n\ncp .env.unix.example .env.unix`))),(0,l.kt)("p",null,"And that is all, if you have correctly set all ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," variables in this ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw)")," file or you have correctly set environment variables, then the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system should be able to ",(0,l.kt)("inlineCode",{parentName:"p"},"auto-detect")," all dependencies . \ud83d\udd25"),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("a",{parentName:"p",href:"#auto-configuration-internals"},(0,l.kt)("inlineCode",{parentName:"a"},"Auto-configuration"))," and ",(0,l.kt)("a",{parentName:"p",href:"#environment-files"},(0,l.kt)("inlineCode",{parentName:"a"},"Environment files"))," internals are described at the end to make this section more clear.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature can be turned off using the ",(0,l.kt)("a",{parentName:"p",href:"#disable_autoconf"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_autoconf"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_autoconf"),").")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," feature can be turned off using the ",(0,l.kt)("a",{parentName:"p",href:"#disable_dotenv"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_dotenv"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_dotenv"),").")),(0,l.kt)("h5",{id:"manual-configuration-confpri"},"Manual configuration (conf.pri)"),(0,l.kt)("p",null,"This is the old method used before ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0"),". You need to copy the ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri.example")," files to ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," (there are four, one for every project or sub-project) and manually update the ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"LIBS")," to configure TinyORM's ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build dependencies. This way you can override any ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build options or variables."),(0,l.kt)("p",null,"To disable the ",(0,l.kt)("a",{parentName:"p",href:"#auto-configuration-internals"},(0,l.kt)("inlineCode",{parentName:"a"},"Auto-configuration"))," feature you must define the ",(0,l.kt)("a",{parentName:"p",href:"#disable_autoconf"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_autoconf"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_autoconf"),") because from ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0")," is the ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature enabled by default."),(0,l.kt)("p",null,"You can also remove all ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files or turn off the ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," feature using ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_dotenv"),". You can use them all at once if you want, ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," and also ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files."),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files are nicely commented on, so you can see what needs to be modified."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,u.go)(y.Fo)}/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,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,u.go)(y.q5)}/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,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("a",{parentName:"p",href:"#manual-configuration-internals"},(0,l.kt)("inlineCode",{parentName:"a"},"Manual configuration"))," internals are described at the end to make this section more clear.")),(0,l.kt)("admonition",{type:"note"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Manual configuration")," is still relevant if you have any non-standard installation of the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"MySQL")," and the ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature fails.")),(0,l.kt)("h5",{id:"opening-tinyormpro-main-project-file"},"Opening TinyORM.pro (main project file)"),(0,l.kt)("p",null,"Now you can open the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM.pro")," project in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),"."),(0,l.kt)("p",null,"This will open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Configure Project")," tab, select some kit and update build folder paths to meet our ",(0,l.kt)("a",{parentName:"p",href:"#folders-structure"},"folders structure")," or like you want."),(0,l.kt)("img",{src:n(6874).Z,alt:"TinyORM - QtCreator - Configure Project",width:"760"}),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can force the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator")," to generate a build folders structure as is described ",(0,l.kt)("a",{parentName:"p",href:"#qtcreator-default-build-directory"},"above"),".")),(0,l.kt)("p",null,"You are ready to configure build options, hit ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"5")," to open ",(0,l.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,l.kt)("inlineCode",{parentName:"p"},"Build")," in the left sidebar to open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Build Settings"),", it should look similar to the following picture."),(0,l.kt)("p",null,"Disable ",(0,l.kt)("inlineCode",{parentName:"p"},"QML debugging and profiling")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt Quick Compiler"),", they are not used."),(0,l.kt)("img",{src:n(7066).Z,alt:"TinyORM - QtCreator - Build Settings",width:"760"}),(0,l.kt)("p",null,"If you want to change some ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build options, you can pass them to the ",(0,l.kt)("inlineCode",{parentName:"p"},"Build Steps")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake TinyORM.pro")," - ",(0,l.kt)("inlineCode",{parentName:"p"},"Additional arguments")," input field. It can look like this."),(0,l.kt)("img",{src:n(5705).Z,alt:"TinyORM - QtCreator - Build Settings - Additional arguments",width:"660"}),(0,l.kt)("h4",{id:"build-tinyorm-1"},"Build TinyORM"),(0,l.kt)("p",null,"Everything is ready for build, you can press ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"b")," to build the project."),(0,l.kt)("h3",{id:"qmake-build-options"},"qmake build options"),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"th"},"CONFIG")," ",(0,l.kt)("small",null,"Option Name")),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"build_tests")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build TinyORM unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_autoconf")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Disable the ",(0,l.kt)("a",{parentName:"td",href:"#auto-configuration-internals"},(0,l.kt)("inlineCode",{parentName:"a"},"Auto-configuration"))," feature ",(0,l.kt)("small",null,"(auto-configuration is enabled by default from ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"td"},"v0.34.0"),")"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_dotenv")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Disable the ",(0,l.kt)("a",{parentName:"td",href:"#environment-files"},(0,l.kt)("inlineCode",{parentName:"a"},"tiny_dotenv"))," feature ",(0,l.kt)("small",null,"(environment files are enabled by default from ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"td"},"v0.34.0"),")"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_thread_local")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Remove all ",(0,l.kt)("a",{parentName:"td",href:"https://en.cppreference.com/w/c/language/storage_duration"},(0,l.kt)("inlineCode",{parentName:"a"},"thread_local"))," storage duration specifiers, it disables multi-threading support.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_orm")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," source code, when this option is ",(0,l.kt)("inlineCode",{parentName:"td"},"enabled"),", then only the ",(0,l.kt)("inlineCode",{parentName:"td"},"query builder")," without ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM")," is compiled. Also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"ORM-related")," unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"disable_tom")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Controls the compilation of all ",(0,l.kt)("inlineCode",{parentName:"td"},"Tom-related")," source code, when this option is ",(0,l.kt)("inlineCode",{parentName:"td"},"disabled"),", then it also excludes ",(0,l.kt)("inlineCode",{parentName:"td"},"Tom-related")," unit tests.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"extern_constants")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Use ",(0,l.kt)("inlineCode",{parentName:"td"},"extern")," constants instead of ",(0,l.kt)("inlineCode",{parentName:"td"},"inline")," constants in the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),".",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"ON")," is highly recommended for the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build")," ",(0,l.kt)("small",null,"(by default)"),";",(0,l.kt)("br",null),"is always ",(0,l.kt)("inlineCode",{parentName:"td"},"OFF")," for the ",(0,l.kt)("inlineCode",{parentName:"td"},"static build"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("code",null,"CONFIG(shared","|","dll):!inline_constants")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"inline_constants")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Use ",(0,l.kt)("inlineCode",{parentName:"td"},"inline")," constants instead of ",(0,l.kt)("inlineCode",{parentName:"td"},"extern")," constants in the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),".",(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"OFF")," is highly recommended for the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared build"),";",(0,l.kt)("br",null),"is always ",(0,l.kt)("inlineCode",{parentName:"td"},"ON")," for the ",(0,l.kt)("inlineCode",{parentName:"td"},"static build"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"link_pkgconfig_off")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Link against ",(0,l.kt)("inlineCode",{parentName:"td"},"mysqlclient")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"libmariadb")," with ",(0,l.kt)("inlineCode",{parentName:"td"},"PKGCONFIG"),".",(0,l.kt)("br",null),"Used only in the ",(0,l.kt)("inlineCode",{parentName:"td"},"Unix")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"MinGW")," ",(0,l.kt)("strong",{parentName:"td"},"shared")," build ",(0,l.kt)("small",null,"(exactly ",(0,l.kt)("code",null,"win32-g++","|","win32-clang-g++"),")")," and when ",(0,l.kt)("inlineCode",{parentName:"td"},"mysql_ping")," is also defined to link against ",(0,l.kt)("inlineCode",{parentName:"td"},"mysqlclient")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"libmariadb"),", ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/conf.pri.example#L132"},"source code"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"unix:mysql_ping")," or ",(0,l.kt)("code",null,"(win32-g++","|","win32-clang-g++):mysql_ping:!static:!staticlib")))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"mysql_ping")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable ",(0,l.kt)("inlineCode",{parentName:"td"},"Orm::MySqlConnection::pingDatabase()")," method.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"tiny_ccache_win32")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ON")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable compiler cache. ",(0,l.kt)("a",{parentName:"td",href:"https://ccache.dev/"},"Homepage"),(0,l.kt)("br",null),(0,l.kt)("small",null,"It works only on Windows systems. It works well with the MSYS2 ",(0,l.kt)("inlineCode",{parentName:"td"},"g++"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"clang++"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc"),", and ",(0,l.kt)("inlineCode",{parentName:"td"},"clang-cl")," with ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc"),". It disables ",(0,l.kt)("inlineCode",{parentName:"td"},"precompile_header")," as they are not supported on Windows and changes the ",(0,l.kt)("inlineCode",{parentName:"td"},"-Zi")," compiler option to the ",(0,l.kt)("inlineCode",{parentName:"td"},"-Z7")," for debug builds as the ",(0,l.kt)("inlineCode",{parentName:"td"},"-Zi")," compiler option is not supported (",(0,l.kt)("a",{parentName:"td",href:"https://github.com/ccache/ccache/issues/1040"},"link")," to the issue)."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"tom_example")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build the ",(0,l.kt)("abbr",{title:"TinyORM Migrations"},(0,l.kt)("inlineCode",{parentName:"td"},"tom"))," console application example.")))))),(0,l.kt)("p",null,"Advanced ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," options."),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Option Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ubsan")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Allows to enable ",(0,l.kt)("a",{parentName:"td",href:"https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html"},"UBSan")," sanitizer (Clang only).")))))),(0,l.kt)("p",null,"Important ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," options."),(0,l.kt)("div",{className:"apitable-build-options"},(0,l.kt)(r.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"th"},"CONFIG")," ",(0,l.kt)("small",null,"Option Name")),(0,l.kt)("th",{parentName:"tr",align:null},"Default"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"ccache")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable compiler cache. ",(0,l.kt)("a",{parentName:"td",href:"https://ccache.dev/"},"Homepage"),(0,l.kt)("br",null),(0,l.kt)("small",null,"It works only on the Unix systems. It works well with the ",(0,l.kt)("inlineCode",{parentName:"td"},"g++")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"clang++")," and also supports precompiled headers."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"precompile_header")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"-")),(0,l.kt)("td",{parentName:"tr",align:null},"Enable precompiled headers, you can disable them with:",(0,l.kt)("br",null)," ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG-=precompile_header"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"The ",(0,l.kt)("inlineCode",{parentName:"td"},"precompile_header")," is enabled by default on ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"g++"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"clang++"),", ",(0,l.kt)("inlineCode",{parentName:"td"},"clang-cl")," on ",(0,l.kt)("inlineCode",{parentName:"td"},"Windows")," and disabled by default on ",(0,l.kt)("inlineCode",{parentName:"td"},"linux"),"."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"static"),(0,l.kt)("br",null),(0,l.kt)("inlineCode",{parentName:"td"},"staticlib")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Build as a ",(0,l.kt)("inlineCode",{parentName:"td"},"static")," library (lib only).",(0,l.kt)("br",null),(0,l.kt)("small",null,"If you want to build all libraries in the ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," project as static library archives and link against static libraries use the ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG += static"),". Don't use the ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG += staticlib"),".",(0,l.kt)("br",null),"See ",(0,l.kt)("a",{parentName:"td",href:"https://github.com/silverqx/TinyORM/blob/main/NOTES.txt"},"NOTES.txt")," for more informations (search ",(0,l.kt)("inlineCode",{parentName:"td"},"static vs staticlib"),")."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"static_runtime")),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"OFF")),(0,l.kt)("td",{parentName:"tr",align:null},"Link against the ",(0,l.kt)("inlineCode",{parentName:"td"},"shared")," (dynamic) or ",(0,l.kt)("inlineCode",{parentName:"td"},"static")," run-time library.",(0,l.kt)("br",null),(0,l.kt)("small",null,"The ",(0,l.kt)("inlineCode",{parentName:"td"},"-MD")," becomes ",(0,l.kt)("inlineCode",{parentName:"td"},"-MT")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"-MDd")," becomes ",(0,l.kt)("inlineCode",{parentName:"td"},"-MTd"),". It works only on ",(0,l.kt)("inlineCode",{parentName:"td"},"MSVC")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"MinGW")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"MSYS2"),".",(0,l.kt)("br",null),"Please ",(0,l.kt)("u",null,"don't use")," this option.",(0,l.kt)("br",null),"Available when: ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc")," or ",(0,l.kt)("inlineCode",{parentName:"td"},"mingw")))))))),(0,l.kt)("h3",{id:"consume-tinyorm-library-qmake"},"Consume TinyOrm library ",(0,l.kt)("small",null,"(qmake)")),(0,l.kt)("p",null,"The ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/qmake/TinyOrm.pri"},(0,l.kt)("inlineCode",{parentName:"a"},"TinyOrm.pri"))," file is available to simplify the integration of the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library into your application. It sets up and configures the ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"DEFINES")," qmake variables, adds the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM"),", ",(0,l.kt)("abbr",{title:"TinyORM Migrations"},(0,l.kt)("inlineCode",{parentName:"p"},"tom")),", and ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," header files on the system ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," (cross-platform using the ",(0,l.kt)("inlineCode",{parentName:"p"},"-isystem")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"-imsvc"),"), links against the TinyORM ",(0,l.kt)("inlineCode",{parentName:"p"},"shared")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"static")," library using the ",(0,l.kt)("inlineCode",{parentName:"p"},"LIBS"),"."),(0,l.kt)("p",null,"You can use it to configure the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library when you are linking against it. It does a very similar thing like the CMake's ",(0,l.kt)("inlineCode",{parentName:"p"},"Find Modules")," feature."),(0,l.kt)("h4",{id:"requirements"},"Requirements"),(0,l.kt)("p",null,"It has a few requirements, you need to:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"specify path to the ",(0,l.kt)("inlineCode",{parentName:"li"},"TinyORM")," qmake features (",(0,l.kt)("inlineCode",{parentName:"li"},".prf")," files) using the ",(0,l.kt)("inlineCode",{parentName:"li"},"QMAKEFEATURES")," variable that can only be set in the ",(0,l.kt)("inlineCode",{parentName:"li"},".qmake.conf")," file"),(0,l.kt)("li",{parentName:"ul"},"specify ",(0,l.kt)("inlineCode",{parentName:"li"},"qmake")," or ",(0,l.kt)("inlineCode",{parentName:"li"},"environment")," variables to find the ",(0,l.kt)("inlineCode",{parentName:"li"},"vcpkg")," installation ",(0,l.kt)("small",null,"(",(0,l.kt)("inlineCode",{parentName:"li"},"TINY_VCPKG_ROOT")," and ",(0,l.kt)("inlineCode",{parentName:"li"},"TINY_VCPKG_TRIPLET"),")")),(0,l.kt)("li",{parentName:"ul"},"specify path to the ",(0,l.kt)("inlineCode",{parentName:"li"},"TinyORM")," build folder ",(0,l.kt)("small",null,"(",(0,l.kt)("inlineCode",{parentName:"li"},"TINYORM_BUILD_TREE"),")"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},"you can specify it ",(0,l.kt)("strong",{parentName:"li"},"manually")),(0,l.kt)("li",{parentName:"ul"},"or you can use ",(0,l.kt)("a",{parentName:"li",href:"#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))))),(0,l.kt)("li",{parentName:"ul"},"build your application with the same ",(0,l.kt)("inlineCode",{parentName:"li"},"CONFIG")," ",(0,l.kt)("inlineCode",{parentName:"li"},"qmake")," variables that were used when building the ",(0,l.kt)("inlineCode",{parentName:"li"},"TinyORM")," library")),(0,l.kt)("p",null,"Let's explain one by one."),(0,l.kt)("h5",{id:"qmakefeatures"},(0,l.kt)("inlineCode",{parentName:"h5"},"QMAKEFEATURES")),(0,l.kt)("p",null,"Create the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file in your application root folder with the following content."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# 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_5_3_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")),(0,l.kt)("p",null,"You can move all ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," variables that are part of the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration process to the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," file if you want (recommended), this is possible because the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," enables the ",(0,l.kt)("a",{parentName:"p",href:"#environment-files"},(0,l.kt)("inlineCode",{parentName:"a"},"Environment files"))," feature by default."),(0,l.kt)("p",null,"You can look at the ",(0,l.kt)("a",{parentName:"p",href:"/building/hello-world#auto-configure-using-qmake_conf-and-env"},"Auto-configure using .qmake.conf and .env")," example for ",(0,l.kt)("inlineCode",{parentName:"p"},"Hello world")," project of what must stay in the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake.conf")," file and what can be moved to the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can use the ",(0,l.kt)("a",{parentName:"p",href:"#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," if you don't like to specify it manually.")),(0,l.kt)("h5",{id:"variables-affecting-tinyormpri"},"Variables affecting ",(0,l.kt)("inlineCode",{parentName:"h5"},"TinyOrm.pri")),(0,l.kt)("p",null,"You must define the following variables before the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," is included:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINYORM_BUILD_TREE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," build folder.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_ROOT")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," installation folder.",(0,l.kt)("br",null),"If not defined, then it tries to use the ",(0,l.kt)("inlineCode",{parentName:"td"},"VCPKG_ROOT")," environment variable.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_TRIPLET")),(0,l.kt)("td",{parentName:"tr",align:null},"The ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"triplet")," to use ",(0,l.kt)("small",null,"(vcpkg/installed/$$TINY_VCPKG_TRIPLET/)"),".",(0,l.kt)("br",null),"If not defined, then it tries to guess the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"triplet")," based on the current compiler and OS (based on the ",(0,l.kt)("inlineCode",{parentName:"td"},"QMAKESPEC"),"), and as the last thing, it tries to use the ",(0,l.kt)("inlineCode",{parentName:"td"},"VCPKG_DEFAULT_TRIPLET")," environment variable.")))),(0,l.kt)("p",null,"These variables will be set after the configuration is done:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_BUILD_SUBFOLDER")),(0,l.kt)("td",{parentName:"tr",align:null},"Folder by release type if ",(0,l.kt)("inlineCode",{parentName:"td"},"CONFIG+=debug_and_release")," is defined ",(0,l.kt)("small",null,"(/debug, /release, or an empty string)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_CCACHE_BUILD")),(0,l.kt)("td",{parentName:"tr",align:null},"To correctly link ",(0,l.kt)("inlineCode",{parentName:"td"},"ccache")," build against a ",(0,l.kt)("inlineCode",{parentName:"td"},"ccache")," build ",(0,l.kt)("small",null,"(_ccache or an empty string)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MSVC_VERSION")),(0,l.kt)("td",{parentName:"tr",align:null},"The ",(0,l.kt)("inlineCode",{parentName:"td"},"msvc")," compiler string ",(0,l.kt)("small",null,"(MSVC2022 or MSVC2019)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_QT_VERSION_UNDERSCORED")),(0,l.kt)("td",{parentName:"tr",align:null},"Underscored ",(0,l.kt)("inlineCode",{parentName:"td"},"Qt")," version ",(0,l.kt)("small",null,"(eg. 6_5_3)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_RELEASE_TYPE_CAMEL")),(0,l.kt)("td",{parentName:"tr",align:null},"Build type string ",(0,l.kt)("small",null,"(Debug, Profile, or Release)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_INCLUDE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"include")," folder ",(0,l.kt)("small",null,"(vcpkg/installed/","<","triplet",">","/include/)"),".")))),(0,l.kt)("p",null,"Then you simply include the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," in your project file."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='AnyProject.pro'",title:"'AnyProject.pro'"},"include($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n")),(0,l.kt)("p",null,"And that is all, now you should be able to link against the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. \ud83d\udc4c"),(0,l.kt)("h5",{id:"manual-configuration-examples"},"Manual configuration examples"),(0,l.kt)("p",null,"Frankly, there is no reason to use the Manual configuration (define the variables described below before the ",(0,l.kt)("inlineCode",{parentName:"p"},"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."),(0,l.kt)("p",null,"You will have to link against the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library manually if you don't set the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," variable before the inclusion of the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," file. The ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," is auto-detected every time."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"{9}","{9}":!0},"# 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_5_3_MSVC2019_64bit-Debug/src$${TINY_BUILD_SUBFOLDER}/)\nLIBS += -lTinyOrm\n"))),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"{9}","{9}":!0},"# 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_5_3_GCC_64bit-Debug/src$${TINY_BUILD_SUBFOLDER}/)\nLIBS += -lTinyOrm\n")))),(0,l.kt)("p",null,"The same is true for the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," include path. If you don't set the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_VCPKG_ROOT")," or have not defined the ",(0,l.kt)("inlineCode",{parentName:"p"},"VCPKG_ROOT")," environment variable, then you need to set up the ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," for the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," that provides the ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," header files."),(0,l.kt)(p.Z,{groupId:y.IZ,mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# vcpkg - range-v3 and tabulate\n# ---\nINCLUDEPATH += $$quote(/vcpkg/installed/x64-windows/include/)\n"))),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# vcpkg - range-v3 and tabulate\n# ---\nQMAKE_CXXFLAGS += -isystem $$shell_quote(/vcpkg/installed/x64-linux/include/)\n")))),(0,l.kt)("p",null,"You can also use TinyORM's ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," function ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_add_system_includepath()")," which handles ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," in a cross-platform way."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# vcpkg - range-v3 and tabulate\n# ---\ntiny_add_system_includepath(/vcpkg/installed/x64-linux/include/)\n")),(0,l.kt)("p",null,"Do not forget to add ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm0.dll")," on the path on Windows and on the ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux, so your application can find it during execution."),(0,l.kt)(p.Z,{groupId:y.IZ,name:"tinyorm-on-path",mdxType:"Tabs"},(0,l.kt)(d.Z,{value:y.Fo,label:y.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,u.go)(y.Fo,!1)}\\TinyORM\\TinyORM-builds-qmake\\build-debug;" + $env:Path`)),(0,l.kt)(d.Z,{value:y.q5,label:y.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export LD_LIBRARY_PATH=${(0,u.go)(y.q5)}/TinyORM/TinyORM-builds-qmake/build-debug\${PATH:+:}$PATH`))),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"On Linux ",(0,l.kt)("inlineCode",{parentName:"p"},"-isystem")," marks the directory as a system directory, it prevents warnings."),(0,l.kt)("p",{parentName:"admonition"},"On Windows you can use ",(0,l.kt)("inlineCode",{parentName:"p"},"QMAKE_CXXFLAGS_WARN_ON = -external:anglebrackets -external:W0"),", it applies a warning level 0 to the angel bracket includes; ",(0,l.kt)("inlineCode",{parentName:"p"},"#include "),"."),(0,l.kt)("p",{parentName:"admonition"},"With the ",(0,l.kt)("inlineCode",{parentName:"p"},"clang-cl")," with ",(0,l.kt)("inlineCode",{parentName:"p"},"MSVC")," you can use ",(0,l.kt)("inlineCode",{parentName:"p"},"-imsvc"),".")),(0,l.kt)("h3",{id:"auto-configuration-internals"},"Auto-configuration internals"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build system does not support ",(0,l.kt)("inlineCode",{parentName:"p"},"auto-configuration")," of dependencies out of the box but ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," from ",(0,l.kt)("inlineCode",{parentName:"p"},"v0.34.0")," added its own ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature along with the ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," qmake feature. These new features allow us to ",(0,l.kt)("inlineCode",{parentName:"p"},"auto-configure")," ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project, and with their help, the ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files can be ",(0,l.kt)("u",null,"skipped entirely"),"."),(0,l.kt)("p",null,"While it adds additional complexity to the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration process, the benefits are significant."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature is designed to find the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"MySQL")," installations, and ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," to include the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," and ",(0,l.kt)("inlineCode",{parentName:"p"},".env.(win32|unix|mingw)")," files in the project's root folder. These new features can be configured using ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"environment")," variables, and they also contain some guessing logic if these variables are not defined."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature can be turned off using the ",(0,l.kt)("a",{parentName:"p",href:"#disable_autoconf"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_autoconf"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_autoconf"),")."),(0,l.kt)("p",null,"These are ",(0,l.kt)("u",null,(0,l.kt)("inlineCode",{parentName:"p"},"qmake"))," and ",(0,l.kt)("u",null,(0,l.kt)("inlineCode",{parentName:"p"},"environment"))," variables that affect the ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_ROOT")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," installation folder.",(0,l.kt)("br",null),"If not defined, then it tries to use the ",(0,l.kt)("inlineCode",{parentName:"td"},"VCPKG_ROOT")," environment variable.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_TRIPLET")),(0,l.kt)("td",{parentName:"tr",align:null},"The ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"triplet")," to use ",(0,l.kt)("small",null,"(vcpkg/installed/$$TINY_VCPKG_TRIPLET/)"),".",(0,l.kt)("br",null),"If not defined, then it tries to guess the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"triplet")," based on the current compiler and OS (based on the ",(0,l.kt)("inlineCode",{parentName:"td"},"QMAKESPEC"),"), and as the last thing, it tries to use the ",(0,l.kt)("inlineCode",{parentName:"td"},"VCPKG_DEFAULT_TRIPLET")," environment variable.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MYSQL_ROOT")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"MySQL")," installation folder.",(0,l.kt)("br",null),"If not defined, then it tries to guess the ",(0,l.kt)("inlineCode",{parentName:"td"},"MySQL")," installation folder (",(0,l.kt)("inlineCode",{parentName:"td"},"win32")," only): ",(0,l.kt)("code",null,"$$(ProgramFiles)/MySQL/MySQL Server (8.1","|","8.0","|","5.7)/"))))),(0,l.kt)("p",null,"You can set these variables in the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," (recommended) or ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files, in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file (or wherever you want), or as environment variables."),(0,l.kt)("p",null,"These variables will be set after ",(0,l.kt)("inlineCode",{parentName:"p"},"auto-configuration")," is done:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_VCPKG_INCLUDE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"vcpkg")," ",(0,l.kt)("inlineCode",{parentName:"td"},"include")," folder ",(0,l.kt)("small",null,"(vcpkg/installed/","<","triplet",">","/include/)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MYSQL_INCLUDE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"MySQL")," ",(0,l.kt)("inlineCode",{parentName:"td"},"include")," folder ",(0,l.kt)("small",null,"(MySQL Server 8.1/include/)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MYSQL_LIB")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("inlineCode",{parentName:"td"},"MySQL")," ",(0,l.kt)("inlineCode",{parentName:"td"},"lib")," folder ",(0,l.kt)("small",null,"(MySQL Server 8.1/lib/)"),".")))),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_MYSQL_INCLUDE")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_MYSQL_LIB")," are only set on ",(0,l.kt)("inlineCode",{parentName:"p"},"win32")," platform except ",(0,l.kt)("inlineCode",{parentName:"p"},"mingw"),"."),(0,l.kt)("h4",{id:"environment-files"},"Environment files"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," feature allows us to define the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," and ",(0,l.kt)("inlineCode",{parentName:"p"},".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,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration process. On the other hand, the ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files are loaded as late as possible, and they can be used to override the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," file is included ",(0,l.kt)("u",null,"first")," and is included on all platforms."),(0,l.kt)("p",null,"There is only one requirement for this feature to work correctly, and that is to set the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_DOTENV_ROOT")," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," variable to the project's root folder. This variable is ",(0,l.kt)("strong",{parentName:"p"},"already")," set in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file for the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project."),(0,l.kt)("p",null,"Then the following names are taken into account: .env, .env.win32, .env.unix, .env.mingw"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# To find .env and .env.$$QMAKE_PLATFORM files\nTINY_DOTENV_ROOT = $$PWD\n")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tiny_dotenv")," feature can be turned off using the ",(0,l.kt)("a",{parentName:"p",href:"#disable_dotenv"},(0,l.kt)("inlineCode",{parentName:"a"},"disable_dotenv"))," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option (eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG*=disable_dotenv"),")."),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},(0,l.kt)("inlineCode",{parentName:"p"},"Environment files")," don't work in the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," builds.")),(0,l.kt)("h4",{id:"partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"h4"},"TINYORM_BUILD_TREE")),(0,l.kt)("p",null,"You don't have to manually define the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," in ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," or ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," files. The ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," absolute path can be put together for you (this is happening inside the ",(0,l.kt)("inlineCode",{parentName:"p"},"variables.pri")," file) and ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build folder name can be guessed for you too."),(0,l.kt)("p",null,"You must define the following variables before the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm.pri")," will be included to make this real (set them in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf"),"):"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Variable Name"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_MAIN_DIR")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("strong",{parentName:"td"},"PARENT")," folder of the ",(0,l.kt)("inlineCode",{parentName:"td"},"TinyORM")," source folder.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"TINY_BUILD_TREE")),(0,l.kt)("td",{parentName:"tr",align:null},"Path to the ",(0,l.kt)("strong",{parentName:"td"},"current")," build tree - ",(0,l.kt)("inlineCode",{parentName:"td"},"TINY_BUILD_TREE = $$shadowed($$PWD)"),".")))),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"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,l.kt)("inlineCode",{parentName:"p"},"TINY_BUILD_TREE"),"."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# Path to the current build tree (used to guess the TinyORM build tree)\nTINY_BUILD_TREE = $$shadowed($$PWD)\n")),(0,l.kt)("p",null,"If you will follow this pattern or logic then you can switch ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator Kits")," and the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," will be ",(0,l.kt)("strong",{parentName:"p"},"auto-generated")," correctly and will always point to the correct ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build tree."),(0,l.kt)("p",null,"It works this way, all is happening inside the ",(0,l.kt)("inlineCode",{parentName:"p"},"variables.pri"),", it takes a build folder name for the ",(0,l.kt)("strong",{parentName:"p"},"current")," project eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"build-HelloWorld-Desktop_Qt_6_5_3_MSVC2022_64bit-Debug"),", replaces the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," with the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," and as we already know the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," build folder location we can simply concatenate these paths like ",(0,l.kt)("inlineCode",{parentName:"p"},"$$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_5_3_MSVC2022_64bit-Debug"),"."),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"This will only work if you follow the recommended ",(0,l.kt)("a",{parentName:"p",href:"#folders-structure"},(0,l.kt)("inlineCode",{parentName:"a"},"Folders structure")),".")),(0,l.kt)("h3",{id:"manual-configuration-internals"},"Manual configuration internals"),(0,l.kt)("p",null,"There is not much to say about the ",(0,l.kt)("inlineCode",{parentName:"p"},"Manual configuration")," feature. It uses ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files (there are four, one for every project or sub-project), and every project has prepared its own ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri.example")," file for faster initial configuration."),(0,l.kt)("p",null,"These ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri.example")," files are nicely commented on, so you can see what needs to be modified. The ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files are loaded as late as possible, and they can be used to override the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration."),(0,l.kt)("p",null,"If the ",(0,l.kt)("inlineCode",{parentName:"p"},"Auto-configuration")," feature is disabled and there are no ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files, then the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," configuration or build will fail at 100%."),(0,l.kt)("p",null,"These ",(0,l.kt)("inlineCode",{parentName:"p"},"conf.pri")," files are intended for configuring qmake's ",(0,l.kt)("inlineCode",{parentName:"p"},"INCLUDEPATH")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"LIBS"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG")," or eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"QMAKE_LFLAGS"),", or any other ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," options or variables."),(0,l.kt)("h2",{id:"ccache-support"},"Ccache support"),(0,l.kt)("p",null,"The TinyORM supports the ",(0,l.kt)("a",{parentName:"p",href:"https://ccache.dev/"},(0,l.kt)("inlineCode",{parentName:"a"},"ccache"))," out of the box for all ",(0,l.kt)("a",{parentName:"p",href:"/supported-compilers"},"supported compilers"),". For qmake you can enable it using the ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG+=ccache")," on Linux or ",(0,l.kt)("inlineCode",{parentName:"p"},"CONFIG+=tiny_ccache_win32")," on Windows. For CMake you can set the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_CXX_COMPILER_LAUNCHER=ccache"),"."),(0,l.kt)("p",null,"On ",(0,l.kt)("inlineCode",{parentName:"p"},"Linux")," it's clear, the ccache is fully supported and works also with the ",(0,l.kt)("inlineCode",{parentName:"p"},"precompiled headers"),". But was necessary to add some workarounds to the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake"),"/",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," build systems to make out of the box support on ",(0,l.kt)("inlineCode",{parentName:"p"},"Windows"),". When you enable the ",(0,l.kt)("inlineCode",{parentName:"p"},"ccache")," on ",(0,l.kt)("inlineCode",{parentName:"p"},"Windows")," then the build system disables ",(0,l.kt)("inlineCode",{parentName:"p"},"precompiled headers")," and replaces the ",(0,l.kt)("inlineCode",{parentName:"p"},"-Zi")," compiler option with the ",(0,l.kt)("inlineCode",{parentName:"p"},"-Z7")," (link to the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/ccache/ccache/issues/1040"},"issue"),")."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can install the ccache using the ",(0,l.kt)("inlineCode",{parentName:"p"},"scoop install ccache")," command on Windows.")))}R.isMDXComponent=!0},5705:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-additional_arguments-14d3b6b82ad6d28db5b999a462500a6a.png"},7066:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-build_settings-7caa6d7c86232484b82acb24b5a3a6a7.png"},6874:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-configure_project-0b6821ea0523567dab9f21b3215055a3.png"}}]); \ No newline at end of file diff --git a/assets/js/1222ea4e.93c74363.js b/assets/js/1222ea4e.93c74363.js new file mode 100644 index 000000000..d26f87380 --- /dev/null +++ b/assets/js/1222ea4e.93c74363.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[535],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>h});var i=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function r(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=i.createContext({}),d=function(e){var t=i.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):r(r({},t),e)),n},p=function(e){var t=d(e.components);return i.createElement(l.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},c=i.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=d(n),c=a,h=u["".concat(l,".").concat(c)]||u[c]||m[c]||o;return n?i.createElement(h,r(r({ref:t},p),{},{components:n})):i.createElement(h,r({ref:t},p))}));function h(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,r=new Array(o);r[0]=c;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[u]="string"==typeof e?e:a,r[1]=s;for(var d=2;d{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>r,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>d});var i=n(7462),a=(n(7294),n(3905));const o={sidebar_position:4,sidebar_label:"Serialization",description:"TinyORM models serialization allows you to serialize models and collection of models including all nested relations to JSON. It also supports converting to vectors or maps and allows controlling a custom date format during serialization.",keywords:["c++ orm","orm","serialization","json","toJson","serializing models","serializing relations","serializing collections","converting","toVector","toMap"]},r="TinyORM: Serialization",s={unversionedId:"tinyorm/serialization",id:"tinyorm/serialization",title:"TinyORM: Serialization",description:"TinyORM models serialization allows you to serialize models and collection of models including all nested relations to JSON. It also supports converting to vectors or maps and allows controlling a custom date format during serialization.",source:"@site/docs/tinyorm/serialization.mdx",sourceDirName:"tinyorm",slug:"/tinyorm/serialization",permalink:"/tinyorm/serialization",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinyorm/serialization.mdx",tags:[],version:"current",sidebarPosition:4,frontMatter:{sidebar_position:4,sidebar_label:"Serialization",description:"TinyORM models serialization allows you to serialize models and collection of models including all nested relations to JSON. It also supports converting to vectors or maps and allows controlling a custom date format during serialization.",keywords:["c++ orm","orm","serialization","json","toJson","serializing models","serializing relations","serializing collections","converting","toVector","toMap"]},sidebar:"tinyormSidebar",previous:{title:"Casts",permalink:"/tinyorm/casts"},next:{title:"Getting Started",permalink:"/tinydrivers/getting-started"}},l={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Serializing Models & Collections",id:"serializing-models-and-collections",level:2},{value:"Serializing To Vectors & Maps",id:"serializing-to-vectors-and-maps",level:3},{value:"Serializing To JSON",id:"serializing-to-json",level:3},{value:"Relationships",id:"relationships",level:4},{value:"Hiding Attributes From JSON",id:"hiding-attributes-from-json",level:2},{value:"Temporarily Modifying Attribute Visibility",id:"temporarily-modifying-attribute-visibility",level:4},{value:"Appending Values To JSON",id:"appending-values-to-json",level:2},{value:"Appending At Run Time",id:"appending-at-run-time",level:4},{value:"Date Serialization",id:"date-serialization",level:2},{value:"Customizing The Default Date Format",id:"customizing-the-default-date-format",level:4},{value:"Customizing The Date Format Per Attribute",id:"customizing-the-date-format-per-attribute",level:4}],p={toc:d},u="wrapper";function m(e){let{components:t,...n}=e;return(0,a.kt)(u,(0,i.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"tinyorm-serialization"},"TinyORM: Serialization"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#serializing-models-and-collections"},"Serializing Models & Collections"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#serializing-to-vectors-and-maps"},"Serializing To Vectors & Maps")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#serializing-to-json"},"Serializing To JSON")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#hiding-attributes-from-json"},"Hiding Attributes From JSON")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#appending-values-to-json"},"Appending Values To JSON")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#date-serialization"},"Date Serialization"))),(0,a.kt)("h2",{id:"introduction"},"Introduction"),(0,a.kt)("p",null,"When building APIs using TinyORM, you will often need to convert your models and relationships to vectors, maps, or JSON. TinyORM includes convenient methods for making these conversions, as well as controlling which attributes are included in the serialized representation of your models."),(0,a.kt)("h2",{id:"serializing-models-and-collections"},"Serializing Models & Collections"),(0,a.kt)("h3",{id:"serializing-to-vectors-and-maps"},"Serializing To Vectors & Maps"),(0,a.kt)("p",null,"To convert a model and its loaded ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationships")," to a vector, you should use the ",(0,a.kt)("inlineCode",{parentName:"p"},"toVector")," or ",(0,a.kt)("inlineCode",{parentName:"p"},"toMap")," methods. This methods are recursive, so all attributes and all relations (including the relations of relations) will be converted to vectors:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using Models::User;\n\nauto user = User::with("roles")->first();\n\nreturn user->toVector();\n\nreturn user->toMap();\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"attributesToVector")," or ",(0,a.kt)("inlineCode",{parentName:"p"},"attributesToMap")," methods may be used to convert a model's attributes to a vector or map but not its relationships:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"auto user = User::first();\n\nreturn user->attributesToVector();\n\nreturn user->attributesToMap();\n")),(0,a.kt)("p",null,"You may also convert entire ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections"},"collections")," of models to vectors or maps by calling the ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tovector"},(0,a.kt)("inlineCode",{parentName:"a"},"toVector"))," or ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tomap"},(0,a.kt)("inlineCode",{parentName:"a"},"toMap"))," methods on the collection instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users = User::with("roles")->all();\n\nreturn users.toVector();\n\nreturn users.toMap();\n')),(0,a.kt)("h3",{id:"serializing-to-json"},"Serializing To JSON"),(0,a.kt)("p",null,"To convert a model to JSON, you should use the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," method. Like ",(0,a.kt)("inlineCode",{parentName:"p"},"toVector")," or ",(0,a.kt)("inlineCode",{parentName:"p"},"toMap"),", the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," method is recursive, so all attributes and relations will be converted to JSON. You may also specify any JSON encoding options that are supported by ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qjsondocument.html#toJson"},"QJsonDocument::toJson"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using Models::User;\n\nauto user = User::with("roles")->find(1);\n\nreturn user->toJson();\n\nreturn user->toJson(QJsonDocument::Indented);\n')),(0,a.kt)("p",null,"You may also convert entire ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections"},"collections")," of models to JSON by calling the ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tojson"},(0,a.kt)("inlineCode",{parentName:"a"},"toJson"))," method on the collection instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users = User::with("roles")->findMany({1, 2});\n\nreturn users.toJson();\n')),(0,a.kt)("p",null,"You can also convert models to the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qjsonobject.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonObject"))," and ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qjsondocument.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonDocument"))," using the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJsonArray")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"toJsonDocument")," methods and collection of models to ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qjsonarray.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonArray"))," and ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qjsondocument.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonDocument"))," using the ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tojsonarray"},(0,a.kt)("inlineCode",{parentName:"a"},"toJsonArray"))," and ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tojsondocument"},(0,a.kt)("inlineCode",{parentName:"a"},"toJsonDocument"))," methods."),(0,a.kt)("h4",{id:"relationships"},"Relationships"),(0,a.kt)("p",null,'When a TinyORM model is converted to JSON, its loaded relationships will automatically be included as attributes on the JSON object. Also, though TinyORM relationship methods are defined using "camelCase" method names, a relationship\'s JSON attributes will be "snake_case".'),(0,a.kt)("p",null,"This behavior is affected and can be overridden by the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_snakeAttributes")," static data member:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"#include \n\nusing Orm::Tiny::Model;\n\nclass Album final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! Indicates whether attributes are snake_cased during serialization. */\n inline static const bool u_snakeAttributes = false;\n};\n")),(0,a.kt)("h2",{id:"hiding-attributes-from-json"},"Hiding Attributes From JSON"),(0,a.kt)("p",null,"Sometimes you may wish to limit the attributes, such as passwords, that are included in your model's vector, map, or JSON representation. To do so, add a ",(0,a.kt)("inlineCode",{parentName:"p"},"u_hidden")," static data member to your model. Attributes that are listed in the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_hidden")," data member set will not be included in the serialized representation of your model:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! The attributes that should be hidden during serialization. */\n inline static std::set u_hidden {"password"};\n};\n')),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"To hide relationships, add the relationship's method name to your TinyORM model's ",(0,a.kt)("inlineCode",{parentName:"p"},"u_hidden")," static data member.")),(0,a.kt)("p",null,"Alternatively, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_visible"),' static data member to define an "allow list" of attributes that should be included in your model\'s vector, map, and JSON representation. All attributes that are not present in the ',(0,a.kt)("inlineCode",{parentName:"p"},"u_visible")," set will be hidden during serialization:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! The attributes that should be visible during serialization. */\n inline static std::set u_visible {\n "first_name", "last_name",\n };\n};\n')),(0,a.kt)("h4",{id:"temporarily-modifying-attribute-visibility"},"Temporarily Modifying Attribute Visibility"),(0,a.kt)("p",null,"If you would like to make some typically hidden attributes visible on a given model instance, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"makeVisible")," method. The ",(0,a.kt)("inlineCode",{parentName:"p"},"makeVisible")," method returns a model reference:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'return user.makeVisible("attribute").toMap();\n\nreturn user.makeVisible({"id", "name"}).toMap();\n')),(0,a.kt)("p",null,"Likewise, if you would like to hide some attributes that are typically visible, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"makeHidden")," method."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'return user.makeHidden("attribute").toVector();\n\nreturn user.makeHidden({"id", "name"}).toVector();\n')),(0,a.kt)("p",null,"If you wish to temporarily override all of the visible or hidden attributes, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"setVisible")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"setHidden")," methods respectively:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'return user.setVisible({"id", "name"}).toMap();\n\nreturn user.setHidden({"email", "password", "note"}).toJson();\n')),(0,a.kt)("p",null,"You can also clear all visible and hidden attributes or determine whether a visible / hidden attribute is defined:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'user.clearVisible();\n\nuser.clearHidden();\n\nreturn user.hasVisible("name");\n\nreturn user.hasHidden("password");\n')),(0,a.kt)("h2",{id:"appending-values-to-json"},"Appending Values To JSON"),(0,a.kt)("p",null,"Occasionally, when converting models to vector, map, or JSON, you may wish to add attributes that do not have a corresponding column in your database. To do so, first define an ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/casts#accessors"},"accessor")," for the value:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\nprotected:\n /*! Accessor to determine if the user is an administrator. */\n Attribute isAdmin() const noexcept\n {\n return Attribute::make(/* get */ []() -> QVariant\n {\n return QStringLiteral("yes");\n });\n }\n};\n')),(0,a.kt)("p",null,"If you would like the accessor to always be appended to your model's vector, map, and JSON representations, you may add the attribute name to the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_appends"),' data member set of your model. Note that attribute names are typically referenced using their "snake_case" serialized representation, even though the accessor\'s method name is defined using "camelCase":'),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! Map of mutator names to methods. */\n inline static const QHash u_mutators {\n {"is_admin", &User::isAdmin},\n };\n\n /*! The attributes that should be appended during serialization. */\n std::set u_appends {"is_admin"};\n};\n')),(0,a.kt)("p",null,"Once the attribute has been added to the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_appends")," set, it will be included in both the model's vector, map, and JSON representations. Attributes in the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_appends")," set will also respect the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_visible")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"u_hidden")," attribute settings configured on the model."),(0,a.kt)("p",null,"Special note should be given to the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_mutators")," static data member map, which maps accessors' attribute names to its methods. This data member is ",(0,a.kt)("strong",{parentName:"p"},"required")," because C++ does not currently support reflection."),(0,a.kt)("h4",{id:"appending-at-run-time"},"Appending At Run Time"),(0,a.kt)("p",null,"At runtime, you may instruct a model instance to append additional attributes using the ",(0,a.kt)("inlineCode",{parentName:"p"},"append")," method. Or, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"setAppends")," method to override the entire set of appended attributes for a given model instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'return user.append("is_admin").toVector();\n\nreturn user.append({"is_admin", "is_banned"}).toMap();\n\nreturn user.setAppends({"is_admin"}).toJson();\n')),(0,a.kt)("p",null,"And you can also clear all appends or determine whether an append is defined:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'user.clearAppends();\n\nreturn user.hasAppend("is_admin");\n')),(0,a.kt)("h2",{id:"date-serialization"},"Date Serialization"),(0,a.kt)("h4",{id:"customizing-the-default-date-format"},"Customizing The Default Date Format"),(0,a.kt)("p",null,"You may customize the default serialization format by overriding the ",(0,a.kt)("inlineCode",{parentName:"p"},"serializeDate")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"serializeDateTime")," methods. These methods do not affect how your dates are formatted for storage in the database:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'/*! Prepare a date for vector, map, or JSON serialization. */\nQString serializeDate(const QDate date)\n{\n return date.toString("yyyy-MM-dd");\n}\n\n/*! Prepare a datetime for vector, map, or JSON serialization. */\nQString serializeDateTime(const QDateTime &datetime)\n{\n return datetime.toUTC().toString("yyyy-MM-ddTHH:mm:ssZ");\n}\n')),(0,a.kt)("h4",{id:"customizing-the-date-format-per-attribute"},"Customizing The Date Format Per Attribute"),(0,a.kt)("p",null,"You may customize the serialization format of individual TinyORM date attributes by specifying the date format in the model's ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/casts#attribute-casting"},"cast declarations"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'/*! The attributes that should be cast. */\ninline static std::unordered_map u_casts {\n {"birthday", {CastType::CustomQDate, "yyyy-MM-dd"}},\n {"joined_at", {CastType::CustomQDateTime, "yyyy-MM-dd HH:00"}},\n};\n')))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/1222ea4e.f70dc92d.js b/assets/js/1222ea4e.f70dc92d.js deleted file mode 100644 index c2d5ac9b4..000000000 --- a/assets/js/1222ea4e.f70dc92d.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[535],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>h});var i=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function r(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=i.createContext({}),d=function(e){var t=i.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):r(r({},t),e)),n},u=function(e){var t=d(e.components);return i.createElement(l.Provider,{value:t},e.children)},p="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},c=i.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),p=d(n),c=a,h=p["".concat(l,".").concat(c)]||p[c]||m[c]||o;return n?i.createElement(h,r(r({ref:t},u),{},{components:n})):i.createElement(h,r({ref:t},u))}));function h(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,r=new Array(o);r[0]=c;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:a,r[1]=s;for(var d=2;d{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>r,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>d});var i=n(7462),a=(n(7294),n(3905));const o={sidebar_position:4,sidebar_label:"Serialization",description:"TinyORM models serialization allows you to serialize models and collection of models including all nested relations to JSON. It also supports converting to vectors or maps and allows controlling a custom date format during serialization.",keywords:["c++ orm","orm","serialization","json","toJson","serializing models","serializing relations","serializing collections","converting","toVector","toMap"]},r="TinyORM: Serialization",s={unversionedId:"tinyorm/serialization",id:"tinyorm/serialization",title:"TinyORM: Serialization",description:"TinyORM models serialization allows you to serialize models and collection of models including all nested relations to JSON. It also supports converting to vectors or maps and allows controlling a custom date format during serialization.",source:"@site/docs/tinyorm/serialization.mdx",sourceDirName:"tinyorm",slug:"/tinyorm/serialization",permalink:"/tinyorm/serialization",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinyorm/serialization.mdx",tags:[],version:"current",sidebarPosition:4,frontMatter:{sidebar_position:4,sidebar_label:"Serialization",description:"TinyORM models serialization allows you to serialize models and collection of models including all nested relations to JSON. It also supports converting to vectors or maps and allows controlling a custom date format during serialization.",keywords:["c++ orm","orm","serialization","json","toJson","serializing models","serializing relations","serializing collections","converting","toVector","toMap"]},sidebar:"tinyormSidebar",previous:{title:"Casts",permalink:"/tinyorm/casts"},next:{title:"TinyORM",permalink:"/building/tinyorm"}},l={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Serializing Models & Collections",id:"serializing-models-and-collections",level:2},{value:"Serializing To Vectors & Maps",id:"serializing-to-vectors-and-maps",level:3},{value:"Serializing To JSON",id:"serializing-to-json",level:3},{value:"Relationships",id:"relationships",level:4},{value:"Hiding Attributes From JSON",id:"hiding-attributes-from-json",level:2},{value:"Temporarily Modifying Attribute Visibility",id:"temporarily-modifying-attribute-visibility",level:4},{value:"Appending Values To JSON",id:"appending-values-to-json",level:2},{value:"Appending At Run Time",id:"appending-at-run-time",level:4},{value:"Date Serialization",id:"date-serialization",level:2},{value:"Customizing The Default Date Format",id:"customizing-the-default-date-format",level:4},{value:"Customizing The Date Format Per Attribute",id:"customizing-the-date-format-per-attribute",level:4}],u={toc:d},p="wrapper";function m(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,i.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"tinyorm-serialization"},"TinyORM: Serialization"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#serializing-models-and-collections"},"Serializing Models & Collections"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#serializing-to-vectors-and-maps"},"Serializing To Vectors & Maps")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#serializing-to-json"},"Serializing To JSON")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#hiding-attributes-from-json"},"Hiding Attributes From JSON")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#appending-values-to-json"},"Appending Values To JSON")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#date-serialization"},"Date Serialization"))),(0,a.kt)("h2",{id:"introduction"},"Introduction"),(0,a.kt)("p",null,"When building APIs using TinyORM, you will often need to convert your models and relationships to vectors, maps, or JSON. TinyORM includes convenient methods for making these conversions, as well as controlling which attributes are included in the serialized representation of your models."),(0,a.kt)("h2",{id:"serializing-models-and-collections"},"Serializing Models & Collections"),(0,a.kt)("h3",{id:"serializing-to-vectors-and-maps"},"Serializing To Vectors & Maps"),(0,a.kt)("p",null,"To convert a model and its loaded ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationships")," to a vector, you should use the ",(0,a.kt)("inlineCode",{parentName:"p"},"toVector")," or ",(0,a.kt)("inlineCode",{parentName:"p"},"toMap")," methods. This methods are recursive, so all attributes and all relations (including the relations of relations) will be converted to vectors:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using Models::User;\n\nauto user = User::with("roles")->first();\n\nreturn user->toVector();\n\nreturn user->toMap();\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"attributesToVector")," or ",(0,a.kt)("inlineCode",{parentName:"p"},"attributesToMap")," methods may be used to convert a model's attributes to a vector or map but not its relationships:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"auto user = User::first();\n\nreturn user->attributesToVector();\n\nreturn user->attributesToMap();\n")),(0,a.kt)("p",null,"You may also convert entire ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections"},"collections")," of models to vectors or maps by calling the ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tovector"},(0,a.kt)("inlineCode",{parentName:"a"},"toVector"))," or ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tomap"},(0,a.kt)("inlineCode",{parentName:"a"},"toMap"))," methods on the collection instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users = User::with("roles")->all();\n\nreturn users.toVector();\n\nreturn users.toMap();\n')),(0,a.kt)("h3",{id:"serializing-to-json"},"Serializing To JSON"),(0,a.kt)("p",null,"To convert a model to JSON, you should use the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," method. Like ",(0,a.kt)("inlineCode",{parentName:"p"},"toVector")," or ",(0,a.kt)("inlineCode",{parentName:"p"},"toMap"),", the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," method is recursive, so all attributes and relations will be converted to JSON. You may also specify any JSON encoding options that are supported by ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qjsondocument.html#toJson"},"QJsonDocument::toJson"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using Models::User;\n\nauto user = User::with("roles")->find(1);\n\nreturn user->toJson();\n\nreturn user->toJson(QJsonDocument::Indented);\n')),(0,a.kt)("p",null,"You may also convert entire ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections"},"collections")," of models to JSON by calling the ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tojson"},(0,a.kt)("inlineCode",{parentName:"a"},"toJson"))," method on the collection instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users = User::with("roles")->findMany({1, 2});\n\nreturn users.toJson();\n')),(0,a.kt)("p",null,"You can also convert models to the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qjsonobject.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonObject"))," and ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qjsondocument.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonDocument"))," using the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJsonArray")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"toJsonDocument")," methods and collection of models to ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qjsonarray.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonArray"))," and ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qjsondocument.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonDocument"))," using the ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tojsonarray"},(0,a.kt)("inlineCode",{parentName:"a"},"toJsonArray"))," and ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/collections#method-tojsondocument"},(0,a.kt)("inlineCode",{parentName:"a"},"toJsonDocument"))," methods."),(0,a.kt)("h4",{id:"relationships"},"Relationships"),(0,a.kt)("p",null,'When a TinyORM model is converted to JSON, its loaded relationships will automatically be included as attributes on the JSON object. Also, though TinyORM relationship methods are defined using "camelCase" method names, a relationship\'s JSON attributes will be "snake_case".'),(0,a.kt)("p",null,"This behavior is affected and can be overridden by the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_snakeAttributes")," static data member:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"#include \n\nusing Orm::Tiny::Model;\n\nclass Album final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! Indicates whether attributes are snake_cased during serialization. */\n inline static const bool u_snakeAttributes = false;\n};\n")),(0,a.kt)("h2",{id:"hiding-attributes-from-json"},"Hiding Attributes From JSON"),(0,a.kt)("p",null,"Sometimes you may wish to limit the attributes, such as passwords, that are included in your model's vector, map, or JSON representation. To do so, add a ",(0,a.kt)("inlineCode",{parentName:"p"},"u_hidden")," static data member to your model. Attributes that are listed in the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_hidden")," data member set will not be included in the serialized representation of your model:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! The attributes that should be hidden during serialization. */\n inline static std::set u_hidden {"password"};\n};\n')),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"To hide relationships, add the relationship's method name to your TinyORM model's ",(0,a.kt)("inlineCode",{parentName:"p"},"u_hidden")," static data member.")),(0,a.kt)("p",null,"Alternatively, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_visible"),' static data member to define an "allow list" of attributes that should be included in your model\'s vector, map, and JSON representation. All attributes that are not present in the ',(0,a.kt)("inlineCode",{parentName:"p"},"u_visible")," set will be hidden during serialization:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! The attributes that should be visible during serialization. */\n inline static std::set u_visible {\n "first_name", "last_name",\n };\n};\n')),(0,a.kt)("h4",{id:"temporarily-modifying-attribute-visibility"},"Temporarily Modifying Attribute Visibility"),(0,a.kt)("p",null,"If you would like to make some typically hidden attributes visible on a given model instance, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"makeVisible")," method. The ",(0,a.kt)("inlineCode",{parentName:"p"},"makeVisible")," method returns a model reference:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'return user.makeVisible("attribute").toMap();\n\nreturn user.makeVisible({"id", "name"}).toMap();\n')),(0,a.kt)("p",null,"Likewise, if you would like to hide some attributes that are typically visible, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"makeHidden")," method."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'return user.makeHidden("attribute").toVector();\n\nreturn user.makeHidden({"id", "name"}).toVector();\n')),(0,a.kt)("p",null,"If you wish to temporarily override all of the visible or hidden attributes, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"setVisible")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"setHidden")," methods respectively:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'return user.setVisible({"id", "name"}).toMap();\n\nreturn user.setHidden({"email", "password", "note"}).toJson();\n')),(0,a.kt)("p",null,"You can also clear all visible and hidden attributes or determine whether a visible / hidden attribute is defined:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'user.clearVisible();\n\nuser.clearHidden();\n\nreturn user.hasVisible("name");\n\nreturn user.hasHidden("password");\n')),(0,a.kt)("h2",{id:"appending-values-to-json"},"Appending Values To JSON"),(0,a.kt)("p",null,"Occasionally, when converting models to vector, map, or JSON, you may wish to add attributes that do not have a corresponding column in your database. To do so, first define an ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/casts#accessors"},"accessor")," for the value:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\nprotected:\n /*! Accessor to determine if the user is an administrator. */\n Attribute isAdmin() const noexcept\n {\n return Attribute::make(/* get */ []() -> QVariant\n {\n return QStringLiteral("yes");\n });\n }\n};\n')),(0,a.kt)("p",null,"If you would like the accessor to always be appended to your model's vector, map, and JSON representations, you may add the attribute name to the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_appends"),' data member set of your model. Note that attribute names are typically referenced using their "snake_case" serialized representation, even though the accessor\'s method name is defined using "camelCase":'),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! Map of mutator names to methods. */\n inline static const QHash u_mutators {\n {"is_admin", &User::isAdmin},\n };\n\n /*! The attributes that should be appended during serialization. */\n std::set u_appends {"is_admin"};\n};\n')),(0,a.kt)("p",null,"Once the attribute has been added to the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_appends")," set, it will be included in both the model's vector, map, and JSON representations. Attributes in the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_appends")," set will also respect the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_visible")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"u_hidden")," attribute settings configured on the model."),(0,a.kt)("p",null,"Special note should be given to the ",(0,a.kt)("inlineCode",{parentName:"p"},"u_mutators")," static data member map, which maps accessors' attribute names to its methods. This data member is ",(0,a.kt)("strong",{parentName:"p"},"required")," because C++ does not currently support reflection."),(0,a.kt)("h4",{id:"appending-at-run-time"},"Appending At Run Time"),(0,a.kt)("p",null,"At runtime, you may instruct a model instance to append additional attributes using the ",(0,a.kt)("inlineCode",{parentName:"p"},"append")," method. Or, you may use the ",(0,a.kt)("inlineCode",{parentName:"p"},"setAppends")," method to override the entire set of appended attributes for a given model instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'return user.append("is_admin").toVector();\n\nreturn user.append({"is_admin", "is_banned"}).toMap();\n\nreturn user.setAppends({"is_admin"}).toJson();\n')),(0,a.kt)("p",null,"And you can also clear all appends or determine whether an append is defined:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'user.clearAppends();\n\nreturn user.hasAppend("is_admin");\n')),(0,a.kt)("h2",{id:"date-serialization"},"Date Serialization"),(0,a.kt)("h4",{id:"customizing-the-default-date-format"},"Customizing The Default Date Format"),(0,a.kt)("p",null,"You may customize the default serialization format by overriding the ",(0,a.kt)("inlineCode",{parentName:"p"},"serializeDate")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"serializeDateTime")," methods. These methods do not affect how your dates are formatted for storage in the database:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'/*! Prepare a date for vector, map, or JSON serialization. */\nQString serializeDate(const QDate date)\n{\n return date.toString("yyyy-MM-dd");\n}\n\n/*! Prepare a datetime for vector, map, or JSON serialization. */\nQString serializeDateTime(const QDateTime &datetime)\n{\n return datetime.toUTC().toString("yyyy-MM-ddTHH:mm:ssZ");\n}\n')),(0,a.kt)("h4",{id:"customizing-the-date-format-per-attribute"},"Customizing The Date Format Per Attribute"),(0,a.kt)("p",null,"You may customize the serialization format of individual TinyORM date attributes by specifying the date format in the model's ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/casts#attribute-casting"},"cast declarations"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'/*! The attributes that should be cast. */\ninline static std::unordered_map u_casts {\n {"birthday", {CastType::CustomQDate, "yyyy-MM-dd"}},\n {"joined_at", {CastType::CustomQDateTime, "yyyy-MM-dd HH:00"}},\n};\n')))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/21dc2778.8476e46c.js b/assets/js/21dc2778.8476e46c.js deleted file mode 100644 index 28878ea7c..000000000 --- a/assets/js/21dc2778.8476e46c.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[291],{5162:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(7294),l=n(6010);const i={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,l.Z)(i.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>C});var a=n(7462),l=n(7294),i=n(6010),o=n(2466),r=n(6550),m=n(1980),d=n(7392),p=n(12);function s(e){return function(e){return l.Children.map(e,(e=>{if(!e||(0,l.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:l}}=e;return{value:t,label:n,attributes:a,default:l}}))}function u(e){const{values:t,children:n}=e;return(0,l.useMemo)((()=>{const e=t??s(n);return function(e){const t=(0,d.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function c(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const a=(0,r.k6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,m._X)(i),(0,l.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(a.location.search);t.set(i,e),a.replace({...a.location,search:t.toString()})}),[i,a])]}function k(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,i=u(e),[o,r]=(0,l.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!c({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:i}))),[m,d]=h({queryString:n,groupId:a}),[s,k]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,i]=(0,p.Nk)(n);return[a,(0,l.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:a}),g=(()=>{const e=m??s;return c({value:e,tabValues:i})?e:null})();(0,l.useLayoutEffect)((()=>{g&&r(g)}),[g]);return{selectedValue:o,selectValue:(0,l.useCallback)((e=>{if(!c({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);r(e),d(e),k(e)}),[d,k,i]),tabValues:i}}var g=n(2389);const N={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function b(e){let{className:t,block:n,selectedValue:r,selectValue:m,tabValues:d}=e;const p=[],{blockElementScrollPositionUntilNextRender:s}=(0,o.o5)(),u=e=>{const t=e.currentTarget,n=p.indexOf(t),a=d[n].value;a!==r&&(s(t),m(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=p.indexOf(e.currentTarget)+1;t=p[n]??p[0];break}case"ArrowLeft":{const n=p.indexOf(e.currentTarget)-1;t=p[n]??p[p.length-1];break}}t?.focus()};return l.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.Z)("tabs",{"tabs--block":n},t)},d.map((e=>{let{value:t,label:n,attributes:o}=e;return l.createElement("li",(0,a.Z)({role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,key:t,ref:e=>p.push(e),onKeyDown:c,onClick:u},o,{className:(0,i.Z)("tabs__item",N.tabItem,o?.className,{"tabs__item--active":r===t})}),n??t)})))}function f(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,l.cloneElement)(e,{className:"margin-top--md"}):null}return l.createElement("div",{className:"margin-top--md"},i.map(((e,t)=>(0,l.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function y(e){const t=k(e);return l.createElement("div",{className:(0,i.Z)("tabs-container",N.tabList)},l.createElement(b,(0,a.Z)({},e,t)),l.createElement(f,(0,a.Z)({},e,t)))}function C(e){const t=(0,g.Z)();return l.createElement(y,(0,a.Z)({key:String(t)},e))}},5178:(e,t,n)=>{n.d(t,{Z:()=>r});var a=n(7294),l=n(6550);const i={apiTable:"apiTable_flxF"};const o=(0,a.forwardRef)(((e,t)=>{let{name:n,children:i}=e;const o=function(e){let t=e;for(;(0,a.isValidElement)(t);)[t]=a.Children.toArray(t.props.children);return t}(i),r=n?`#${n}-${o}`:`#${o}`,m=(0,l.k6)();return a.createElement("tr",{id:o,tabIndex:0,ref:m.location.hash===r?t:void 0,onClick:()=>{m.push(r)},onKeyDown:e=>{"Enter"===e.key&&m.push(r)}},i.props.children)}));function r(e){let{children:t,name:n}=e;const[l,r]=a.Children.toArray(t.props.children),m=(0,a.useRef)(null);(0,a.useEffect)((()=>{m.current?.focus()}),[m]);const d=a.Children.map(r.props.children,(e=>a.createElement(o,{name:n,ref:m},e)));return a.createElement("table",{className:i.apiTable},l,a.createElement("tbody",null,d))}},2044:(e,t,n)=>{n.d(t,{$t:()=>s,Ae:()=>g,C:()=>h,DK:()=>N,Fo:()=>r,Fs:()=>l,IM:()=>k,IZ:()=>a,RS:()=>T,VE:()=>b,Wg:()=>y,_A:()=>d,al:()=>v,jk:()=>c,js:()=>m,of:()=>p,q5:()=>o,qb:()=>C,vk:()=>u,wU:()=>i,zg:()=>f});const a="shell",l="database",i="application",o="bash",r="pwsh",m="zsh",d="maria",p="mysql",s="postgres",u="sqlite",c="application",h="bash",k="pwsh",g="zsh",N="MariaDB",b="MySQL",f="PostgreSQL",y="SQLite",C="tinyorm.org",v="$HOME/Code/c/",T="$env:USERPROFILE\\Code\\c\\"},4355:(e,t,n)=>{n.d(t,{Z:()=>i});var a=n(7294),l=n(9482);function i(){const e=(0,a.useContext)(l.Z);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6005:(e,t,n)=>{n.d(t,{AE:()=>r,EA:()=>o,em:()=>d,go:()=>m,mT:()=>p,we:()=>s});var a=n(4355),l=n(2389),i=n(2044);const o=function(e,t){return void 0===t&&(t=!0),u((0,a.Z)().rootFolder[e]??d(e),e,t)},r=()=>(0,a.Z)().rootFolder[i.wU]??d(i.wU),m=function(e,t){if(void 0===t&&(t=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const n=t||e!==i.Fo?"/":"\\";return u(o(e)+n+r(),e,t)};function d(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,l.Z)())return"";switch(e){case i.Fo:return i.RS;case i.q5:return i.al;case i.wU:return i.qb;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function p(e){return e===i.wU}function s(e,t){if(null==t||""===t)return t;const n="$ENV{$1}$2";switch(e){case i.Fo:return h(t).replace(/\$env:(.+?)(\/.*)/,n);case i.q5:return t.replace(/\$(.+?)(\/.*)/,n);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function u(e,t,n){if(void 0===n&&(n=!0),null==e||""===e)return e;if(t!==i.Fo)return c(e);const a=c(e);return n?h(a):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(a)}function c(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function h(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},6122:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>h,contentTitle:()=>u,default:()=>b,frontMatter:()=>s,metadata:()=>c,toc:()=>k});var a=n(7462),l=(n(7294),n(3905)),i=n(5178),o=n(7693),r=n(5162),m=n(4866),d=n(2044),p=n(6005);const s={sidebar_position:2,sidebar_label:"Migrations",description:"Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. Migrations use the Schema facade that provides database agnostic support for creating and manipulating tables across all of TinyORM's supported database systems.",keywords:["c++ orm","database","migrations","tinyorm"]},u="Database: Migrations",c={unversionedId:"database/migrations",id:"database/migrations",title:"Database: Migrations",description:"Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. Migrations use the Schema facade that provides database agnostic support for creating and manipulating tables across all of TinyORM's supported database systems.",source:"@site/docs/database/migrations.mdx",sourceDirName:"database",slug:"/database/migrations",permalink:"/database/migrations",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/database/migrations.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,sidebar_label:"Migrations",description:"Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. Migrations use the Schema facade that provides database agnostic support for creating and manipulating tables across all of TinyORM's supported database systems.",keywords:["c++ orm","database","migrations","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Query Builder",permalink:"/database/query-builder"},next:{title:"Seeding",permalink:"/database/seeding"}},h={},k=[{value:"Introduction",id:"introduction",level:2},{value:"Generating Migrations",id:"generating-migrations",level:2},{value:"Migrations naming rules",id:"migrations-naming-rules",level:4},{value:"Tab completion",id:"tab-completion",level:2},{value:"Alternative installation methods",id:"alternative-installation-methods",level:3},{value:"Static installation",id:"static-installation",level:4},{value:"Dynamic installation",id:"dynamic-installation",level:4},{value:"Migration Structure",id:"migration-structure",level:2},{value:"Setting The Migration Connection",id:"setting-the-migration-connection",level:4},{value:"Running Migrations",id:"running-migrations",level:2},{value:"Forcing Migrations To Run In Production",id:"forcing-migrations-to-run-in-production",level:4},{value:"Rolling Back Migrations",id:"rolling-back-migrations",level:3},{value:"Roll Back & Migrate Using A Single Command",id:"roll-back--migrate-using-a-single-command",level:4},{value:"Drop All Tables & Migrate",id:"drop-all-tables--migrate",level:4},{value:"Tables",id:"tables",level:2},{value:"Creating Tables",id:"creating-tables",level:3},{value:"Checking For Table / Column Existence",id:"checking-for-table--column-existence",level:4},{value:"Database Connection & Table Options",id:"database-connection--table-options",level:4},{value:"Updating Tables",id:"updating-tables",level:3},{value:"Renaming / Dropping Tables",id:"renaming-and-dropping-tables",level:3},{value:"Renaming Tables With Foreign Keys",id:"renaming-tables-with-foreign-keys",level:4},{value:"Columns",id:"columns",level:2},{value:"Creating Columns",id:"creating-columns",level:3},{value:"Available Column Types",id:"available-column-types",level:3},{value:"bigIncrements()",id:"column-method-bigIncrements",level:4},{value:"bigInteger()",id:"column-method-bigInteger",level:4},{value:"binary()",id:"column-method-binary",level:4},{value:"boolean()",id:"column-method-boolean",level:4},{value:"Char()",id:"column-method-Char",level:4},{value:"date()",id:"column-method-date",level:4},{value:"datetime()",id:"column-method-datetime",level:4},{value:"datetimes()",id:"column-method-datetimes",level:4},{value:"datetimeTz()",id:"column-method-datetimeTz",level:4},{value:"decimal()",id:"column-method-decimal",level:4},{value:"Double()",id:"column-method-Double",level:4},{value:"Enum()",id:"column-method-Enum",level:4},{value:"Float()",id:"column-method-Float",level:4},{value:"foreignId()",id:"column-method-foreignId",level:4},{value:"foreignIdFor()",id:"column-method-foreignIdFor",level:4},{value:"foreignUuid()",id:"column-method-foreignUuid",level:4},{value:"geometry()",id:"column-method-geometry",level:4},{value:"geometryCollection()",id:"column-method-geometryCollection",level:4},{value:"id()",id:"column-method-id",level:4},{value:"increments()",id:"column-method-increments",level:4},{value:"integer()",id:"column-method-integer",level:4},{value:"ipAddress()",id:"column-method-ipAddress",level:4},{value:"json()",id:"column-method-json",level:4},{value:"jsonb()",id:"column-method-jsonb",level:4},{value:"lineString()",id:"column-method-lineString",level:4},{value:"longText()",id:"column-method-longText",level:4},{value:"macAddress()",id:"column-method-macAddress",level:4},{value:"mediumIncrements()",id:"column-method-mediumIncrements",level:4},{value:"mediumInteger()",id:"column-method-mediumInteger",level:4},{value:"mediumText()",id:"column-method-mediumText",level:4},{value:"multiLineString()",id:"column-method-multiLineString",level:4},{value:"multiPoint()",id:"column-method-multiPoint",level:4},{value:"multiPolygon()",id:"column-method-multiPolygon",level:4},{value:"point()",id:"column-method-point",level:4},{value:"polygon()",id:"column-method-polygon",level:4},{value:"rememberToken()",id:"column-method-rememberToken",level:4},{value:"set()",id:"column-method-set",level:4},{value:"smallIncrements()",id:"column-method-smallIncrements",level:4},{value:"smallInteger()",id:"column-method-smallInteger",level:4},{value:"softDeletes()",id:"column-method-softDeletes",level:4},{value:"softDeletesDatetime()",id:"column-method-softDeletesDatetime",level:4},{value:"softDeletesTz()",id:"column-method-softDeletesTz",level:4},{value:"string()",id:"column-method-string",level:4},{value:"text()",id:"column-method-text",level:4},{value:"time()",id:"column-method-time",level:4},{value:"timeTz()",id:"column-method-timeTz",level:4},{value:"timestamp()",id:"column-method-timestamp",level:4},{value:"timestampTz()",id:"column-method-timestampTz",level:4},{value:"timestampsTz()",id:"column-method-timestampsTz",level:4},{value:"timestamps()",id:"column-method-timestamps",level:4},{value:"tinyIncrements()",id:"column-method-tinyIncrements",level:4},{value:"tinyInteger()",id:"column-method-tinyInteger",level:4},{value:"tinyText()",id:"column-method-tinyText",level:4},{value:"unsignedBigInteger()",id:"column-method-unsignedBigInteger",level:4},{value:"unsignedDecimal()",id:"column-method-unsignedDecimal",level:4},{value:"unsignedInteger()",id:"column-method-unsignedInteger",level:4},{value:"unsignedMediumInteger()",id:"column-method-unsignedMediumInteger",level:4},{value:"unsignedSmallInteger()",id:"column-method-unsignedSmallInteger",level:4},{value:"unsignedTinyInteger()",id:"column-method-unsignedTinyInteger",level:4},{value:"uuid()",id:"column-method-uuid",level:4},{value:"year()",id:"column-method-year",level:4},{value:"Column Modifiers",id:"column-modifiers",level:3},{value:"Default Expressions",id:"default-expressions",level:4},{value:"Column Order",id:"column-order",level:4},{value:"Modifying Columns",id:"modifying-columns",level:3},{value:"Renaming Columns",id:"renaming-columns",level:4},{value:"Renaming Columns On Legacy Databases",id:"renaming-columns-on-legacy-databases",level:4},{value:"Dropping Columns",id:"dropping-columns",level:3},{value:"Available Command Aliases",id:"available-command-aliases",level:4},{value:"Indexes",id:"indexes",level:2},{value:"Creating Indexes",id:"creating-indexes",level:3},{value:"Available Index Types",id:"available-index-types",level:4},{value:"Index Lengths & MySQL / MariaDB",id:"index-lengths--mysql--mariadb",level:4},{value:"Renaming Indexes",id:"renaming-indexes",level:3},{value:"Dropping Indexes",id:"dropping-indexes",level:3},{value:"Foreign Key Constraints",id:"foreign-key-constraints",level:3},{value:"Dropping Foreign Keys",id:"dropping-foreign-keys",level:4},{value:"Toggling Foreign Key Constraints",id:"toggling-foreign-key-constraints",level:4}],g={toc:k},N="wrapper";function b(e){let{components:t,...s}=e;return(0,l.kt)(N,(0,a.Z)({},g,s,{components:t,mdxType:"MDXLayout"}),(0,l.kt)("h1",{id:"database-migrations"},"Database: Migrations"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#generating-migrations"},"Generating Migrations")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#tab-completion"},"Tab completion"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#alternative-installation-methods"},"Alternative installation methods")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#migration-structure"},"Migration Structure")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#running-migrations"},"Running Migrations"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#rolling-back-migrations"},"Rolling Back Migrations")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#tables"},"Tables"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#creating-tables"},"Creating Tables")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#updating-tables"},"Updating Tables")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#renaming-and-dropping-tables"},"Renaming / Dropping Tables")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#columns"},"Columns"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#creating-columns"},"Creating Columns")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#available-column-types"},"Available Column Types")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#column-modifiers"},"Column Modifiers")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#modifying-columns"},"Modifying Columns")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#dropping-columns"},"Dropping Columns")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#indexes"},"Indexes"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#creating-indexes"},"Creating Indexes")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#renaming-indexes"},"Renaming Indexes")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#dropping-indexes"},"Dropping Indexes")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#foreign-key-constraints"},"Foreign Key Constraints"))))),(0,l.kt)("h2",{id:"introduction"},"Introduction"),(0,l.kt)("p",null,"Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. If you have ever had to tell a teammate to manually add a column to their local database schema after pulling in your changes from source control, you've faced the problem that database migrations solve."),(0,l.kt)("p",null,"The TinyORM ",(0,l.kt)("inlineCode",{parentName:"p"},"Schema")," facade provides database agnostic support for creating and manipulating tables across all of TinyORM's supported database systems. Typically, migrations will use this facade to create and modify database tables and columns."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," migrations is a small console application that depends on the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. All migrations logic is compiled so recompilation is needed after adding a new migration class."),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("a",{parentName:"p",href:"/database/migrations#tables"},(0,l.kt)("inlineCode",{parentName:"a"},"schema builder"))," and ",(0,l.kt)("a",{parentName:"p",href:"/database/migrations"},(0,l.kt)("inlineCode",{parentName:"a"},"migrations"))," don't support ",(0,l.kt)("a",{parentName:"p",href:"/database/getting-started#multi-threading-support"},"multi-threading"),".")),(0,l.kt)("admonition",{type:"note"},(0,l.kt)("p",{parentName:"admonition"},"TinyORM's schema builder supports all ",(0,l.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"supported databases")," out of the box.")),(0,l.kt)("p",null,"The following image shows what the ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," console application looks like. \u2728 As you can see it offers everything that is needed to generate and manage migrations and seeders and all of this is backed up with the tab completion."),(0,l.kt)("img",{src:n(9566).Z,alt:"TinyORM - Tom console application - Showcase",width:"760",title:"TinyORM - Tom console application - Showcase"}),(0,l.kt)("h2",{id:"generating-migrations"},"Generating Migrations"),(0,l.kt)("p",null,"You may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"make:migration")," ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," command to generate a database migration. The new migration will be placed in your ",(0,l.kt)("inlineCode",{parentName:"p"},"database/migrations")," directory. Each migration filename contains a timestamp that allows ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," to determine the order of the migrations:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:migration create_posts_table\n")),(0,l.kt)("p",null,"tom will use the name of the migration to attempt to guess the name of the table and whether or not the migration will be creating a new table. If ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," is able to determine the table name from the migration name, ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," will pre-fill the generated migration file with the specified table. Otherwise, you may simply specify the table in the migration file manually."),(0,l.kt)("p",null,"If you would like to specify a custom path for the generated migration, you may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"--path")," option when executing the ",(0,l.kt)("inlineCode",{parentName:"p"},"make:migration")," command. The given path should be relative to your ",(0,l.kt)("abbr",{title:"Current working directory"},"pwd")," or you can use the ",(0,l.kt)("inlineCode",{parentName:"p"},"--realpath")," option and pass the absolute path to the ",(0,l.kt)("inlineCode",{parentName:"p"},"--path")," option."),(0,l.kt)("h4",{id:"migrations-naming-rules"},"Migrations naming rules"),(0,l.kt)("p",null,"If the migration name starts with the ",(0,l.kt)("inlineCode",{parentName:"p"},"create_")," string then the stub for table creation will be used and if the migration name contains ",(0,l.kt)("inlineCode",{parentName:"p"},"_(from|to|in)_")," then the stub for table update will be used. You can override these rules using the ",(0,l.kt)("inlineCode",{parentName:"p"},"--create")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"--table")," options and specify the table name manually."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can also pass the full migration filename with the datetime prefix and extension to the ",(0,l.kt)("inlineCode",{parentName:"p"},"make:migration"),". This command is able to detect almost any combination of the passed value, with or without datetime prefix or extension if it is the filename; or StudlyCase, snake_case, or kebab-case if it is the classname or any combination described above. \ud83d\udc40")),(0,l.kt)("h2",{id:"tab-completion"},"Tab completion"),(0,l.kt)("p",null,"Tab completion is available for the ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh")," (on Linux too), ",(0,l.kt)("inlineCode",{parentName:"p"},"bash"),", and ",(0,l.kt)("inlineCode",{parentName:"p"},"zsh")," shells. For ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh")," the ",(0,l.kt)("inlineCode",{parentName:"p"},"tom.exe")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm0.dll")," library must be on the system path to work properly. With ",(0,l.kt)("inlineCode",{parentName:"p"},"bash")," if the ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," executable and ",(0,l.kt)("inlineCode",{parentName:"p"},"libTinyOrm.so")," library is ",(0,l.kt)("strong",{parentName:"p"},"not")," on the system path then it will provide less accurate completions."),(0,l.kt)("p",null,"You can enable it using the following commands."),(0,l.kt)(m.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(r.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},"tom integrate pwsh\n"))),(0,l.kt)(r.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom integrate bash\n"))),(0,l.kt)(r.Z,{value:d.js,label:d.Ae,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom integrate zsh\ntom integrate zsh --path=/usr/share/zsh/site-functions\n")))),(0,l.kt)("p",null,"Or you can enable it manually. Following actions are the same as the ",(0,l.kt)("inlineCode",{parentName:"p"},"tom integrate")," command does."),(0,l.kt)("p",null,"For the ",(0,l.kt)("inlineCode",{parentName:"p"},"pwsh")," paste the following code to the pwsh profile (works on Linux or Windows)."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell",metastring:"title='~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1'",title:"'~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1'"},"Register-ArgumentCompleter -Native -CommandName tom,tom_testdata -ScriptBlock {\n param($wordToComplete, $commandAst, $cursorPosition)\n [Console]::InputEncoding =\n [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()\n $Local:word = $wordToComplete.Replace('\"', '\\\"')\n $Local:ast = $commandAst.ToString().Replace('\"', '\\\"')\n tom complete --word=\"$Local:word\" --commandline=\"$Local:ast\" --position=$cursorPosition\n | ForEach-Object {\n $completionText, $listText, $toolTip = $_ -split ';', 3\n $listText ??= $completionText\n $toolTip ??= $completionText\n [System.Management.Automation.CompletionResult]::new(\n $completionText, $listText, 'ParameterValue', $toolTip)\n }\n}\n")),(0,l.kt)("p",null,"For ",(0,l.kt)("inlineCode",{parentName:"p"},"bash")," you can copy or create symlink of the ",(0,l.kt)("inlineCode",{parentName:"p"},"/tools/completions/tom.bash")," file to the ",(0,l.kt)("inlineCode",{parentName:"p"},"/usr/share/bash-completion/completions")," folder."),(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`sudo ln -s ${(0,p.go)(d.q5)}/TinyORM/tools/completions/tom.bash /usr/share/bash-completion/completions/tom`),(0,l.kt)("p",null,"And for ",(0,l.kt)("inlineCode",{parentName:"p"},"zsh")," you can copy or create symlink of the ",(0,l.kt)("inlineCode",{parentName:"p"},"/tools/completions/tom.zsh")," file to the ",(0,l.kt)("inlineCode",{parentName:"p"},"_tom")," file to ",(0,l.kt)("inlineCode",{parentName:"p"},"/usr/local/share/zsh/site-functions")," folder."),(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`sudo ln -s ${(0,p.go)(d.q5)}/TinyORM/tools/completions/tom.zsh /usr/local/share/zsh/site-functions/_tom`),(0,l.kt)("p",null,"It will provide completions for the ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," commands, long and short parameters, and also for some positional arguments like namespaces for the ",(0,l.kt)("inlineCode",{parentName:"p"},"list")," command or commands for the ",(0,l.kt)("inlineCode",{parentName:"p"},"help")," command."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tom integrate zsh")," command also accepts the ",(0,l.kt)("inlineCode",{parentName:"p"},"--path=")," option with which you can set the location, where the zsh completion file should be created.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can also output the completion script using the ",(0,l.kt)("inlineCode",{parentName:"p"},"--stdout")," option eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"tom integrate bash --stdout"),".")),(0,l.kt)("h3",{id:"alternative-installation-methods"},"Alternative installation methods"),(0,l.kt)("p",null,"This section describes alternative installation methods for ",(0,l.kt)("inlineCode",{parentName:"p"},"bash")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"zsh")," tab completions."),(0,l.kt)("h4",{id:"static-installation"},"Static installation"),(0,l.kt)("p",null,"Idea is to output the tab completion to the file and then source it."),(0,l.kt)(m.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(r.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"mkdir -p ~/.local/share/tom\ntom integrate bash --stdout > ~/.local/share/tom/tom.bash\n\n# Then source this file in the ~/.bashrc\nsource $HOME/.local/share/tom/tom.bash\n"))),(0,l.kt)(r.Z,{value:d.js,label:d.Ae,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"mkdir -p ~/.local/share/tom\ntom integrate zsh --stdout > ~/.local/share/tom/tom.zsh\n\n# Then source this file in the ~/.zshrc\nsource $HOME/.local/share/tom/tom.zsh\ncompdef _tom tom\n")))),(0,l.kt)("h4",{id:"dynamic-installation"},"Dynamic installation"),(0,l.kt)("p",null,"Idea is to ",(0,l.kt)("strong",{parentName:"p"},"avoid")," outputting the tab completion to the file, so you ",(0,l.kt)("inlineCode",{parentName:"p"},"eval")," the tab completion source code right away."),(0,l.kt)(m.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(r.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},'# Add this eval to the ~/.bashrc\neval "$(tom integrate bash --stdout)"\n'))),(0,l.kt)(r.Z,{value:d.js,label:d.Ae,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},'# Add this eval to the ~/.zshrc\neval "$(tom integrate zsh --stdout)"\ncompdef _tom tom\n')))),(0,l.kt)("h2",{id:"migration-structure"},"Migration Structure"),(0,l.kt)("p",null,"A migration class contains two methods: ",(0,l.kt)("inlineCode",{parentName:"p"},"up")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"down"),". The ",(0,l.kt)("inlineCode",{parentName:"p"},"up")," method is used to add new tables, columns, or indexes to your database, while the ",(0,l.kt)("inlineCode",{parentName:"p"},"down")," method should reverse the operations performed by the ",(0,l.kt)("inlineCode",{parentName:"p"},"up")," method."),(0,l.kt)("p",null,"Within both of these methods, you may use the TinyORM schema builder to expressively create and modify tables. To learn about all of the methods available on the ",(0,l.kt)("inlineCode",{parentName:"p"},"Schema")," builder, ",(0,l.kt)("a",{parentName:"p",href:"#creating-tables"},"check out its documentation"),". For example, the following migration creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"posts")," table:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#pragma once\n\n#include \n\nnamespace Migrations\n{\n\n struct CreatePostsTable : Migration\n {\n /*! Filename of the migration file. */\n T_MIGRATION\n\n /*! Run the migrations. */\n void up() const override\n {\n Schema::create("posts", [](Blueprint &table)\n {\n table.id();\n\n table.string(NAME);\n table.timestamps();\n });\n }\n\n /*! Reverse the migrations. */\n void down() const override\n {\n Schema::dropIfExists("posts");\n }\n };\n\n} // namespace Migrations\n')),(0,l.kt)("p",null,'Migration classes can be named in two formats, StudlyCase without the datetime prefix and "snake_case" with the datetime prefix. If the StudlyCase name is used then the ',(0,l.kt)("inlineCode",{parentName:"p"},"T_MIGRATION")," macro must also be used in the migration class."),(0,l.kt)("p",null,"Naming with the datetime prefix should look like this."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"struct _2014_10_12_000000_create_posts_table : Migration\n{\n\n /*! Run the migrations. */\n void up() const override\n {\n //\n }\n\n /*! Reverse the migrations. */\n void down() const override\n {\n //\n }\n};\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The StudlyCase naming is preferred. Also the ",(0,l.kt)("inlineCode",{parentName:"p"},"make:migration")," command generates migrations in this format.")),(0,l.kt)("h4",{id:"setting-the-migration-connection"},"Setting The Migration Connection"),(0,l.kt)("p",null,"If your migration will be interacting with a database connection other than your application's default database connection, you should set the ",(0,l.kt)("inlineCode",{parentName:"p"},"connection")," data member of your migration:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'/*! The name of the database connection to use. */\nQString connection = QStringLiteral("tinyorm_example");\n\n/*! Run the migrations. */\nvoid up() const override\n{\n //\n}\n')),(0,l.kt)("h2",{id:"running-migrations"},"Running Migrations"),(0,l.kt)("p",null,"To run all of your outstanding migrations, execute the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate")," Tom command:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate\n")),(0,l.kt)("p",null,"If you would like to see which migrations have run thus far, you may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:status")," tom command:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:status\n")),(0,l.kt)("p",null,"If you would like to see the SQL statements that will be executed by the migrations without actually running them, you may provide the ",(0,l.kt)("inlineCode",{parentName:"p"},"--pretend")," flag to the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate")," command:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate --pretend\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"Many ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," commands offer variety of options, you can explore them using the ",(0,l.kt)("inlineCode",{parentName:"p"},"tom list")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tom help")," commands. In most cases, these commands and options are self-explanatory.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," command is able to guess the command name and command namespace, eg. ",(0,l.kt)("inlineCode",{parentName:"p"},"tom mig:st")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"tom m:rol"),", ...")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can pass the ",(0,l.kt)("inlineCode",{parentName:"p"},"-vvv")," command-line argument to any command to see all executed SQL queries. \ud83d\udc4c")),(0,l.kt)("admonition",{type:"note"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate")," Tom command internally calls the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:install")," command which installs the migration repository table. To uninstall this repository table you can call the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:uninstall"),".")),(0,l.kt)("h4",{id:"forcing-migrations-to-run-in-production"},"Forcing Migrations To Run In Production"),(0,l.kt)("p",null,"Some migration operations are destructive, which means they may cause you to lose data. In order to protect you from running these commands against your production database, you will be prompted for confirmation before the commands are executed. To force the commands to run without a prompt, use the ",(0,l.kt)("inlineCode",{parentName:"p"},"--force")," flag:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate --force\n")),(0,l.kt)("h3",{id:"rolling-back-migrations"},"Rolling Back Migrations"),(0,l.kt)("p",null,"To roll back the latest migration operation, you may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"rollback"),' Tom command. This command rolls back the last "batch" of migrations, which may include multiple migration files:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:rollback\n")),(0,l.kt)("p",null,"You may roll back a limited number of migrations by providing the ",(0,l.kt)("inlineCode",{parentName:"p"},"step")," option to the ",(0,l.kt)("inlineCode",{parentName:"p"},"rollback")," command. For example, the following command will roll back the last five migrations:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:rollback --step=5\n")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:reset")," command will roll back all of your application's migrations:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:reset\n")),(0,l.kt)("p",null,'You may roll back a specific "batch" of migrations by providing the ',(0,l.kt)("inlineCode",{parentName:"p"},"batch")," option to the ",(0,l.kt)("inlineCode",{parentName:"p"},"rollback")," command, where the ",(0,l.kt)("inlineCode",{parentName:"p"},"batch")," option corresponds to a batch value within your application's ",(0,l.kt)("inlineCode",{parentName:"p"},"migrations")," database table. For example, the following command will roll back all migrations in batch three:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:rollback --batch=3\n")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:reset")," command will roll back all of your application's migrations:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:reset\n")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:uninstall")," command will uninstall the migration repository table, it optionally accepts the ",(0,l.kt)("inlineCode",{parentName:"p"},"--reset")," option to roll back all of your application's migrations:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:uninstall --reset\n")),(0,l.kt)("h4",{id:"roll-back--migrate-using-a-single-command"},"Roll Back & Migrate Using A Single Command"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:refresh")," command will roll back all of your migrations and then execute the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate")," command. This command effectively re-creates your entire database:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:refresh\n")),(0,l.kt)("p",null,"You may roll back and re-migrate a limited number of migrations by providing the ",(0,l.kt)("inlineCode",{parentName:"p"},"step")," option to the ",(0,l.kt)("inlineCode",{parentName:"p"},"refresh")," command. For example, the following command will roll back and re-migrate the last five migrations:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:refresh --step=5\n")),(0,l.kt)("h4",{id:"drop-all-tables--migrate"},"Drop All Tables & Migrate"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:fresh")," command will drop all tables from the database and then execute the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate")," command:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:fresh\n")),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:fresh")," command will drop all database tables regardless of their prefix. This command should be used with caution when developing on a database that is shared with other applications.")),(0,l.kt)("h2",{id:"tables"},"Tables"),(0,l.kt)("h3",{id:"creating-tables"},"Creating Tables"),(0,l.kt)("p",null,"To create a new database table, use the ",(0,l.kt)("inlineCode",{parentName:"p"},"create")," method on the ",(0,l.kt)("inlineCode",{parentName:"p"},"Schema")," facade. The ",(0,l.kt)("inlineCode",{parentName:"p"},"create")," method accepts two arguments: the first is the name of the table, while the second is a lambda expression which receives a ",(0,l.kt)("inlineCode",{parentName:"p"},"Orm::SchemaNs::Blueprint")," object that may be used to define the new table:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Schema;\n\nSchema::create("users", [](Blueprint &table)\n{\n table.id();\n table.string("name");\n table.string("email");\n table.timestamps();\n});\n')),(0,l.kt)("p",null,"When creating the table, you may use any of the schema builder's ",(0,l.kt)("a",{parentName:"p",href:"#creating-columns"},"column methods")," to define the table's columns."),(0,l.kt)("h4",{id:"checking-for-table--column-existence"},"Checking For Table / Column Existence"),(0,l.kt)("p",null,"You may check for the existence of a table or column using the ",(0,l.kt)("inlineCode",{parentName:"p"},"hasTable")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"hasColumn")," methods:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'if (Schema::hasTable("users")) {\n // The "users" table exists...\n}\n\nif (Schema::hasColumn("users", "email")) {\n // The "users" table exists and has an "email" column...\n}\n')),(0,l.kt)("h4",{id:"database-connection--table-options"},"Database Connection & Table Options"),(0,l.kt)("p",null,"If you want to perform a schema operation on a database connection that is not your application's default connection, use the ",(0,l.kt)("inlineCode",{parentName:"p"},"connection")," method or ",(0,l.kt)("inlineCode",{parentName:"p"},"on")," alias:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::connection("postgres").create("users", [](Blueprint &table)\n{\n table.id();\n});\n')),(0,l.kt)("p",null,"In addition, a few other data members and methods may be used to define other aspects of the table's creation. The ",(0,l.kt)("inlineCode",{parentName:"p"},"engine")," data member may be used to specify the table's storage engine when using MySQL:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Constants::InnoDB;\n\nSchema::create("users", [](Blueprint &table)\n{\n table.engine = InnoDB;\n\n // ...\n});\n')),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"charset")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"collation")," data members may be used to specify the character set and collation for the created table when using MySQL:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Constants::UTF8MB4;\n\nSchema::create("users", [](Blueprint &table)\n{\n table.charset = UTF8MB4;\n table.collation = "utf8mb4_unicode_ci";\n\n // ...\n});\n')),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"temporary"),' method may be used to indicate that the table should be "temporary". Temporary tables are only visible to the current connection\'s database session and are dropped automatically when the connection is closed:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::create("calculations", [](Blueprint &table)\n{\n table.temporary();\n\n // ...\n});\n')),(0,l.kt)("p",null,'If you would like to add a "comment" to a database table, you may invoke the ',(0,l.kt)("inlineCode",{parentName:"p"},"comment")," method on the table instance. Table comments are currently only supported by MySQL and PostgreSQL:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::create("calculations", [](Blueprint &table)\n{\n table.comment("Business calculations");\n\n // ...\n});\n')),(0,l.kt)("h3",{id:"updating-tables"},"Updating Tables"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"table")," method on the ",(0,l.kt)("inlineCode",{parentName:"p"},"Schema")," facade may be used to update existing tables. Like the ",(0,l.kt)("inlineCode",{parentName:"p"},"create")," method, the ",(0,l.kt)("inlineCode",{parentName:"p"},"table")," method accepts two arguments: the name of the table and a lambda expression that receives a ",(0,l.kt)("inlineCode",{parentName:"p"},"Blueprint")," instance you may use to add columns or indexes to the table:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.integer("votes");\n});\n')),(0,l.kt)("h3",{id:"renaming-and-dropping-tables"},"Renaming / Dropping Tables"),(0,l.kt)("p",null,"To rename an existing database table, use the ",(0,l.kt)("inlineCode",{parentName:"p"},"rename")," method:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nSchema::rename("from", "to");\n')),(0,l.kt)("p",null,"To drop an existing table, you may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"drop")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"dropIfExists")," methods:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::drop("users");\n\nSchema::dropIfExists("users");\n')),(0,l.kt)("h4",{id:"renaming-tables-with-foreign-keys"},"Renaming Tables With Foreign Keys"),(0,l.kt)("p",null,"Before renaming a table, you should verify that any foreign key constraints on the table have an explicit name in your migration files instead of letting TinyORM assign a convention based name. Otherwise, the foreign key constraint ",(0,l.kt)("strong",{parentName:"p"},"index name")," will refer to the old table name."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"After renaming a table, you can re-create (drop and create again) the foreign key constraints to fix an ",(0,l.kt)("strong",{parentName:"p"},"index name"),", so it refers to a renamed table.")),(0,l.kt)("h2",{id:"columns"},"Columns"),(0,l.kt)("h3",{id:"creating-columns"},"Creating Columns"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"table")," method on the ",(0,l.kt)("inlineCode",{parentName:"p"},"Schema")," facade may be used to update existing tables. Like the ",(0,l.kt)("inlineCode",{parentName:"p"},"create")," method, the ",(0,l.kt)("inlineCode",{parentName:"p"},"table")," method accepts two arguments: the name of the table and a lambda expression that receives a ",(0,l.kt)("inlineCode",{parentName:"p"},"Blueprint")," instance you may use to add columns to the table:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.integer("votes");\n});\n')),(0,l.kt)("h3",{id:"available-column-types"},"Available Column Types"),(0,l.kt)("p",null,"The schema builder blueprint offers a variety of methods that correspond to the different types of columns you can add to your database tables. Each of the available methods are listed in the table below:"),(0,l.kt)("div",{class:"tom-column-types-list"},(0,l.kt)("p",null,(0,l.kt)("a",{parentName:"p",href:"#column-method-bigIncrements"},"bigIncrements"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-bigInteger"},"bigInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-binary"},"binary"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-boolean"},"boolean"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-Char"},"Char"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-date"},"date"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-datetime"},"datetime"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-datetimes"},"datetimes"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-datetimeTz"},"datetimeTz"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-decimal"},"decimal"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-Double"},"Double"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-Enum"},"Enum"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-Float"},"Float"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-foreignId"},"foreignId"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-foreignIdFor"},"foreignIdFor"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-foreignUuid"},"foreignUuid"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-geometry"},"geometry"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-geometryCollection"},"geometryCollection"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-id"},"id"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-increments"},"increments"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-integer"},"integer"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-ipAddress"},"ipAddress"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-json"},"json"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-jsonb"},"jsonb"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-lineString"},"lineString"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-longText"},"longText"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-macAddress"},"macAddress"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-mediumIncrements"},"mediumIncrements"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-mediumInteger"},"mediumInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-mediumText"},"mediumText"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-multiLineString"},"multiLineString"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-multiPoint"},"multiPoint"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-multiPolygon"},"multiPolygon"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-point"},"point"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-polygon"},"polygon"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-rememberToken"},"rememberToken"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-set"},"set"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-smallIncrements"},"smallIncrements"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-smallInteger"},"smallInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-softDeletes"},"softDeletes"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-softDeletesDatetime"},"softDeletesDatetime"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-softDeletesTz"},"softDeletesTz"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-string"},"string"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-text"},"text"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-time"},"time"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-timeTz"},"timeTz"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-timestamp"},"timestamp"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-timestampTz"},"timestampTz"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-timestampsTz"},"timestampsTz"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-timestamps"},"timestamps"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-tinyIncrements"},"tinyIncrements"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-tinyInteger"},"tinyInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-tinyText"},"tinyText"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-unsignedBigInteger"},"unsignedBigInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-unsignedDecimal"},"unsignedDecimal"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-unsignedInteger"},"unsignedInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-unsignedMediumInteger"},"unsignedMediumInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-unsignedSmallInteger"},"unsignedSmallInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-unsignedTinyInteger"},"unsignedTinyInteger"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-uuid"},"uuid"),"\n",(0,l.kt)("a",{parentName:"p",href:"#column-method-year"},"year"))),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"Names of ",(0,l.kt)("inlineCode",{parentName:"p"},"Char"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"Double"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"Enum"),", and ",(0,l.kt)("inlineCode",{parentName:"p"},"Float")," column methods are in the CamelCase format to avoid collisions with C++ keywords.")),(0,l.kt)("div",{class:"tom-column-types"},(0,l.kt)("h4",{id:"column-method-bigIncrements"},(0,l.kt)("inlineCode",{parentName:"h4"},"bigIncrements()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"bigIncrements")," method creates an auto-incrementing ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED BIGINT")," (primary key) equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"#include \n\ntable.bigIncrements(Orm::ID);\n")),(0,l.kt)("h4",{id:"column-method-bigInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"bigInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"bigInteger")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"BIGINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.bigInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-binary"},(0,l.kt)("inlineCode",{parentName:"h4"},"binary()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"binary")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"BLOB")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.binary("photo");\n')),(0,l.kt)("h4",{id:"column-method-boolean"},(0,l.kt)("inlineCode",{parentName:"h4"},"boolean()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"boolean")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"BOOLEAN")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.boolean("confirmed");\n')),(0,l.kt)("h4",{id:"column-method-Char"},(0,l.kt)("inlineCode",{parentName:"h4"},"Char()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Char")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"CHAR")," equivalent column with of a given length:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"#include \n\ntable.Char(Orm::NAME, 100);\n")),(0,l.kt)("h4",{id:"column-method-date"},(0,l.kt)("inlineCode",{parentName:"h4"},"date()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"date")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"DATE")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.date("created_at");\n')),(0,l.kt)("h4",{id:"column-method-datetime"},(0,l.kt)("inlineCode",{parentName:"h4"},"datetime()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"datetime")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"DATETIME")," equivalent column with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.datetime("created_at", precision = 0);\n')),(0,l.kt)("h4",{id:"column-method-datetimes"},(0,l.kt)("inlineCode",{parentName:"h4"},"datetimes()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"datetimes")," method creates ",(0,l.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"updated_at")," ",(0,l.kt)("inlineCode",{parentName:"p"},"DATETIME")," equivalent columns with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"table.datetimes(precision = 0);\n")),(0,l.kt)("h4",{id:"column-method-datetimeTz"},(0,l.kt)("inlineCode",{parentName:"h4"},"datetimeTz()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"datetimeTz")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"DATETIME")," (with timezone) equivalent column with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"#include \n\ntable.datetimeTz(Orm::CREATED_AT, precision = 0);\n")),(0,l.kt)("h4",{id:"column-method-decimal"},(0,l.kt)("inlineCode",{parentName:"h4"},"decimal()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"decimal")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"DECIMAL")," equivalent column with the given precision (total digits) and scale (decimal digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.decimal("amount", precision = 8, scale = 2);\n')),(0,l.kt)("h4",{id:"column-method-Double"},(0,l.kt)("inlineCode",{parentName:"h4"},"Double()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Double")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"DOUBLE")," equivalent column with the given precision (total digits) and scale (decimal digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.Double("amount", 8, 2);\n')),(0,l.kt)("h4",{id:"column-method-Enum"},(0,l.kt)("inlineCode",{parentName:"h4"},"Enum()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Enum")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"ENUM")," equivalent column with the given valid values:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.Enum("difficulty", {"easy", "hard"});\n')),(0,l.kt)("h4",{id:"column-method-Float"},(0,l.kt)("inlineCode",{parentName:"h4"},"Float()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"Float")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"FLOAT")," equivalent column with the given precision (total digits) and scale (decimal digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.Float("amount", 8, 2);\n')),(0,l.kt)("h4",{id:"column-method-foreignId"},(0,l.kt)("inlineCode",{parentName:"h4"},"foreignId()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"foreignId")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED BIGINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.foreignId("user_id");\n')),(0,l.kt)("h4",{id:"column-method-foreignIdFor"},(0,l.kt)("inlineCode",{parentName:"h4"},"foreignIdFor()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"foreignIdFor")," method adds a ",(0,l.kt)("inlineCode",{parentName:"p"},"{column}_id UNSIGNED BIGINT")," equivalent column for a given model class:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include "models/user.hpp"\n\nModels::User user;\n\ntable.foreignIdFor(User);\n')),(0,l.kt)("h4",{id:"column-method-foreignUuid"},(0,l.kt)("inlineCode",{parentName:"h4"},"foreignUuid()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"foreignUuid")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"UUID")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.foreignUuid("user_id");\n')),(0,l.kt)("h4",{id:"column-method-geometry"},(0,l.kt)("inlineCode",{parentName:"h4"},"geometry()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"geometry")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"GEOMETRY")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.geometry("positions");\n')),(0,l.kt)("h4",{id:"column-method-geometryCollection"},(0,l.kt)("inlineCode",{parentName:"h4"},"geometryCollection()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"geometryCollection")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"GEOMETRYCOLLECTION")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.geometryCollection("positions");\n')),(0,l.kt)("h4",{id:"column-method-id"},(0,l.kt)("inlineCode",{parentName:"h4"},"id()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"id")," method is an alias of the ",(0,l.kt)("inlineCode",{parentName:"p"},"bigIncrements")," method. By default, the method will create an ",(0,l.kt)("inlineCode",{parentName:"p"},"id")," column; however, you may pass a column name if you would like to assign a different name to the column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"table.id();\n")),(0,l.kt)("h4",{id:"column-method-increments"},(0,l.kt)("inlineCode",{parentName:"h4"},"increments()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"increments")," method creates an auto-incrementing ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED INTEGER")," equivalent column as a primary key:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.increments("id");\n')),(0,l.kt)("h4",{id:"column-method-integer"},(0,l.kt)("inlineCode",{parentName:"h4"},"integer()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"integer")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"INTEGER")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.integer("votes");\n')),(0,l.kt)("h4",{id:"column-method-ipAddress"},(0,l.kt)("inlineCode",{parentName:"h4"},"ipAddress()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"ipAddress")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"VARCHAR(45)")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.ipAddress("visitor");\n')),(0,l.kt)("h4",{id:"column-method-json"},(0,l.kt)("inlineCode",{parentName:"h4"},"json()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"json")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"JSON")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.json("options");\n')),(0,l.kt)("h4",{id:"column-method-jsonb"},(0,l.kt)("inlineCode",{parentName:"h4"},"jsonb()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"jsonb")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"JSONB")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.jsonb("options");\n')),(0,l.kt)("h4",{id:"column-method-lineString"},(0,l.kt)("inlineCode",{parentName:"h4"},"lineString()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"lineString")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"LINESTRING")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.lineString("positions");\n')),(0,l.kt)("h4",{id:"column-method-longText"},(0,l.kt)("inlineCode",{parentName:"h4"},"longText()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"longText")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"LONGTEXT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.longText("description");\n')),(0,l.kt)("h4",{id:"column-method-macAddress"},(0,l.kt)("inlineCode",{parentName:"h4"},"macAddress()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"macAddress")," method creates a column that is intended to hold a MAC address. Some database systems, such as PostgreSQL, have a dedicated column type for this type of data. Other database systems will use a string equivalent ",(0,l.kt)("inlineCode",{parentName:"p"},"VARCHAR(17)")," column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.macAddress("device");\n')),(0,l.kt)("h4",{id:"column-method-mediumIncrements"},(0,l.kt)("inlineCode",{parentName:"h4"},"mediumIncrements()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"mediumIncrements")," method creates an auto-incrementing ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED MEDIUMINT")," equivalent column as a primary key:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.mediumIncrements("id");\n')),(0,l.kt)("h4",{id:"column-method-mediumInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"mediumInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"mediumInteger")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"MEDIUMINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.mediumInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-mediumText"},(0,l.kt)("inlineCode",{parentName:"h4"},"mediumText()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"mediumText")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"MEDIUMTEXT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.mediumText("description");\n')),(0,l.kt)("h4",{id:"column-method-multiLineString"},(0,l.kt)("inlineCode",{parentName:"h4"},"multiLineString()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"multiLineString")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"MULTILINESTRING")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.multiLineString("positions");\n')),(0,l.kt)("h4",{id:"column-method-multiPoint"},(0,l.kt)("inlineCode",{parentName:"h4"},"multiPoint()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"multiPoint")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"MULTIPOINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.multiPoint("positions");\n')),(0,l.kt)("h4",{id:"column-method-multiPolygon"},(0,l.kt)("inlineCode",{parentName:"h4"},"multiPolygon()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"multiPolygon")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"MULTIPOLYGON")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.multiPolygon("positions");\n')),(0,l.kt)("h4",{id:"column-method-point"},(0,l.kt)("inlineCode",{parentName:"h4"},"point()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"point")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"POINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.point("position");\n')),(0,l.kt)("h4",{id:"column-method-polygon"},(0,l.kt)("inlineCode",{parentName:"h4"},"polygon()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"polygon")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"POLYGON")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.polygon("position");\n')),(0,l.kt)("h4",{id:"column-method-rememberToken"},(0,l.kt)("inlineCode",{parentName:"h4"},"rememberToken()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"rememberToken")," method creates a nullable, ",(0,l.kt)("inlineCode",{parentName:"p"},"VARCHAR(100)"),' equivalent column that is intended to store the current "remember me" authentication token:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"table.rememberToken();\n")),(0,l.kt)("h4",{id:"column-method-set"},(0,l.kt)("inlineCode",{parentName:"h4"},"set()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"set")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"SET")," equivalent column with the given list of valid values:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.set("flavors", {"strawberry", "vanilla"});\n')),(0,l.kt)("h4",{id:"column-method-smallIncrements"},(0,l.kt)("inlineCode",{parentName:"h4"},"smallIncrements()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"smallIncrements")," method creates an auto-incrementing ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED SMALLINT")," equivalent column as a primary key:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.smallIncrements("id");\n')),(0,l.kt)("h4",{id:"column-method-smallInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"smallInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"smallInteger")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"SMALLINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.smallInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-softDeletes"},(0,l.kt)("inlineCode",{parentName:"h4"},"softDeletes()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"softDeletes")," method adds a nullable ",(0,l.kt)("inlineCode",{parentName:"p"},"deleted_at")," ",(0,l.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," equivalent column with an optional precision (total digits). This column is intended to store the ",(0,l.kt)("inlineCode",{parentName:"p"},"deleted_at"),' timestamp needed for TinyORM\'s "soft delete" functionality:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.softDeletes("deleted_at", precision = 0);\n')),(0,l.kt)("h4",{id:"column-method-softDeletesDatetime"},(0,l.kt)("inlineCode",{parentName:"h4"},"softDeletesDatetime()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"softDeletesDatetime")," method adds a nullable ",(0,l.kt)("inlineCode",{parentName:"p"},"deleted_at")," ",(0,l.kt)("inlineCode",{parentName:"p"},"DATETIME")," equivalent column with an optional precision (total digits). This column is intended to store the ",(0,l.kt)("inlineCode",{parentName:"p"},"deleted_at"),' timestamp needed for TinyORM\'s "soft delete" functionality:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.softDeletesDatetime("deleted_at", precision = 0);\n')),(0,l.kt)("h4",{id:"column-method-softDeletesTz"},(0,l.kt)("inlineCode",{parentName:"h4"},"softDeletesTz()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"softDeletesTz")," method adds a nullable ",(0,l.kt)("inlineCode",{parentName:"p"},"deleted_at")," ",(0,l.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," (with timezone) equivalent column with an optional precision (total digits). This column is intended to store the ",(0,l.kt)("inlineCode",{parentName:"p"},"deleted_at"),' timestamp needed for TinyORM\'s "soft delete" functionality:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.softDeletesTz("deleted_at", precision = 0);\n')),(0,l.kt)("h4",{id:"column-method-string"},(0,l.kt)("inlineCode",{parentName:"h4"},"string()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"string")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"VARCHAR")," equivalent column of the given length:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"#include \n\ntable.string(Orm::NAME, 100);\n")),(0,l.kt)("h4",{id:"column-method-text"},(0,l.kt)("inlineCode",{parentName:"h4"},"text()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"text")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"TEXT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.text("description");\n')),(0,l.kt)("h4",{id:"column-method-time"},(0,l.kt)("inlineCode",{parentName:"h4"},"time()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"time")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"TIME")," equivalent column with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.time("sunrise", precision = 0);\n')),(0,l.kt)("h4",{id:"column-method-timeTz"},(0,l.kt)("inlineCode",{parentName:"h4"},"timeTz()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"timeTz")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"TIME")," (with timezone) equivalent column with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.timeTz("sunrise", precision = 0);\n')),(0,l.kt)("h4",{id:"column-method-timestamp"},(0,l.kt)("inlineCode",{parentName:"h4"},"timestamp()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"timestamp")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," equivalent column with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.timestamp("added_at", precision = 0);\n')),(0,l.kt)("h4",{id:"column-method-timestampTz"},(0,l.kt)("inlineCode",{parentName:"h4"},"timestampTz()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"timestampTz")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," (with timezone) equivalent column with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.timestampTz("added_at", precision = 0);\n')),(0,l.kt)("h4",{id:"column-method-timestampsTz"},(0,l.kt)("inlineCode",{parentName:"h4"},"timestampsTz()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"timestampsTz")," method creates ",(0,l.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"updated_at")," ",(0,l.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," (with timezone) equivalent columns with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"table.timestampsTz(precision = 0);\n")),(0,l.kt)("h4",{id:"column-method-timestamps"},(0,l.kt)("inlineCode",{parentName:"h4"},"timestamps()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"timestamps")," method creates ",(0,l.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"updated_at")," ",(0,l.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," equivalent columns with an optional precision (total digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"table.timestamps(precision = 0);\n")),(0,l.kt)("h4",{id:"column-method-tinyIncrements"},(0,l.kt)("inlineCode",{parentName:"h4"},"tinyIncrements()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tinyIncrements")," method creates an auto-incrementing ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED TINYINT")," equivalent column as a primary key:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.tinyIncrements("id");\n')),(0,l.kt)("h4",{id:"column-method-tinyInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"tinyInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tinyInteger")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.tinyInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-tinyText"},(0,l.kt)("inlineCode",{parentName:"h4"},"tinyText()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"tinyText")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYTEXT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.tinyText("notes");\n')),(0,l.kt)("h4",{id:"column-method-unsignedBigInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"unsignedBigInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"unsignedBigInteger")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED BIGINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.unsignedBigInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-unsignedDecimal"},(0,l.kt)("inlineCode",{parentName:"h4"},"unsignedDecimal()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"unsignedDecimal")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED DECIMAL")," equivalent column with an optional precision (total digits) and scale (decimal digits):"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.unsignedDecimal("amount", precision = 8, scale = 2);\n')),(0,l.kt)("h4",{id:"column-method-unsignedInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"unsignedInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"unsignedInteger")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED INTEGER")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.unsignedInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-unsignedMediumInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"unsignedMediumInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"unsignedMediumInteger")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED MEDIUMINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.unsignedMediumInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-unsignedSmallInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"unsignedSmallInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"unsignedSmallInteger")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED SMALLINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.unsignedSmallInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-unsignedTinyInteger"},(0,l.kt)("inlineCode",{parentName:"h4"},"unsignedTinyInteger()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"unsignedTinyInteger")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED TINYINT")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.unsignedTinyInteger("votes");\n')),(0,l.kt)("h4",{id:"column-method-uuid"},(0,l.kt)("inlineCode",{parentName:"h4"},"uuid()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"uuid")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"UUID")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.uuid("id");\n')),(0,l.kt)("h4",{id:"column-method-year"},(0,l.kt)("inlineCode",{parentName:"h4"},"year()")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"year")," method creates a ",(0,l.kt)("inlineCode",{parentName:"p"},"YEAR")," equivalent column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.year("birth_year");\n'))),(0,l.kt)("h3",{id:"column-modifiers"},"Column Modifiers"),(0,l.kt)("p",null,'In addition to the column types listed above, there are several column "modifiers" you may use when adding a column to a database table. For example, to make the column "nullable", you may use the ',(0,l.kt)("inlineCode",{parentName:"p"},"nullable")," method:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.string("email").nullable();\n});\n')),(0,l.kt)("p",null,"The following table contains all of the available column modifiers. This list does not include ",(0,l.kt)("a",{parentName:"p",href:"#creating-indexes"},"index modifiers"),":"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Modifier"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'.after("column")')),(0,l.kt)("td",{parentName:"tr",align:null},'Place the column "after" another column ',(0,l.kt)("small",null,"(MySQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".autoIncrement()")),(0,l.kt)("td",{parentName:"tr",align:null},"Set INTEGER columns as auto-incrementing (primary key).")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'.charset("utf8mb4")')),(0,l.kt)("td",{parentName:"tr",align:null},"Specify a character set for the column ",(0,l.kt)("small",null,"(MySQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("small",null,(0,l.kt)("inlineCode",{parentName:"td"},'.collation("utf8mb4_unicode_ci")'))),(0,l.kt)("td",{parentName:"tr",align:null},"Specify a collation for the column ",(0,l.kt)("small",null,"(MySQL/PostgreSQL/SQL Server)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'.comment("my comment")')),(0,l.kt)("td",{parentName:"tr",align:null},"Add a comment to a column ",(0,l.kt)("small",null,"(MySQL / PostgreSQL)"),".",(0,l.kt)("br",null),(0,l.kt)("small",null,"Special characters are escaped."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".defaultValue(value)")),(0,l.kt)("td",{parentName:"tr",align:null},'Specify a "default" value for the column.',(0,l.kt)("br",null),(0,l.kt)("small",null,"Special characters are escaped."))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".first()")),(0,l.kt)("td",{parentName:"tr",align:null},'Place the column "first" in the table ',(0,l.kt)("small",null,"(MySQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".from(integer)")),(0,l.kt)("td",{parentName:"tr",align:null},"Set the starting value of an auto-incrementing field, an alias for ",(0,l.kt)("inlineCode",{parentName:"td"},"startingValue()")," ",(0,l.kt)("small",null,"(MySQL / PostgreSQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".invisible()")),(0,l.kt)("td",{parentName:"tr",align:null},'Make the column "invisible" to ',(0,l.kt)("inlineCode",{parentName:"td"},"SELECT *")," queries ",(0,l.kt)("small",null,"(MySQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".nullable(value = true)")),(0,l.kt)("td",{parentName:"tr",align:null},"Allow NULL values to be inserted into the column.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".startingValue(integer)")),(0,l.kt)("td",{parentName:"tr",align:null},"Set the starting value of an auto-incrementing field ",(0,l.kt)("small",null,"(MySQL / PostgreSQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".storedAs(expression)")),(0,l.kt)("td",{parentName:"tr",align:null},"Create a stored generated column ",(0,l.kt)("small",null,"(MySQL / PostgreSQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".unsigned()")),(0,l.kt)("td",{parentName:"tr",align:null},"Set INTEGER columns as UNSIGNED ",(0,l.kt)("small",null,"(MySQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".useCurrent()")),(0,l.kt)("td",{parentName:"tr",align:null},"Set TIMESTAMP columns to use CURRENT_TIMESTAMP as default value.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".useCurrentOnUpdate()")),(0,l.kt)("td",{parentName:"tr",align:null},"Set TIMESTAMP columns to use CURRENT_TIMESTAMP when a record is updated.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".virtualAs(expression)")),(0,l.kt)("td",{parentName:"tr",align:null},"Create a virtual generated column ",(0,l.kt)("small",null,"(MySQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".generatedAs(expression)")),(0,l.kt)("td",{parentName:"tr",align:null},"Create an identity column with specified sequence options ",(0,l.kt)("small",null,"(PostgreSQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".always()")),(0,l.kt)("td",{parentName:"tr",align:null},"Defines the precedence of sequence values over input for an identity column ",(0,l.kt)("small",null,"(PostgreSQL)"),".")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},".isGeometry()")),(0,l.kt)("td",{parentName:"tr",align:null},"Set spatial column type to ",(0,l.kt)("inlineCode",{parentName:"td"},"geometry")," - the default type is ",(0,l.kt)("inlineCode",{parentName:"td"},"geography")," ",(0,l.kt)("small",null,"(PostgreSQL)"),".")))),(0,l.kt)("h4",{id:"default-expressions"},"Default Expressions"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"defaultValue")," modifier accepts a value or an ",(0,l.kt)("inlineCode",{parentName:"p"},"Orm::Query::Expression")," instance. Using an ",(0,l.kt)("inlineCode",{parentName:"p"},"Expression")," instance will prevent TinyORM from wrapping the value in quotes and allow you to use database-specific functions. One situation where this is particularly useful is when you need to assign default values to JSON columns:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Query::Expression;\n\nSchema::create("flights", [](Blueprint &table)\n{\n table.id();\n table.json("detail").defaultValue(Expression("(JSON_ARRAY(\'none\'))"));\n table.timestamps();\n});\n')),(0,l.kt)("admonition",{type:"note"},(0,l.kt)("p",{parentName:"admonition"},"Support for default expressions depends on your database driver, database version, and the field type. Please refer to your database's documentation.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can obtain an ",(0,l.kt)("inlineCode",{parentName:"p"},"Orm::Query::Expression")," using the ",(0,l.kt)("a",{parentName:"p",href:"/database/query-builder#raw-expressions"},(0,l.kt)("inlineCode",{parentName:"a"},"DB::raw"))," method if you have access to the ",(0,l.kt)("inlineCode",{parentName:"p"},"DB")," facade.")),(0,l.kt)("h4",{id:"column-order"},"Column Order"),(0,l.kt)("p",null,"When using the MySQL database, the ",(0,l.kt)("inlineCode",{parentName:"p"},"after")," method may be used to add columns after an existing column in the schema:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.after("password", [](Blueprint &table)\n{\n table.string("address_line1");\n table.string("address_line2");\n table.string("city");\n});\n')),(0,l.kt)("h3",{id:"modifying-columns"},"Modifying Columns"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"change")," method allows you to modify the type and attributes of existing columns. For example, you may wish to increase the size of a ",(0,l.kt)("inlineCode",{parentName:"p"},"string")," column. To see the ",(0,l.kt)("inlineCode",{parentName:"p"},"change")," method in action, let's increase the size of the ",(0,l.kt)("inlineCode",{parentName:"p"},"name")," column from 25 to 50. To accomplish this, we simply define the new state of the column and then call the ",(0,l.kt)("inlineCode",{parentName:"p"},"change")," method:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.string("name", 50).change();\n});\n')),(0,l.kt)("p",null,"When modifying a column, you must explicitly include all of the modifiers you want to keep on the column definition - any missing attribute will be dropped. For example, to retain the ",(0,l.kt)("inlineCode",{parentName:"p"},"unsigned"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"default"),", and ",(0,l.kt)("inlineCode",{parentName:"p"},"comment")," attributes, you must call each modifier explicitly when changing the column:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::table("users", [](Blueprint &table)\n{\n table.integer("votes").isUnsigned().defaultValue(1).comment("my comment").change();\n});\n')),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"change")," method and modifying columns is not implemented for the ",(0,l.kt)("inlineCode",{parentName:"p"},"SQLite")," database because it doesn't support modifying columns out of the box.")),(0,l.kt)("h4",{id:"renaming-columns"},"Renaming Columns"),(0,l.kt)("p",null,"To rename a column, you may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"renameColumn")," method provided by the schema builder blueprint:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::table("users", [](Blueprint &table)\n{\n table.renameColumn("from", "to");\n});\n')),(0,l.kt)("h4",{id:"renaming-columns-on-legacy-databases"},"Renaming Columns On Legacy Databases"),(0,l.kt)("p",null,"Renaming columns is not supported if you are running a database installation older than one of the following releases:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"MySQL ",(0,l.kt)("inlineCode",{parentName:"li"},"<8.0.3")),(0,l.kt)("li",{parentName:"ul"},"MariaDB ",(0,l.kt)("inlineCode",{parentName:"li"},"<10.5.2")),(0,l.kt)("li",{parentName:"ul"},"SQLite ",(0,l.kt)("inlineCode",{parentName:"li"},"<3.25.0"))),(0,l.kt)("h3",{id:"dropping-columns"},"Dropping Columns"),(0,l.kt)("p",null,"To drop a column, you may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"dropColumn")," method on the schema builder blueprint:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::table("users", [](Blueprint &table)\n{\n table.dropColumn("votes");\n});\n')),(0,l.kt)("p",null,"You may drop multiple columns from a table by passing a ",(0,l.kt)("inlineCode",{parentName:"p"},"QVector")," of column names to the ",(0,l.kt)("inlineCode",{parentName:"p"},"dropColumns")," method, the ",(0,l.kt)("inlineCode",{parentName:"p"},"dropColumns")," method also provides parameter pack overload:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::table("users", [](Blueprint &table)\n{\n table.dropColumns({"votes", "avatar", "location"});\n // Parameter pack overload\n table.dropColumns("votes", "avatar", "location");\n});\n')),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The SQLite prior to ",(0,l.kt)("inlineCode",{parentName:"p"},"v3.35.0")," doesn't support dropping columns using the ",(0,l.kt)("inlineCode",{parentName:"p"},"ALTER TABLE DROP COLUMN"),", dropping columns was added in the SQLite ",(0,l.kt)("inlineCode",{parentName:"p"},"v3.35.0")," as is described in the ",(0,l.kt)("a",{parentName:"p",href:"https://www.sqlite.org/releaselog/3_35_0.html"},"release notes"),".")),(0,l.kt)("h4",{id:"available-command-aliases"},"Available Command Aliases"),(0,l.kt)("p",null,"TinyORM provides several convenient methods related to dropping common types of columns. Each of these methods is described in the table below:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Command"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.dropRememberToken();")),(0,l.kt)("td",{parentName:"tr",align:null},"Drop the ",(0,l.kt)("inlineCode",{parentName:"td"},"remember_token")," column.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.dropSoftDeletes();")),(0,l.kt)("td",{parentName:"tr",align:null},"Drop the ",(0,l.kt)("inlineCode",{parentName:"td"},"deleted_at")," column.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.dropSoftDeletesDatetime();")),(0,l.kt)("td",{parentName:"tr",align:null},"Alias of ",(0,l.kt)("inlineCode",{parentName:"td"},"dropSoftDeletes()")," method.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.dropSoftDeletesTz();")),(0,l.kt)("td",{parentName:"tr",align:null},"Alias of ",(0,l.kt)("inlineCode",{parentName:"td"},"dropSoftDeletes()")," method.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.dropTimestamps();")),(0,l.kt)("td",{parentName:"tr",align:null},"Drop the ",(0,l.kt)("inlineCode",{parentName:"td"},"created_at")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"updated_at")," columns.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.dropTimestampsTz();")),(0,l.kt)("td",{parentName:"tr",align:null},"Alias of ",(0,l.kt)("inlineCode",{parentName:"td"},"dropTimestamps()")," method.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.dropDatetimes();")),(0,l.kt)("td",{parentName:"tr",align:null},"Alias of ",(0,l.kt)("inlineCode",{parentName:"td"},"dropTimestamps()")," method.")))),(0,l.kt)("h2",{id:"indexes"},"Indexes"),(0,l.kt)("h3",{id:"creating-indexes"},"Creating Indexes"),(0,l.kt)("p",null,"The TinyORM schema builder supports several types of indexes. The following example creates a new ",(0,l.kt)("inlineCode",{parentName:"p"},"email")," column and specifies that its values should be unique. To create the index, we can chain the ",(0,l.kt)("inlineCode",{parentName:"p"},"unique")," method onto the column definition:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.string("email").unique();\n});\n')),(0,l.kt)("p",null,"Alternatively, you may create the index after defining the column. To do so, you should call the ",(0,l.kt)("inlineCode",{parentName:"p"},"unique")," method on the schema builder blueprint. This method accepts the name of the column that should receive a unique index:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.unique("email");\n')),(0,l.kt)("p",null,"You may even pass a ",(0,l.kt)("inlineCode",{parentName:"p"},"QVector")," of columns to an index method to create a compound (or composite) index:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.index({"account_id", "created_at"});\n')),(0,l.kt)("p",null,"When creating an index, TinyORM will automatically generate an index name based on the table, column names, and the index type (eg. users_email_unique), but you may pass a second argument to the method to specify the index name yourself:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.unique("email", "unique_email");\n')),(0,l.kt)("h4",{id:"available-index-types"},"Available Index Types"),(0,l.kt)("p",null,"TinyORM's schema builder blueprint class provides methods for creating each type of index supported by TinyORM. Each index method accepts an optional second argument to specify the name of the index. If omitted, the name will be derived from the names of the table and column(s) used for the index, as well as the index type (eg. users_email_fulltext). Each of the available index methods is described in the table below:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Command"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.primary("id");')),(0,l.kt)("td",{parentName:"tr",align:null},"Adds a primary key.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.primary({"id", "parent_id"});')),(0,l.kt)("td",{parentName:"tr",align:null},"Adds composite keys.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.unique("email");')),(0,l.kt)("td",{parentName:"tr",align:null},"Adds a unique index.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.index("state");')),(0,l.kt)("td",{parentName:"tr",align:null},"Adds an index.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.fullText("body");')),(0,l.kt)("td",{parentName:"tr",align:null},"Adds a full text index (MySQL/PostgreSQL).")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("small",null,(0,l.kt)("inlineCode",{parentName:"td"},'table.fullText("body").language("english");'))),(0,l.kt)("td",{parentName:"tr",align:null},"Adds a full text index of the specified language (PostgreSQL).")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.spatialIndex("location");')),(0,l.kt)("td",{parentName:"tr",align:null},"Adds a spatial index (except SQLite).")))),(0,l.kt)("h4",{id:"index-lengths--mysql--mariadb"},"Index Lengths & MySQL / MariaDB"),(0,l.kt)("p",null,"By default, TinyORM uses the ",(0,l.kt)("inlineCode",{parentName:"p"},"utf8mb4")," character set. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure the default string length by calling the ",(0,l.kt)("inlineCode",{parentName:"p"},"Schema::defaultStringLength")," method:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"#include \n\nSchema::defaultStringLength(191);\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"Alternatively, you may enable the ",(0,l.kt)("inlineCode",{parentName:"p"},"innodb_large_prefix")," option for your database (enabled by default in >=MySQL 5.7.7). Refer to your database's documentation for instructions on how to properly enable this option.")),(0,l.kt)("h3",{id:"renaming-indexes"},"Renaming Indexes"),(0,l.kt)("p",null,"To rename an index, you may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"renameIndex")," method provided by the schema builder blueprint. This method accepts the current index name as its first argument and the desired name as its second argument:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.renameIndex("from", "to");\n')),(0,l.kt)("h3",{id:"dropping-indexes"},"Dropping Indexes"),(0,l.kt)("p",null,"To drop an index, you must specify the index's name. By default, TinyORM automatically assigns an index name based on the table name, the name of the indexed column, and the index type (eg. users_email_unique). Here are some examples:"),(0,l.kt)("div",{id:"apitable-dropping-indexes"},(0,l.kt)(i.Z,{mdxType:"APITable"},(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Command"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.dropPrimary("users_id_primary");')),(0,l.kt)("td",{parentName:"tr",align:null},'Drop a primary key from the "users" table.')),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.dropUnique("users_email_unique");')),(0,l.kt)("td",{parentName:"tr",align:null},'Drop a unique index from the "users" table.')),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'table.dropIndex("geo_state_index");')),(0,l.kt)("td",{parentName:"tr",align:null},'Drop a basic index from the "geo" table.')),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("small",null,(0,l.kt)("inlineCode",{parentName:"td"},'table.dropFullText("posts_body_fulltext");'))),(0,l.kt)("td",{parentName:"tr",align:null},'Drop a full text index from the "posts" table.')),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("small",null,(0,l.kt)("inlineCode",{parentName:"td"},'.dropSpatialIndex("geo_location_spatialindex");'))),(0,l.kt)("td",{parentName:"tr",align:null},'Drop a spatial index from the "geo" table (except SQLite).')))))),(0,l.kt)("p",null,"I may also drop indexes by a column name or column names for composite keys, if you pass a ",(0,l.kt)("inlineCode",{parentName:"p"},"QVector")," of columns into a method that drops indexes, the conventional index name will be generated based on the table name, columns, and index type:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::table("geo", [](Blueprint &table)\n{\n table.dropIndex({"state"}); // Drops index \'geo_state_index\'\n});\n')),(0,l.kt)("h3",{id:"foreign-key-constraints"},"Foreign Key Constraints"),(0,l.kt)("p",null,"TinyORM also provides support for creating foreign key constraints, which are used to force referential integrity at the database level. For example, let's define a ",(0,l.kt)("inlineCode",{parentName:"p"},"user_id")," column on the ",(0,l.kt)("inlineCode",{parentName:"p"},"posts")," table that references the ",(0,l.kt)("inlineCode",{parentName:"p"},"id")," column on a ",(0,l.kt)("inlineCode",{parentName:"p"},"users")," table:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Constants::ID;\n\nSchema::table("posts", [](Blueprint &table)\n{\n table.unsignedBigInteger("user_id");\n\n table.foreign("user_id").references(ID).on("users");\n});\n')),(0,l.kt)("p",null,"Since this syntax is rather verbose, TinyORM provides additional, terser methods that use conventions to provide a better developer experience. When using the ",(0,l.kt)("inlineCode",{parentName:"p"},"foreignId")," method to create your column, the example above can be rewritten like so:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::table("posts", [](Blueprint &table)\n{\n table.foreignId("user_id").constrained();\n});\n')),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"foreignId")," method creates an ",(0,l.kt)("inlineCode",{parentName:"p"},"UNSIGNED BIGINT")," equivalent column, while the ",(0,l.kt)("inlineCode",{parentName:"p"},"constrained")," method will use conventions to determine the table and column name being referenced. If your table name does not match TinyORM's conventions, you may specify the table name by passing it as an argument to the ",(0,l.kt)("inlineCode",{parentName:"p"},"constrained")," method:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'Schema::table("posts", [](Blueprint &table)\n{\n table.foreignId("user_id").constrained("users");\n});\n')),(0,l.kt)("p",null,'You may also specify the desired action for the "on delete" and "on update" properties of the constraint:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::SchemaNs::Constants::Cascade;\n\ntable.foreignId("user_id")\n .constrained()\n .onUpdate("cascade")\n .onDelete(Cascade);\n')),(0,l.kt)("p",null,"An alternative, expressive syntax is also provided for these actions:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Method"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.cascadeOnUpdate();")),(0,l.kt)("td",{parentName:"tr",align:null},"Updates should cascade.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.restrictOnUpdate();")),(0,l.kt)("td",{parentName:"tr",align:null},"Updates should be restricted.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.cascadeOnDelete();")),(0,l.kt)("td",{parentName:"tr",align:null},"Deletes should cascade.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.restrictOnDelete();")),(0,l.kt)("td",{parentName:"tr",align:null},"Deletes should be restricted.")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"table.nullOnDelete();")),(0,l.kt)("td",{parentName:"tr",align:null},"Deletes should set the foreign key value to null.")))),(0,l.kt)("p",null,"Any additional ",(0,l.kt)("a",{parentName:"p",href:"#column-modifiers"},"column modifiers")," must be called before the ",(0,l.kt)("inlineCode",{parentName:"p"},"constrained")," method:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.foreignId("user_id")\n .nullable()\n .constrained();\n')),(0,l.kt)("h4",{id:"dropping-foreign-keys"},"Dropping Foreign Keys"),(0,l.kt)("p",null,"To drop a foreign key, you may use the ",(0,l.kt)("inlineCode",{parentName:"p"},"dropForeign"),' method, passing the name of the foreign key constraint to be deleted as an argument. Foreign key constraints use the same naming convention as indexes. In other words, the foreign key constraint name is based on the name of the table and the columns in the constraint, followed by a "_foreign" suffix:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.dropForeign("posts_user_id_foreign");\n')),(0,l.kt)("p",null,"Alternatively, you may pass a ",(0,l.kt)("inlineCode",{parentName:"p"},"QVector")," containing the column name that holds the foreign key to the ",(0,l.kt)("inlineCode",{parentName:"p"},"dropForeign")," method. The ",(0,l.kt)("inlineCode",{parentName:"p"},"QVector")," will be converted to a foreign key constraint name using TinyORM's constraint naming conventions:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},'table.dropForeign({"user_id"});\n')),(0,l.kt)("h4",{id:"toggling-foreign-key-constraints"},"Toggling Foreign Key Constraints"),(0,l.kt)("p",null,"You may enable or disable foreign key constraints within your migrations by using the following methods:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"Schema::enableForeignKeyConstraints();\n\nSchema::disableForeignKeyConstraints();\n\nSchema::withoutForeignKeyConstraints([]\n{\n // Constraints disabled within this lambda expression...\n});\n")),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The SQLite disables foreign key constraints by default. When using SQLite, make sure to ",(0,l.kt)("a",{parentName:"p",href:"/database/getting-started#sqlite-configuration"},"enable foreign key support")," in your database configuration before attempting to create them in your migrations. In addition, SQLite only supports creating foreign keys when creating tables and ",(0,l.kt)("a",{parentName:"p",href:"https://www.sqlite.org/omitted.html"},"not when tables are altered"),".")))}b.isMDXComponent=!0},9566:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/tom_cli-402f7dd4dfe7dbd0b20dfe5fb61838a2.png"}}]); \ No newline at end of file diff --git a/assets/js/21dc2778.c3cad2a2.js b/assets/js/21dc2778.c3cad2a2.js new file mode 100644 index 000000000..5a9410236 --- /dev/null +++ b/assets/js/21dc2778.c3cad2a2.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[291],{5162:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(7294),i=n(6010);const l={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,i.Z)(l.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>C});var a=n(7462),i=n(7294),l=n(6010),o=n(2466),r=n(6550),m=n(1980),d=n(7392),p=n(12);function s(e){return function(e){return i.Children.map(e,(e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:i}}=e;return{value:t,label:n,attributes:a,default:i}}))}function u(e){const{values:t,children:n}=e;return(0,i.useMemo)((()=>{const e=t??s(n);return function(e){const t=(0,d.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function c(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const a=(0,r.k6)(),l=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,m._X)(l),(0,i.useCallback)((e=>{if(!l)return;const t=new URLSearchParams(a.location.search);t.set(l,e),a.replace({...a.location,search:t.toString()})}),[l,a])]}function k(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,l=u(e),[o,r]=(0,i.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!c({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:l}))),[m,d]=h({queryString:n,groupId:a}),[s,k]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,p.Nk)(n);return[a,(0,i.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:a}),g=(()=>{const e=m??s;return c({value:e,tabValues:l})?e:null})();(0,i.useLayoutEffect)((()=>{g&&r(g)}),[g]);return{selectedValue:o,selectValue:(0,i.useCallback)((e=>{if(!c({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);r(e),d(e),k(e)}),[d,k,l]),tabValues:l}}var g=n(2389);const N={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function b(e){let{className:t,block:n,selectedValue:r,selectValue:m,tabValues:d}=e;const p=[],{blockElementScrollPositionUntilNextRender:s}=(0,o.o5)(),u=e=>{const t=e.currentTarget,n=p.indexOf(t),a=d[n].value;a!==r&&(s(t),m(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=p.indexOf(e.currentTarget)+1;t=p[n]??p[0];break}case"ArrowLeft":{const n=p.indexOf(e.currentTarget)-1;t=p[n]??p[p.length-1];break}}t?.focus()};return i.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},d.map((e=>{let{value:t,label:n,attributes:o}=e;return i.createElement("li",(0,a.Z)({role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,key:t,ref:e=>p.push(e),onKeyDown:c,onClick:u},o,{className:(0,l.Z)("tabs__item",N.tabItem,o?.className,{"tabs__item--active":r===t})}),n??t)})))}function f(e){let{lazy:t,children:n,selectedValue:a}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=l.find((e=>e.props.value===a));return e?(0,i.cloneElement)(e,{className:"margin-top--md"}):null}return i.createElement("div",{className:"margin-top--md"},l.map(((e,t)=>(0,i.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function y(e){const t=k(e);return i.createElement("div",{className:(0,l.Z)("tabs-container",N.tabList)},i.createElement(b,(0,a.Z)({},e,t)),i.createElement(f,(0,a.Z)({},e,t)))}function C(e){const t=(0,g.Z)();return i.createElement(y,(0,a.Z)({key:String(t)},e))}},5178:(e,t,n)=>{n.d(t,{Z:()=>r});var a=n(7294),i=n(6550);const l={apiTable:"apiTable_flxF"};const o=(0,a.forwardRef)(((e,t)=>{let{name:n,children:l}=e;const o=function(e){let t=e;for(;(0,a.isValidElement)(t);)[t]=a.Children.toArray(t.props.children);return t}(l),r=n?`#${n}-${o}`:`#${o}`,m=(0,i.k6)();return a.createElement("tr",{id:o,tabIndex:0,ref:m.location.hash===r?t:void 0,onClick:()=>{m.push(r)},onKeyDown:e=>{"Enter"===e.key&&m.push(r)}},l.props.children)}));function r(e){let{children:t,name:n}=e;const[i,r]=a.Children.toArray(t.props.children),m=(0,a.useRef)(null);(0,a.useEffect)((()=>{m.current?.focus()}),[m]);const d=a.Children.map(r.props.children,(e=>a.createElement(o,{name:n,ref:m},e)));return a.createElement("table",{className:l.apiTable},i,a.createElement("tbody",null,d))}},2044:(e,t,n)=>{n.d(t,{$t:()=>s,Ae:()=>g,C:()=>h,DK:()=>N,Fo:()=>r,Fs:()=>i,IM:()=>k,IZ:()=>a,RS:()=>T,VE:()=>b,Wg:()=>y,_A:()=>d,al:()=>v,jk:()=>c,js:()=>m,of:()=>p,q5:()=>o,qb:()=>C,vk:()=>u,wU:()=>l,zg:()=>f});const a="shell",i="database",l="application",o="bash",r="pwsh",m="zsh",d="maria",p="mysql",s="postgres",u="sqlite",c="application",h="bash",k="pwsh",g="zsh",N="MariaDB",b="MySQL",f="PostgreSQL",y="SQLite",C="tinyorm.org",v="$HOME/Code/c/",T="$env:USERPROFILE\\Code\\c\\"},4355:(e,t,n)=>{n.d(t,{Z:()=>l});var a=n(7294),i=n(9482);function l(){const e=(0,a.useContext)(i.Z);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6005:(e,t,n)=>{n.d(t,{AE:()=>r,EA:()=>o,em:()=>d,go:()=>m,mT:()=>p,we:()=>s});var a=n(4355),i=n(2389),l=n(2044);const o=function(e,t){return void 0===t&&(t=!0),u((0,a.Z)().rootFolder[e]??d(e),e,t)},r=()=>(0,a.Z)().rootFolder[l.wU]??d(l.wU),m=function(e,t){if(void 0===t&&(t=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const n=t||e!==l.Fo?"/":"\\";return u(o(e)+n+r(),e,t)};function d(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,i.Z)())return"";switch(e){case l.Fo:return l.RS;case l.q5:return l.al;case l.wU:return l.qb;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function p(e){return e===l.wU}function s(e,t){if(null==t||""===t)return t;const n="$ENV{$1}$2";switch(e){case l.Fo:return h(t).replace(/\$env:(.+?)(\/.*)/,n);case l.q5:return t.replace(/\$(.+?)(\/.*)/,n);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function u(e,t,n){if(void 0===n&&(n=!0),null==e||""===e)return e;if(t!==l.Fo)return c(e);const a=c(e);return n?h(a):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(a)}function c(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function h(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},6122:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>h,contentTitle:()=>u,default:()=>b,frontMatter:()=>s,metadata:()=>c,toc:()=>k});var a=n(7462),i=(n(7294),n(3905)),l=n(5178),o=n(7693),r=n(5162),m=n(4866),d=n(2044),p=n(6005);const s={sidebar_position:2,sidebar_label:"Migrations",description:"Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. Migrations use the Schema facade that provides database agnostic support for creating and manipulating tables across all of TinyORM's supported database systems.",keywords:["c++ orm","database","migrations","tinyorm"]},u="Database: Migrations",c={unversionedId:"database/migrations",id:"database/migrations",title:"Database: Migrations",description:"Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. Migrations use the Schema facade that provides database agnostic support for creating and manipulating tables across all of TinyORM's supported database systems.",source:"@site/docs/database/migrations.mdx",sourceDirName:"database",slug:"/database/migrations",permalink:"/database/migrations",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/database/migrations.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,sidebar_label:"Migrations",description:"Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. Migrations use the Schema facade that provides database agnostic support for creating and manipulating tables across all of TinyORM's supported database systems.",keywords:["c++ orm","database","migrations","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Query Builder",permalink:"/database/query-builder"},next:{title:"Seeding",permalink:"/database/seeding"}},h={},k=[{value:"Introduction",id:"introduction",level:2},{value:"Generating Migrations",id:"generating-migrations",level:2},{value:"Migrations naming rules",id:"migrations-naming-rules",level:4},{value:"Tab completion",id:"tab-completion",level:2},{value:"Alternative installation methods",id:"alternative-installation-methods",level:3},{value:"Static installation",id:"static-installation",level:4},{value:"Dynamic installation",id:"dynamic-installation",level:4},{value:"Migration Structure",id:"migration-structure",level:2},{value:"Setting The Migration Connection",id:"setting-the-migration-connection",level:4},{value:"Running Migrations",id:"running-migrations",level:2},{value:"Forcing Migrations To Run In Production",id:"forcing-migrations-to-run-in-production",level:4},{value:"Rolling Back Migrations",id:"rolling-back-migrations",level:3},{value:"Roll Back & Migrate Using A Single Command",id:"roll-back--migrate-using-a-single-command",level:4},{value:"Drop All Tables & Migrate",id:"drop-all-tables--migrate",level:4},{value:"Tables",id:"tables",level:2},{value:"Creating Tables",id:"creating-tables",level:3},{value:"Checking For Table / Column Existence",id:"checking-for-table--column-existence",level:4},{value:"Database Connection & Table Options",id:"database-connection--table-options",level:4},{value:"Updating Tables",id:"updating-tables",level:3},{value:"Renaming / Dropping Tables",id:"renaming-and-dropping-tables",level:3},{value:"Renaming Tables With Foreign Keys",id:"renaming-tables-with-foreign-keys",level:4},{value:"Columns",id:"columns",level:2},{value:"Creating Columns",id:"creating-columns",level:3},{value:"Available Column Types",id:"available-column-types",level:3},{value:"bigIncrements()",id:"column-method-bigIncrements",level:4},{value:"bigInteger()",id:"column-method-bigInteger",level:4},{value:"binary()",id:"column-method-binary",level:4},{value:"boolean()",id:"column-method-boolean",level:4},{value:"Char()",id:"column-method-Char",level:4},{value:"date()",id:"column-method-date",level:4},{value:"datetime()",id:"column-method-datetime",level:4},{value:"datetimes()",id:"column-method-datetimes",level:4},{value:"datetimeTz()",id:"column-method-datetimeTz",level:4},{value:"decimal()",id:"column-method-decimal",level:4},{value:"Double()",id:"column-method-Double",level:4},{value:"Enum()",id:"column-method-Enum",level:4},{value:"Float()",id:"column-method-Float",level:4},{value:"foreignId()",id:"column-method-foreignId",level:4},{value:"foreignIdFor()",id:"column-method-foreignIdFor",level:4},{value:"foreignUuid()",id:"column-method-foreignUuid",level:4},{value:"geometry()",id:"column-method-geometry",level:4},{value:"geometryCollection()",id:"column-method-geometryCollection",level:4},{value:"id()",id:"column-method-id",level:4},{value:"increments()",id:"column-method-increments",level:4},{value:"integer()",id:"column-method-integer",level:4},{value:"ipAddress()",id:"column-method-ipAddress",level:4},{value:"json()",id:"column-method-json",level:4},{value:"jsonb()",id:"column-method-jsonb",level:4},{value:"lineString()",id:"column-method-lineString",level:4},{value:"longBinary()",id:"column-method-longBinary",level:4},{value:"longText()",id:"column-method-longText",level:4},{value:"macAddress()",id:"column-method-macAddress",level:4},{value:"mediumBinary()",id:"column-method-mediumBinary",level:4},{value:"mediumIncrements()",id:"column-method-mediumIncrements",level:4},{value:"mediumInteger()",id:"column-method-mediumInteger",level:4},{value:"mediumText()",id:"column-method-mediumText",level:4},{value:"multiLineString()",id:"column-method-multiLineString",level:4},{value:"multiPoint()",id:"column-method-multiPoint",level:4},{value:"multiPolygon()",id:"column-method-multiPolygon",level:4},{value:"point()",id:"column-method-point",level:4},{value:"polygon()",id:"column-method-polygon",level:4},{value:"rememberToken()",id:"column-method-rememberToken",level:4},{value:"set()",id:"column-method-set",level:4},{value:"smallIncrements()",id:"column-method-smallIncrements",level:4},{value:"smallInteger()",id:"column-method-smallInteger",level:4},{value:"softDeletes()",id:"column-method-softDeletes",level:4},{value:"softDeletesDatetime()",id:"column-method-softDeletesDatetime",level:4},{value:"softDeletesTz()",id:"column-method-softDeletesTz",level:4},{value:"string()",id:"column-method-string",level:4},{value:"text()",id:"column-method-text",level:4},{value:"time()",id:"column-method-time",level:4},{value:"timeTz()",id:"column-method-timeTz",level:4},{value:"timestamp()",id:"column-method-timestamp",level:4},{value:"timestampTz()",id:"column-method-timestampTz",level:4},{value:"timestampsTz()",id:"column-method-timestampsTz",level:4},{value:"timestamps()",id:"column-method-timestamps",level:4},{value:"tinyBinary()",id:"column-method-tinyBinary",level:4},{value:"tinyIncrements()",id:"column-method-tinyIncrements",level:4},{value:"tinyInteger()",id:"column-method-tinyInteger",level:4},{value:"tinyText()",id:"column-method-tinyText",level:4},{value:"unsignedBigInteger()",id:"column-method-unsignedBigInteger",level:4},{value:"unsignedDecimal()",id:"column-method-unsignedDecimal",level:4},{value:"unsignedInteger()",id:"column-method-unsignedInteger",level:4},{value:"unsignedMediumInteger()",id:"column-method-unsignedMediumInteger",level:4},{value:"unsignedSmallInteger()",id:"column-method-unsignedSmallInteger",level:4},{value:"unsignedTinyInteger()",id:"column-method-unsignedTinyInteger",level:4},{value:"uuid()",id:"column-method-uuid",level:4},{value:"year()",id:"column-method-year",level:4},{value:"Column Modifiers",id:"column-modifiers",level:3},{value:"Default Expressions",id:"default-expressions",level:4},{value:"Column Order",id:"column-order",level:4},{value:"Modifying Columns",id:"modifying-columns",level:3},{value:"Renaming Columns",id:"renaming-columns",level:4},{value:"Renaming Columns On Legacy Databases",id:"renaming-columns-on-legacy-databases",level:4},{value:"Dropping Columns",id:"dropping-columns",level:3},{value:"Available Command Aliases",id:"available-command-aliases",level:4},{value:"Indexes",id:"indexes",level:2},{value:"Creating Indexes",id:"creating-indexes",level:3},{value:"Available Index Types",id:"available-index-types",level:4},{value:"Index Lengths & MySQL / MariaDB",id:"index-lengths--mysql--mariadb",level:4},{value:"Renaming Indexes",id:"renaming-indexes",level:3},{value:"Dropping Indexes",id:"dropping-indexes",level:3},{value:"Foreign Key Constraints",id:"foreign-key-constraints",level:3},{value:"Dropping Foreign Keys",id:"dropping-foreign-keys",level:4},{value:"Toggling Foreign Key Constraints",id:"toggling-foreign-key-constraints",level:4}],g={toc:k},N="wrapper";function b(e){let{components:t,...s}=e;return(0,i.kt)(N,(0,a.Z)({},g,s,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"database-migrations"},"Database: Migrations"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#generating-migrations"},"Generating Migrations")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#tab-completion"},"Tab completion"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#alternative-installation-methods"},"Alternative installation methods")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#migration-structure"},"Migration Structure")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#running-migrations"},"Running Migrations"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#rolling-back-migrations"},"Rolling Back Migrations")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#tables"},"Tables"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#creating-tables"},"Creating Tables")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#updating-tables"},"Updating Tables")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#renaming-and-dropping-tables"},"Renaming / Dropping Tables")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#columns"},"Columns"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#creating-columns"},"Creating Columns")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#available-column-types"},"Available Column Types")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#column-modifiers"},"Column Modifiers")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#modifying-columns"},"Modifying Columns")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#dropping-columns"},"Dropping Columns")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#indexes"},"Indexes"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#creating-indexes"},"Creating Indexes")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#renaming-indexes"},"Renaming Indexes")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#dropping-indexes"},"Dropping Indexes")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#foreign-key-constraints"},"Foreign Key Constraints"))))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,"Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. If you have ever had to tell a teammate to manually add a column to their local database schema after pulling in your changes from source control, you've faced the problem that database migrations solve."),(0,i.kt)("p",null,"The TinyORM ",(0,i.kt)("inlineCode",{parentName:"p"},"Schema")," facade provides database agnostic support for creating and manipulating tables across all of TinyORM's supported database systems. Typically, migrations will use this facade to create and modify database tables and columns."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations is a small console application that depends on the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. All migrations logic is compiled so recompilation is needed after adding a new migration class."),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#tables"},(0,i.kt)("inlineCode",{parentName:"a"},"schema builder"))," and ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},(0,i.kt)("inlineCode",{parentName:"a"},"migrations"))," don't support ",(0,i.kt)("a",{parentName:"p",href:"/database/getting-started#multi-threading-support"},"multi-threading"),".")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"TinyORM's schema builder supports all ",(0,i.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"supported databases")," out of the box.")),(0,i.kt)("p",null,"The following image shows what the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," console application looks like. \u2728 As you can see it offers everything that is needed to generate and manage migrations and seeders and all of this is backed up with the tab completion."),(0,i.kt)("img",{src:n(9566).Z,alt:"TinyORM - Tom console application - Showcase",width:"760",title:"TinyORM - Tom console application - Showcase"}),(0,i.kt)("h2",{id:"generating-migrations"},"Generating Migrations"),(0,i.kt)("p",null,"You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"make:migration")," ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," command to generate a database migration. The new migration will be placed in your ",(0,i.kt)("inlineCode",{parentName:"p"},"database/migrations")," directory. Each migration filename contains a timestamp that allows ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," to determine the order of the migrations:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:migration create_posts_table\n")),(0,i.kt)("p",null,"tom will use the name of the migration to attempt to guess the name of the table and whether or not the migration will be creating a new table. If ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," is able to determine the table name from the migration name, ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," will pre-fill the generated migration file with the specified table. Otherwise, you may simply specify the table in the migration file manually."),(0,i.kt)("p",null,"If you would like to specify a custom path for the generated migration, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"--path")," option when executing the ",(0,i.kt)("inlineCode",{parentName:"p"},"make:migration")," command. The given path should be relative to your ",(0,i.kt)("abbr",{title:"Current working directory"},"pwd")," or you can use the ",(0,i.kt)("inlineCode",{parentName:"p"},"--realpath")," option and pass the absolute path to the ",(0,i.kt)("inlineCode",{parentName:"p"},"--path")," option."),(0,i.kt)("h4",{id:"migrations-naming-rules"},"Migrations naming rules"),(0,i.kt)("p",null,"If the migration name starts with the ",(0,i.kt)("inlineCode",{parentName:"p"},"create_")," string then the stub for table creation will be used and if the migration name contains ",(0,i.kt)("inlineCode",{parentName:"p"},"_(from|to|in)_")," then the stub for table update will be used. You can override these rules using the ",(0,i.kt)("inlineCode",{parentName:"p"},"--create")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"--table")," options and specify the table name manually."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can also pass the full migration filename with the datetime prefix and extension to the ",(0,i.kt)("inlineCode",{parentName:"p"},"make:migration"),". This command is able to detect almost any combination of the passed value, with or without datetime prefix or extension if it is the filename; or StudlyCase, snake_case, or kebab-case if it is the classname or any combination described above. \ud83d\udc40")),(0,i.kt)("h2",{id:"tab-completion"},"Tab completion"),(0,i.kt)("p",null,"Tab completion is available for the ",(0,i.kt)("inlineCode",{parentName:"p"},"pwsh")," (on Linux too), ",(0,i.kt)("inlineCode",{parentName:"p"},"bash"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"zsh")," shells. For ",(0,i.kt)("inlineCode",{parentName:"p"},"pwsh")," the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom.exe")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyOrm0.dll")," library must be on the system path to work properly. With ",(0,i.kt)("inlineCode",{parentName:"p"},"bash")," if the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," executable and ",(0,i.kt)("inlineCode",{parentName:"p"},"libTinyOrm.so")," library is ",(0,i.kt)("strong",{parentName:"p"},"not")," on the system path then it will provide less accurate completions."),(0,i.kt)("p",null,"You can enable it using the following commands."),(0,i.kt)(m.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-powershell"},"tom integrate pwsh\n"))),(0,i.kt)(r.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom integrate bash\n"))),(0,i.kt)(r.Z,{value:d.js,label:d.Ae,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom integrate zsh\ntom integrate zsh --path=/usr/share/zsh/site-functions\n")))),(0,i.kt)("p",null,"Or you can enable it manually. Following actions are the same as the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom integrate")," command does."),(0,i.kt)("p",null,"For the ",(0,i.kt)("inlineCode",{parentName:"p"},"pwsh")," paste the following code to the pwsh profile (works on Linux or Windows)."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-powershell",metastring:"title='~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1'",title:"'~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1'"},"Register-ArgumentCompleter -Native -CommandName tom,tom_testdata -ScriptBlock {\n Param($wordToComplete, $commandAst, $cursorPosition)\n [Console]::InputEncoding =\n [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()\n $Local:word = $wordToComplete.Replace('\"', '\\\"')\n $Local:ast = $commandAst.ToString().Replace('\"', '\\\"')\n tom complete --word=\"$Local:word\" --commandline=\"$Local:ast\" --position=$cursorPosition\n | ForEach-Object {\n $completionText, $listText, $toolTip = $_ -split ';', 3\n $listText ??= $completionText\n $toolTip ??= $completionText\n [System.Management.Automation.CompletionResult]::new(\n $completionText, $listText, 'ParameterValue', $toolTip)\n }\n}\n")),(0,i.kt)("p",null,"For ",(0,i.kt)("inlineCode",{parentName:"p"},"bash")," you can copy or create symlink of the ",(0,i.kt)("inlineCode",{parentName:"p"},"/tools/completions/tom.bash")," file to the ",(0,i.kt)("inlineCode",{parentName:"p"},"/usr/share/bash-completion/completions")," folder."),(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`sudo ln -s ${(0,p.go)(d.q5)}/TinyORM/tools/completions/tom.bash /usr/share/bash-completion/completions/tom`),(0,i.kt)("p",null,"And for ",(0,i.kt)("inlineCode",{parentName:"p"},"zsh")," you can copy or create symlink of the ",(0,i.kt)("inlineCode",{parentName:"p"},"/tools/completions/tom.zsh")," file to the ",(0,i.kt)("inlineCode",{parentName:"p"},"_tom")," file to ",(0,i.kt)("inlineCode",{parentName:"p"},"/usr/local/share/zsh/site-functions")," folder."),(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`sudo ln -s ${(0,p.go)(d.q5)}/TinyORM/tools/completions/tom.zsh /usr/local/share/zsh/site-functions/_tom`),(0,i.kt)("p",null,"It will provide completions for the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," commands, long and short parameters, and also for some positional arguments like namespaces for the ",(0,i.kt)("inlineCode",{parentName:"p"},"list")," command or commands for the ",(0,i.kt)("inlineCode",{parentName:"p"},"help")," command."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tom integrate zsh")," command also accepts the ",(0,i.kt)("inlineCode",{parentName:"p"},"--path=")," option with which you can set the location, where the zsh completion file should be created.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can also output the completion script using the ",(0,i.kt)("inlineCode",{parentName:"p"},"--stdout")," option eg. ",(0,i.kt)("inlineCode",{parentName:"p"},"tom integrate bash --stdout"),".")),(0,i.kt)("h3",{id:"alternative-installation-methods"},"Alternative installation methods"),(0,i.kt)("p",null,"This section describes alternative installation methods for ",(0,i.kt)("inlineCode",{parentName:"p"},"bash")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"zsh")," tab completions."),(0,i.kt)("h4",{id:"static-installation"},"Static installation"),(0,i.kt)("p",null,"Idea is to output the tab completion to the file and then source it."),(0,i.kt)(m.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"mkdir -p ~/.local/share/tom\ntom integrate bash --stdout > ~/.local/share/tom/tom.bash\n\n# Then source this file in the ~/.bashrc\nsource $HOME/.local/share/tom/tom.bash\n"))),(0,i.kt)(r.Z,{value:d.js,label:d.Ae,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"mkdir -p ~/.local/share/tom\ntom integrate zsh --stdout > ~/.local/share/tom/tom.zsh\n\n# Then source this file in the ~/.zshrc\nsource $HOME/.local/share/tom/tom.zsh\ncompdef _tom tom\n")))),(0,i.kt)("h4",{id:"dynamic-installation"},"Dynamic installation"),(0,i.kt)("p",null,"Idea is to ",(0,i.kt)("strong",{parentName:"p"},"avoid")," outputting the tab completion to the file, so you ",(0,i.kt)("inlineCode",{parentName:"p"},"eval")," the tab completion source code right away."),(0,i.kt)(m.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},'# Add this eval to the ~/.bashrc\neval "$(tom integrate bash --stdout)"\n'))),(0,i.kt)(r.Z,{value:d.js,label:d.Ae,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},'# Add this eval to the ~/.zshrc\neval "$(tom integrate zsh --stdout)"\ncompdef _tom tom\n')))),(0,i.kt)("h2",{id:"migration-structure"},"Migration Structure"),(0,i.kt)("p",null,"A migration class contains two methods: ",(0,i.kt)("inlineCode",{parentName:"p"},"up")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"down"),". The ",(0,i.kt)("inlineCode",{parentName:"p"},"up")," method is used to add new tables, columns, or indexes to your database, while the ",(0,i.kt)("inlineCode",{parentName:"p"},"down")," method should reverse the operations performed by the ",(0,i.kt)("inlineCode",{parentName:"p"},"up")," method."),(0,i.kt)("p",null,"Within both of these methods, you may use the TinyORM schema builder to expressively create and modify tables. To learn about all of the methods available on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Schema")," builder, ",(0,i.kt)("a",{parentName:"p",href:"#creating-tables"},"check out its documentation"),". For example, the following migration creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"posts")," table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#pragma once\n\n#include \n\nnamespace Migrations\n{\n\n struct CreatePostsTable : Migration\n {\n /*! Filename of the migration file. */\n T_MIGRATION\n\n /*! Run the migrations. */\n void up() const override\n {\n Schema::create("posts", [](Blueprint &table)\n {\n table.id();\n\n table.string(NAME);\n table.timestamps();\n });\n }\n\n /*! Reverse the migrations. */\n void down() const override\n {\n Schema::dropIfExists("posts");\n }\n };\n\n} // namespace Migrations\n')),(0,i.kt)("p",null,'Migration classes can be named in two formats, StudlyCase without the datetime prefix and "snake_case" with the datetime prefix. If the StudlyCase name is used then the ',(0,i.kt)("inlineCode",{parentName:"p"},"T_MIGRATION")," macro must also be used in the migration class."),(0,i.kt)("p",null,"Naming with the datetime prefix should look like this."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"struct _2014_10_12_000000_create_posts_table : Migration\n{\n\n /*! Run the migrations. */\n void up() const override\n {\n //\n }\n\n /*! Reverse the migrations. */\n void down() const override\n {\n //\n }\n};\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The StudlyCase naming is preferred. Also the ",(0,i.kt)("inlineCode",{parentName:"p"},"make:migration")," command generates migrations in this format.")),(0,i.kt)("h4",{id:"setting-the-migration-connection"},"Setting The Migration Connection"),(0,i.kt)("p",null,"If your migration will be interacting with a database connection other than your application's default database connection, you should set the ",(0,i.kt)("inlineCode",{parentName:"p"},"connection")," data member of your migration:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! The name of the database connection to use. */\nQString connection = QStringLiteral("tinyorm_example");\n\n/*! Run the migrations. */\nvoid up() const override\n{\n //\n}\n')),(0,i.kt)("h2",{id:"running-migrations"},"Running Migrations"),(0,i.kt)("p",null,"To run all of your outstanding migrations, execute the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate")," Tom command:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate\n")),(0,i.kt)("p",null,"If you would like to see which migrations have run thus far, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:status")," tom command:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:status\n")),(0,i.kt)("p",null,"If you would like to see the SQL statements that will be executed by the migrations without actually running them, you may provide the ",(0,i.kt)("inlineCode",{parentName:"p"},"--pretend")," flag to the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate")," command:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate --pretend\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"Many ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," commands offer variety of options, you can explore them using the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom list")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"tom help")," commands. In most cases, these commands and options are self-explanatory.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," command is able to guess the command name and command namespace, eg. ",(0,i.kt)("inlineCode",{parentName:"p"},"tom mig:st")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"tom m:rol"),", ...")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can pass the ",(0,i.kt)("inlineCode",{parentName:"p"},"-vvv")," command-line argument to any command to see all executed SQL queries. \ud83d\udc4c")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate")," Tom command internally calls the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:install")," command which installs the migration repository table. To uninstall this repository table you can call the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:uninstall"),".")),(0,i.kt)("h4",{id:"forcing-migrations-to-run-in-production"},"Forcing Migrations To Run In Production"),(0,i.kt)("p",null,"Some migration operations are destructive, which means they may cause you to lose data. In order to protect you from running these commands against your production database, you will be prompted for confirmation before the commands are executed. To force the commands to run without a prompt, use the ",(0,i.kt)("inlineCode",{parentName:"p"},"--force")," flag:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate --force\n")),(0,i.kt)("h3",{id:"rolling-back-migrations"},"Rolling Back Migrations"),(0,i.kt)("p",null,"To roll back the latest migration operation, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"rollback"),' Tom command. This command rolls back the last "batch" of migrations, which may include multiple migration files:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:rollback\n")),(0,i.kt)("p",null,"You may roll back a limited number of migrations by providing the ",(0,i.kt)("inlineCode",{parentName:"p"},"step")," option to the ",(0,i.kt)("inlineCode",{parentName:"p"},"rollback")," command. For example, the following command will roll back the last five migrations:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:rollback --step=5\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:reset")," command will roll back all of your application's migrations:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:reset\n")),(0,i.kt)("p",null,'You may roll back a specific "batch" of migrations by providing the ',(0,i.kt)("inlineCode",{parentName:"p"},"batch")," option to the ",(0,i.kt)("inlineCode",{parentName:"p"},"rollback")," command, where the ",(0,i.kt)("inlineCode",{parentName:"p"},"batch")," option corresponds to a batch value within your application's ",(0,i.kt)("inlineCode",{parentName:"p"},"migrations")," database table. For example, the following command will roll back all migrations in batch three:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:rollback --batch=3\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:reset")," command will roll back all of your application's migrations:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:reset\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:uninstall")," command will uninstall the migration repository table, it optionally accepts the ",(0,i.kt)("inlineCode",{parentName:"p"},"--reset")," option to roll back all of your application's migrations:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:uninstall --reset\n")),(0,i.kt)("h4",{id:"roll-back--migrate-using-a-single-command"},"Roll Back & Migrate Using A Single Command"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:refresh")," command will roll back all of your migrations and then execute the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate")," command. This command effectively re-creates your entire database:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:refresh\n")),(0,i.kt)("p",null,"You may roll back and re-migrate a limited number of migrations by providing the ",(0,i.kt)("inlineCode",{parentName:"p"},"step")," option to the ",(0,i.kt)("inlineCode",{parentName:"p"},"refresh")," command. For example, the following command will roll back and re-migrate the last five migrations:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:refresh --step=5\n")),(0,i.kt)("h4",{id:"drop-all-tables--migrate"},"Drop All Tables & Migrate"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:fresh")," command will drop all tables from the database and then execute the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate")," command:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom migrate:fresh\n")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:fresh")," command will drop all database tables regardless of their prefix. This command should be used with caution when developing on a database that is shared with other applications.")),(0,i.kt)("h2",{id:"tables"},"Tables"),(0,i.kt)("h3",{id:"creating-tables"},"Creating Tables"),(0,i.kt)("p",null,"To create a new database table, use the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Schema")," facade. The ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method accepts two arguments: the first is the name of the table, while the second is a lambda expression which receives a ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::SchemaNs::Blueprint")," object that may be used to define the new table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Schema;\n\nSchema::create("users", [](Blueprint &table)\n{\n table.id();\n table.string("name");\n table.string("email");\n table.timestamps();\n});\n')),(0,i.kt)("p",null,"When creating the table, you may use any of the schema builder's ",(0,i.kt)("a",{parentName:"p",href:"#creating-columns"},"column methods")," to define the table's columns."),(0,i.kt)("h4",{id:"checking-for-table--column-existence"},"Checking For Table / Column Existence"),(0,i.kt)("p",null,"You may check for the existence of a table or column using the ",(0,i.kt)("inlineCode",{parentName:"p"},"hasTable")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"hasColumn")," methods:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'if (Schema::hasTable("users")) {\n // The "users" table exists...\n}\n\nif (Schema::hasColumn("users", "email")) {\n // The "users" table exists and has an "email" column...\n}\n')),(0,i.kt)("h4",{id:"database-connection--table-options"},"Database Connection & Table Options"),(0,i.kt)("p",null,"If you want to perform a schema operation on a database connection that is not your application's default connection, use the ",(0,i.kt)("inlineCode",{parentName:"p"},"connection")," method or ",(0,i.kt)("inlineCode",{parentName:"p"},"on")," alias:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::connection("postgres").create("users", [](Blueprint &table)\n{\n table.id();\n});\n')),(0,i.kt)("p",null,"In addition, a few other data members and methods may be used to define other aspects of the table's creation. The ",(0,i.kt)("inlineCode",{parentName:"p"},"engine")," data member may be used to specify the table's storage engine when using MySQL:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Constants::InnoDB;\n\nSchema::create("users", [](Blueprint &table)\n{\n table.engine = InnoDB;\n\n // ...\n});\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"charset")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"collation")," data members may be used to specify the character set and collation for the created table when using MySQL:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Constants::UTF8MB4;\n\nSchema::create("users", [](Blueprint &table)\n{\n table.charset = UTF8MB4;\n table.collation = "utf8mb4_unicode_ci";\n\n // ...\n});\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"temporary"),' method may be used to indicate that the table should be "temporary". Temporary tables are only visible to the current connection\'s database session and are dropped automatically when the connection is closed:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::create("calculations", [](Blueprint &table)\n{\n table.temporary();\n\n // ...\n});\n')),(0,i.kt)("p",null,'If you would like to add a "comment" to a database table, you may invoke the ',(0,i.kt)("inlineCode",{parentName:"p"},"comment")," method on the table instance. Table comments are currently only supported by MySQL and PostgreSQL:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::create("calculations", [](Blueprint &table)\n{\n table.comment("Business calculations");\n\n // ...\n});\n')),(0,i.kt)("h3",{id:"updating-tables"},"Updating Tables"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"table")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Schema")," facade may be used to update existing tables. Like the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method, the ",(0,i.kt)("inlineCode",{parentName:"p"},"table")," method accepts two arguments: the name of the table and a lambda expression that receives a ",(0,i.kt)("inlineCode",{parentName:"p"},"Blueprint")," instance you may use to add columns or indexes to the table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.integer("votes");\n});\n')),(0,i.kt)("h3",{id:"renaming-and-dropping-tables"},"Renaming / Dropping Tables"),(0,i.kt)("p",null,"To rename an existing database table, use the ",(0,i.kt)("inlineCode",{parentName:"p"},"rename")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nSchema::rename("from", "to");\n')),(0,i.kt)("p",null,"To drop an existing table, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"drop")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"dropIfExists")," methods:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::drop("users");\n\nSchema::dropIfExists("users");\n')),(0,i.kt)("h4",{id:"renaming-tables-with-foreign-keys"},"Renaming Tables With Foreign Keys"),(0,i.kt)("p",null,"Before renaming a table, you should verify that any foreign key constraints on the table have an explicit name in your migration files instead of letting TinyORM assign a convention based name. Otherwise, the foreign key constraint ",(0,i.kt)("strong",{parentName:"p"},"index name")," will refer to the old table name."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"After renaming a table, you can re-create (drop and create again) the foreign key constraints to fix an ",(0,i.kt)("strong",{parentName:"p"},"index name"),", so it refers to a renamed table.")),(0,i.kt)("h2",{id:"columns"},"Columns"),(0,i.kt)("h3",{id:"creating-columns"},"Creating Columns"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"table")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Schema")," facade may be used to update existing tables. Like the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method, the ",(0,i.kt)("inlineCode",{parentName:"p"},"table")," method accepts two arguments: the name of the table and a lambda expression that receives a ",(0,i.kt)("inlineCode",{parentName:"p"},"Blueprint")," instance you may use to add columns to the table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.integer("votes");\n});\n')),(0,i.kt)("h3",{id:"available-column-types"},"Available Column Types"),(0,i.kt)("p",null,"The schema builder blueprint offers a variety of methods that correspond to the different types of columns you can add to your database tables. Each of the available methods are listed in the table below:"),(0,i.kt)("div",{class:"tom-column-types-list"},(0,i.kt)("p",null,(0,i.kt)("a",{parentName:"p",href:"#column-method-bigIncrements"},"bigIncrements"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-bigInteger"},"bigInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-binary"},"binary"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-boolean"},"boolean"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-Char"},"Char"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-date"},"date"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-datetime"},"datetime"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-datetimes"},"datetimes"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-datetimeTz"},"datetimeTz"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-decimal"},"decimal"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-Double"},"Double"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-Enum"},"Enum"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-Float"},"Float"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-foreignId"},"foreignId"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-foreignIdFor"},"foreignIdFor"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-foreignUuid"},"foreignUuid"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-geometry"},"geometry"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-geometryCollection"},"geometryCollection"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-id"},"id"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-increments"},"increments"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-integer"},"integer"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-ipAddress"},"ipAddress"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-json"},"json"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-jsonb"},"jsonb"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-lineString"},"lineString"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-longBinary"},"longBinary"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-longText"},"longText"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-macAddress"},"macAddress"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-mediumBinary"},"mediumBinary"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-mediumIncrements"},"mediumIncrements"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-mediumInteger"},"mediumInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-mediumText"},"mediumText"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-multiLineString"},"multiLineString"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-multiPoint"},"multiPoint"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-multiPolygon"},"multiPolygon"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-point"},"point"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-polygon"},"polygon"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-rememberToken"},"rememberToken"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-set"},"set"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-smallIncrements"},"smallIncrements"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-smallInteger"},"smallInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-softDeletes"},"softDeletes"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-softDeletesDatetime"},"softDeletesDatetime"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-softDeletesTz"},"softDeletesTz"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-string"},"string"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-text"},"text"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-time"},"time"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-timeTz"},"timeTz"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-timestamp"},"timestamp"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-timestampTz"},"timestampTz"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-timestampsTz"},"timestampsTz"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-timestamps"},"timestamps"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-tinyBinary"},"tinyBinary"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-tinyIncrements"},"tinyIncrements"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-tinyInteger"},"tinyInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-tinyText"},"tinyText"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-unsignedBigInteger"},"unsignedBigInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-unsignedDecimal"},"unsignedDecimal"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-unsignedInteger"},"unsignedInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-unsignedMediumInteger"},"unsignedMediumInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-unsignedSmallInteger"},"unsignedSmallInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-unsignedTinyInteger"},"unsignedTinyInteger"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-uuid"},"uuid"),"\n",(0,i.kt)("a",{parentName:"p",href:"#column-method-year"},"year"))),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Names of ",(0,i.kt)("inlineCode",{parentName:"p"},"Char"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"Double"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"Enum"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"Float")," column methods are in the CamelCase format to avoid collisions with C++ keywords.")),(0,i.kt)("div",{class:"tom-column-types"},(0,i.kt)("h4",{id:"column-method-bigIncrements"},(0,i.kt)("inlineCode",{parentName:"h4"},"bigIncrements()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"bigIncrements")," method creates an auto-incrementing ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED BIGINT")," (primary key) equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#include \n\ntable.bigIncrements(Orm::ID);\n")),(0,i.kt)("h4",{id:"column-method-bigInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"bigInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"bigInteger")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"BIGINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.bigInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-binary"},(0,i.kt)("inlineCode",{parentName:"h4"},"binary()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"binary")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"BLOB")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.binary("photo");\n')),(0,i.kt)("h4",{id:"column-method-boolean"},(0,i.kt)("inlineCode",{parentName:"h4"},"boolean()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"boolean")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"BOOLEAN")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.boolean("confirmed");\n')),(0,i.kt)("h4",{id:"column-method-Char"},(0,i.kt)("inlineCode",{parentName:"h4"},"Char()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"Char")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"CHAR")," equivalent column with of a given length:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#include \n\ntable.Char(Orm::NAME, 100);\n")),(0,i.kt)("h4",{id:"column-method-date"},(0,i.kt)("inlineCode",{parentName:"h4"},"date()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"date")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"DATE")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.date("created_at");\n')),(0,i.kt)("h4",{id:"column-method-datetime"},(0,i.kt)("inlineCode",{parentName:"h4"},"datetime()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"datetime")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"DATETIME")," equivalent column with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.datetime("created_at", precision = 0);\n')),(0,i.kt)("h4",{id:"column-method-datetimes"},(0,i.kt)("inlineCode",{parentName:"h4"},"datetimes()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"datetimes")," method creates ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," ",(0,i.kt)("inlineCode",{parentName:"p"},"DATETIME")," equivalent columns with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"table.datetimes(precision = 0);\n")),(0,i.kt)("h4",{id:"column-method-datetimeTz"},(0,i.kt)("inlineCode",{parentName:"h4"},"datetimeTz()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"datetimeTz")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"DATETIME")," (with timezone) equivalent column with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#include \n\ntable.datetimeTz(Orm::CREATED_AT, precision = 0);\n")),(0,i.kt)("h4",{id:"column-method-decimal"},(0,i.kt)("inlineCode",{parentName:"h4"},"decimal()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"decimal")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"DECIMAL")," equivalent column with the given precision (total digits) and scale (decimal digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.decimal("amount", precision = 8, scale = 2);\n')),(0,i.kt)("h4",{id:"column-method-Double"},(0,i.kt)("inlineCode",{parentName:"h4"},"Double()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"Double")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"DOUBLE")," equivalent column with the given precision (total digits) and scale (decimal digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.Double("amount", 8, 2);\n')),(0,i.kt)("h4",{id:"column-method-Enum"},(0,i.kt)("inlineCode",{parentName:"h4"},"Enum()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"Enum")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"ENUM")," equivalent column with the given valid values:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.Enum("difficulty", {"easy", "hard"});\n')),(0,i.kt)("h4",{id:"column-method-Float"},(0,i.kt)("inlineCode",{parentName:"h4"},"Float()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"Float")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"FLOAT")," equivalent column with the given precision (total digits) and scale (decimal digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.Float("amount", 8, 2);\n')),(0,i.kt)("h4",{id:"column-method-foreignId"},(0,i.kt)("inlineCode",{parentName:"h4"},"foreignId()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"foreignId")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED BIGINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.foreignId("user_id");\n')),(0,i.kt)("h4",{id:"column-method-foreignIdFor"},(0,i.kt)("inlineCode",{parentName:"h4"},"foreignIdFor()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"foreignIdFor")," method adds a ",(0,i.kt)("inlineCode",{parentName:"p"},"{column}_id UNSIGNED BIGINT")," equivalent column for a given model class:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/user.hpp"\n\nModels::User user;\n\ntable.foreignIdFor(User);\n')),(0,i.kt)("h4",{id:"column-method-foreignUuid"},(0,i.kt)("inlineCode",{parentName:"h4"},"foreignUuid()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"foreignUuid")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"UUID")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.foreignUuid("user_id");\n')),(0,i.kt)("h4",{id:"column-method-geometry"},(0,i.kt)("inlineCode",{parentName:"h4"},"geometry()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"geometry")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"GEOMETRY")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.geometry("positions");\n')),(0,i.kt)("h4",{id:"column-method-geometryCollection"},(0,i.kt)("inlineCode",{parentName:"h4"},"geometryCollection()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"geometryCollection")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"GEOMETRYCOLLECTION")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.geometryCollection("positions");\n')),(0,i.kt)("h4",{id:"column-method-id"},(0,i.kt)("inlineCode",{parentName:"h4"},"id()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"id")," method is an alias of the ",(0,i.kt)("inlineCode",{parentName:"p"},"bigIncrements")," method. By default, the method will create an ",(0,i.kt)("inlineCode",{parentName:"p"},"id")," column; however, you may pass a column name if you would like to assign a different name to the column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"table.id();\n")),(0,i.kt)("h4",{id:"column-method-increments"},(0,i.kt)("inlineCode",{parentName:"h4"},"increments()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"increments")," method creates an auto-incrementing ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED INTEGER")," equivalent column as a primary key:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.increments("id");\n')),(0,i.kt)("h4",{id:"column-method-integer"},(0,i.kt)("inlineCode",{parentName:"h4"},"integer()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"integer")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"INTEGER")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.integer("votes");\n')),(0,i.kt)("h4",{id:"column-method-ipAddress"},(0,i.kt)("inlineCode",{parentName:"h4"},"ipAddress()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"ipAddress")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"VARCHAR(45)")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.ipAddress("visitor");\n')),(0,i.kt)("h4",{id:"column-method-json"},(0,i.kt)("inlineCode",{parentName:"h4"},"json()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"json")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"JSON")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.json("options");\n')),(0,i.kt)("h4",{id:"column-method-jsonb"},(0,i.kt)("inlineCode",{parentName:"h4"},"jsonb()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"jsonb")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"JSONB")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.jsonb("options");\n')),(0,i.kt)("h4",{id:"column-method-lineString"},(0,i.kt)("inlineCode",{parentName:"h4"},"lineString()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"lineString")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"LINESTRING")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.lineString("positions");\n')),(0,i.kt)("h4",{id:"column-method-longBinary"},(0,i.kt)("inlineCode",{parentName:"h4"},"longBinary()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"longBinary")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"LONGBLOB")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.longBinary("photo");\n')),(0,i.kt)("h4",{id:"column-method-longText"},(0,i.kt)("inlineCode",{parentName:"h4"},"longText()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"longText")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"LONGTEXT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.longText("description");\n')),(0,i.kt)("h4",{id:"column-method-macAddress"},(0,i.kt)("inlineCode",{parentName:"h4"},"macAddress()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"macAddress")," method creates a column that is intended to hold a MAC address. Some database systems, such as PostgreSQL, have a dedicated column type for this type of data. Other database systems will use a string equivalent ",(0,i.kt)("inlineCode",{parentName:"p"},"VARCHAR(17)")," column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.macAddress("device");\n')),(0,i.kt)("h4",{id:"column-method-mediumBinary"},(0,i.kt)("inlineCode",{parentName:"h4"},"mediumBinary()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"mediumBinary")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"MEDIUMBLOB")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.mediumBinary("photo");\n')),(0,i.kt)("h4",{id:"column-method-mediumIncrements"},(0,i.kt)("inlineCode",{parentName:"h4"},"mediumIncrements()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"mediumIncrements")," method creates an auto-incrementing ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED MEDIUMINT")," equivalent column as a primary key:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.mediumIncrements("id");\n')),(0,i.kt)("h4",{id:"column-method-mediumInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"mediumInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"mediumInteger")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"MEDIUMINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.mediumInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-mediumText"},(0,i.kt)("inlineCode",{parentName:"h4"},"mediumText()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"mediumText")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"MEDIUMTEXT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.mediumText("description");\n')),(0,i.kt)("h4",{id:"column-method-multiLineString"},(0,i.kt)("inlineCode",{parentName:"h4"},"multiLineString()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"multiLineString")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"MULTILINESTRING")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.multiLineString("positions");\n')),(0,i.kt)("h4",{id:"column-method-multiPoint"},(0,i.kt)("inlineCode",{parentName:"h4"},"multiPoint()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"multiPoint")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"MULTIPOINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.multiPoint("positions");\n')),(0,i.kt)("h4",{id:"column-method-multiPolygon"},(0,i.kt)("inlineCode",{parentName:"h4"},"multiPolygon()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"multiPolygon")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"MULTIPOLYGON")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.multiPolygon("positions");\n')),(0,i.kt)("h4",{id:"column-method-point"},(0,i.kt)("inlineCode",{parentName:"h4"},"point()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"point")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"POINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.point("position");\n')),(0,i.kt)("h4",{id:"column-method-polygon"},(0,i.kt)("inlineCode",{parentName:"h4"},"polygon()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"polygon")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"POLYGON")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.polygon("position");\n')),(0,i.kt)("h4",{id:"column-method-rememberToken"},(0,i.kt)("inlineCode",{parentName:"h4"},"rememberToken()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"rememberToken")," method creates a nullable, ",(0,i.kt)("inlineCode",{parentName:"p"},"VARCHAR(100)"),' equivalent column that is intended to store the current "remember me" authentication token:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"table.rememberToken();\n")),(0,i.kt)("h4",{id:"column-method-set"},(0,i.kt)("inlineCode",{parentName:"h4"},"set()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"set")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"SET")," equivalent column with the given list of valid values:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.set("flavors", {"strawberry", "vanilla"});\n')),(0,i.kt)("h4",{id:"column-method-smallIncrements"},(0,i.kt)("inlineCode",{parentName:"h4"},"smallIncrements()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"smallIncrements")," method creates an auto-incrementing ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED SMALLINT")," equivalent column as a primary key:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.smallIncrements("id");\n')),(0,i.kt)("h4",{id:"column-method-smallInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"smallInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"smallInteger")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"SMALLINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.smallInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-softDeletes"},(0,i.kt)("inlineCode",{parentName:"h4"},"softDeletes()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"softDeletes")," method adds a nullable ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," ",(0,i.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," equivalent column with an optional precision (total digits). This column is intended to store the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at"),' timestamp needed for TinyORM\'s "soft delete" functionality:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.softDeletes("deleted_at", precision = 0);\n')),(0,i.kt)("h4",{id:"column-method-softDeletesDatetime"},(0,i.kt)("inlineCode",{parentName:"h4"},"softDeletesDatetime()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"softDeletesDatetime")," method adds a nullable ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," ",(0,i.kt)("inlineCode",{parentName:"p"},"DATETIME")," equivalent column with an optional precision (total digits). This column is intended to store the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at"),' timestamp needed for TinyORM\'s "soft delete" functionality:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.softDeletesDatetime("deleted_at", precision = 0);\n')),(0,i.kt)("h4",{id:"column-method-softDeletesTz"},(0,i.kt)("inlineCode",{parentName:"h4"},"softDeletesTz()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"softDeletesTz")," method adds a nullable ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," ",(0,i.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," (with timezone) equivalent column with an optional precision (total digits). This column is intended to store the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at"),' timestamp needed for TinyORM\'s "soft delete" functionality:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.softDeletesTz("deleted_at", precision = 0);\n')),(0,i.kt)("h4",{id:"column-method-string"},(0,i.kt)("inlineCode",{parentName:"h4"},"string()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"string")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"VARCHAR")," equivalent column of the given length:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#include \n\ntable.string(Orm::NAME, 100);\n")),(0,i.kt)("h4",{id:"column-method-text"},(0,i.kt)("inlineCode",{parentName:"h4"},"text()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"text")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"TEXT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.text("description");\n')),(0,i.kt)("h4",{id:"column-method-time"},(0,i.kt)("inlineCode",{parentName:"h4"},"time()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"time")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"TIME")," equivalent column with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.time("sunrise", precision = 0);\n')),(0,i.kt)("h4",{id:"column-method-timeTz"},(0,i.kt)("inlineCode",{parentName:"h4"},"timeTz()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"timeTz")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"TIME")," (with timezone) equivalent column with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.timeTz("sunrise", precision = 0);\n')),(0,i.kt)("h4",{id:"column-method-timestamp"},(0,i.kt)("inlineCode",{parentName:"h4"},"timestamp()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"timestamp")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," equivalent column with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.timestamp("added_at", precision = 0);\n')),(0,i.kt)("h4",{id:"column-method-timestampTz"},(0,i.kt)("inlineCode",{parentName:"h4"},"timestampTz()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"timestampTz")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," (with timezone) equivalent column with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.timestampTz("added_at", precision = 0);\n')),(0,i.kt)("h4",{id:"column-method-timestampsTz"},(0,i.kt)("inlineCode",{parentName:"h4"},"timestampsTz()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"timestampsTz")," method creates ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," ",(0,i.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," (with timezone) equivalent columns with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"table.timestampsTz(precision = 0);\n")),(0,i.kt)("h4",{id:"column-method-timestamps"},(0,i.kt)("inlineCode",{parentName:"h4"},"timestamps()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"timestamps")," method creates ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," ",(0,i.kt)("inlineCode",{parentName:"p"},"TIMESTAMP")," equivalent columns with an optional precision (total digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"table.timestamps(precision = 0);\n")),(0,i.kt)("h4",{id:"column-method-tinyBinary"},(0,i.kt)("inlineCode",{parentName:"h4"},"tinyBinary()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tinyBinary")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYBLOB")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.tinyBinary("photo");\n')),(0,i.kt)("h4",{id:"column-method-tinyIncrements"},(0,i.kt)("inlineCode",{parentName:"h4"},"tinyIncrements()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tinyIncrements")," method creates an auto-incrementing ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED TINYINT")," equivalent column as a primary key:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.tinyIncrements("id");\n')),(0,i.kt)("h4",{id:"column-method-tinyInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"tinyInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tinyInteger")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.tinyInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-tinyText"},(0,i.kt)("inlineCode",{parentName:"h4"},"tinyText()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tinyText")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYTEXT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.tinyText("notes");\n')),(0,i.kt)("h4",{id:"column-method-unsignedBigInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"unsignedBigInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"unsignedBigInteger")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED BIGINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.unsignedBigInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-unsignedDecimal"},(0,i.kt)("inlineCode",{parentName:"h4"},"unsignedDecimal()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"unsignedDecimal")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED DECIMAL")," equivalent column with an optional precision (total digits) and scale (decimal digits):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.unsignedDecimal("amount", precision = 8, scale = 2);\n')),(0,i.kt)("h4",{id:"column-method-unsignedInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"unsignedInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"unsignedInteger")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED INTEGER")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.unsignedInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-unsignedMediumInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"unsignedMediumInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"unsignedMediumInteger")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED MEDIUMINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.unsignedMediumInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-unsignedSmallInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"unsignedSmallInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"unsignedSmallInteger")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED SMALLINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.unsignedSmallInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-unsignedTinyInteger"},(0,i.kt)("inlineCode",{parentName:"h4"},"unsignedTinyInteger()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"unsignedTinyInteger")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED TINYINT")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.unsignedTinyInteger("votes");\n')),(0,i.kt)("h4",{id:"column-method-uuid"},(0,i.kt)("inlineCode",{parentName:"h4"},"uuid()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"uuid")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"UUID")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.uuid("id");\n')),(0,i.kt)("h4",{id:"column-method-year"},(0,i.kt)("inlineCode",{parentName:"h4"},"year()")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"year")," method creates a ",(0,i.kt)("inlineCode",{parentName:"p"},"YEAR")," equivalent column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.year("birth_year");\n'))),(0,i.kt)("h3",{id:"column-modifiers"},"Column Modifiers"),(0,i.kt)("p",null,'In addition to the column types listed above, there are several column "modifiers" you may use when adding a column to a database table. For example, to make the column "nullable", you may use the ',(0,i.kt)("inlineCode",{parentName:"p"},"nullable")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.string("email").nullable();\n});\n')),(0,i.kt)("p",null,"The following table contains all of the available column modifiers. This list does not include ",(0,i.kt)("a",{parentName:"p",href:"#creating-indexes"},"index modifiers"),":"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"Modifier"),(0,i.kt)("th",{parentName:"tr",align:null},"Description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'.after("column")')),(0,i.kt)("td",{parentName:"tr",align:null},'Place the column "after" another column ',(0,i.kt)("small",null,"(MySQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".autoIncrement()")),(0,i.kt)("td",{parentName:"tr",align:null},"Set INTEGER columns as auto-incrementing (primary key).")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'.charset("utf8mb4")')),(0,i.kt)("td",{parentName:"tr",align:null},"Specify a character set for the column ",(0,i.kt)("small",null,"(MySQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("small",null,(0,i.kt)("inlineCode",{parentName:"td"},'.collation("utf8mb4_unicode_ci")'))),(0,i.kt)("td",{parentName:"tr",align:null},"Specify a collation for the column ",(0,i.kt)("small",null,"(MySQL/PostgreSQL/SQL Server)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'.comment("my comment")')),(0,i.kt)("td",{parentName:"tr",align:null},"Add a comment to a column ",(0,i.kt)("small",null,"(MySQL / PostgreSQL)"),".",(0,i.kt)("br",null),(0,i.kt)("small",null,"Special characters are escaped."))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".defaultValue(value)")),(0,i.kt)("td",{parentName:"tr",align:null},'Specify a "default" value for the column.',(0,i.kt)("br",null),(0,i.kt)("small",null,"Special characters are escaped."))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".first()")),(0,i.kt)("td",{parentName:"tr",align:null},'Place the column "first" in the table ',(0,i.kt)("small",null,"(MySQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".from(integer)")),(0,i.kt)("td",{parentName:"tr",align:null},"Set the starting value of an auto-incrementing field, an alias for ",(0,i.kt)("inlineCode",{parentName:"td"},"startingValue()")," ",(0,i.kt)("small",null,"(MySQL / PostgreSQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".invisible()")),(0,i.kt)("td",{parentName:"tr",align:null},'Make the column "invisible" to ',(0,i.kt)("inlineCode",{parentName:"td"},"SELECT *")," queries ",(0,i.kt)("small",null,"(MySQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".nullable(value = true)")),(0,i.kt)("td",{parentName:"tr",align:null},"Allow NULL values to be inserted into the column.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".startingValue(integer)")),(0,i.kt)("td",{parentName:"tr",align:null},"Set the starting value of an auto-incrementing field ",(0,i.kt)("small",null,"(MySQL / PostgreSQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".storedAs(expression)")),(0,i.kt)("td",{parentName:"tr",align:null},"Create a stored generated column ",(0,i.kt)("small",null,"(MySQL / PostgreSQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".unsigned()")),(0,i.kt)("td",{parentName:"tr",align:null},"Set INTEGER columns as UNSIGNED ",(0,i.kt)("small",null,"(MySQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".useCurrent()")),(0,i.kt)("td",{parentName:"tr",align:null},"Set TIMESTAMP columns to use CURRENT_TIMESTAMP as default value.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".useCurrentOnUpdate()")),(0,i.kt)("td",{parentName:"tr",align:null},"Set TIMESTAMP columns to use CURRENT_TIMESTAMP when a record is updated.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".virtualAs(expression)")),(0,i.kt)("td",{parentName:"tr",align:null},"Create a virtual generated column ",(0,i.kt)("small",null,"(MySQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".generatedAs(expression)")),(0,i.kt)("td",{parentName:"tr",align:null},"Create an identity column with specified sequence options ",(0,i.kt)("small",null,"(PostgreSQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".always()")),(0,i.kt)("td",{parentName:"tr",align:null},"Defines the precedence of sequence values over input for an identity column ",(0,i.kt)("small",null,"(PostgreSQL)"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".isGeometry()")),(0,i.kt)("td",{parentName:"tr",align:null},"Set spatial column type to ",(0,i.kt)("inlineCode",{parentName:"td"},"geometry")," - the default type is ",(0,i.kt)("inlineCode",{parentName:"td"},"geography")," ",(0,i.kt)("small",null,"(PostgreSQL)"),".")))),(0,i.kt)("h4",{id:"default-expressions"},"Default Expressions"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"defaultValue")," modifier accepts a value or an ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Query::Expression")," instance. Using an ",(0,i.kt)("inlineCode",{parentName:"p"},"Expression")," instance will prevent TinyORM from wrapping the value in quotes and allow you to use database-specific functions. One situation where this is particularly useful is when you need to assign default values to JSON columns:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Query::Expression;\n\nSchema::create("flights", [](Blueprint &table)\n{\n table.id();\n table.json("detail").defaultValue(Expression("(JSON_ARRAY(\'none\'))"));\n table.timestamps();\n});\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"Support for default expressions depends on your database driver, database version, and the field type. Please refer to your database's documentation.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can obtain an ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Query::Expression")," using the ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder#raw-expressions"},(0,i.kt)("inlineCode",{parentName:"a"},"DB::raw"))," method if you have access to the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade.")),(0,i.kt)("h4",{id:"column-order"},"Column Order"),(0,i.kt)("p",null,"When using the MySQL database, the ",(0,i.kt)("inlineCode",{parentName:"p"},"after")," method may be used to add columns after an existing column in the schema:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.after("password", [](Blueprint &table)\n{\n table.string("address_line1");\n table.string("address_line2");\n table.string("city");\n});\n')),(0,i.kt)("h3",{id:"modifying-columns"},"Modifying Columns"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"change")," method allows you to modify the type and attributes of existing columns. For example, you may wish to increase the size of a ",(0,i.kt)("inlineCode",{parentName:"p"},"string")," column. To see the ",(0,i.kt)("inlineCode",{parentName:"p"},"change")," method in action, let's increase the size of the ",(0,i.kt)("inlineCode",{parentName:"p"},"name")," column from 25 to 50. To accomplish this, we simply define the new state of the column and then call the ",(0,i.kt)("inlineCode",{parentName:"p"},"change")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.string("name", 50).change();\n});\n')),(0,i.kt)("p",null,"When modifying a column, you must explicitly include all of the modifiers you want to keep on the column definition - any missing attribute will be dropped. For example, to retain the ",(0,i.kt)("inlineCode",{parentName:"p"},"unsigned"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"default"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"comment")," attributes, you must call each modifier explicitly when changing the column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("users", [](Blueprint &table)\n{\n table.integer("votes").isUnsigned().defaultValue(1).comment("my comment").change();\n});\n')),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"change")," method and modifying columns is not implemented for the ",(0,i.kt)("inlineCode",{parentName:"p"},"SQLite")," database because it doesn't support modifying columns out of the box.")),(0,i.kt)("h4",{id:"renaming-columns"},"Renaming Columns"),(0,i.kt)("p",null,"To rename a column, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"renameColumn")," method provided by the schema builder blueprint:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("users", [](Blueprint &table)\n{\n table.renameColumn("from", "to");\n});\n')),(0,i.kt)("h4",{id:"renaming-columns-on-legacy-databases"},"Renaming Columns On Legacy Databases"),(0,i.kt)("p",null,"Renaming columns is not supported if you are running a database installation older than one of the following releases:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"MySQL ",(0,i.kt)("inlineCode",{parentName:"li"},"<8.0.3")),(0,i.kt)("li",{parentName:"ul"},"MariaDB ",(0,i.kt)("inlineCode",{parentName:"li"},"<10.5.2")),(0,i.kt)("li",{parentName:"ul"},"SQLite ",(0,i.kt)("inlineCode",{parentName:"li"},"<3.25.0"))),(0,i.kt)("h3",{id:"dropping-columns"},"Dropping Columns"),(0,i.kt)("p",null,"To drop a column, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"dropColumn")," method on the schema builder blueprint:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("users", [](Blueprint &table)\n{\n table.dropColumn("votes");\n});\n')),(0,i.kt)("p",null,"You may drop multiple columns from a table by passing a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," of column names to the ",(0,i.kt)("inlineCode",{parentName:"p"},"dropColumns")," method, the ",(0,i.kt)("inlineCode",{parentName:"p"},"dropColumns")," method also provides parameter pack overload:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("users", [](Blueprint &table)\n{\n table.dropColumns({"votes", "avatar", "location"});\n // Parameter pack overload\n table.dropColumns("votes", "avatar", "location");\n});\n')),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"The SQLite prior to ",(0,i.kt)("inlineCode",{parentName:"p"},"v3.35.0")," doesn't support dropping columns using the ",(0,i.kt)("inlineCode",{parentName:"p"},"ALTER TABLE DROP COLUMN"),", dropping columns was added in the SQLite ",(0,i.kt)("inlineCode",{parentName:"p"},"v3.35.0")," as is described in the ",(0,i.kt)("a",{parentName:"p",href:"https://www.sqlite.org/releaselog/3_35_0.html"},"release notes"),".")),(0,i.kt)("h4",{id:"available-command-aliases"},"Available Command Aliases"),(0,i.kt)("p",null,"TinyORM provides several convenient methods related to dropping common types of columns. Each of these methods is described in the table below:"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"Command"),(0,i.kt)("th",{parentName:"tr",align:null},"Description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.dropRememberToken();")),(0,i.kt)("td",{parentName:"tr",align:null},"Drop the ",(0,i.kt)("inlineCode",{parentName:"td"},"remember_token")," column.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.dropSoftDeletes();")),(0,i.kt)("td",{parentName:"tr",align:null},"Drop the ",(0,i.kt)("inlineCode",{parentName:"td"},"deleted_at")," column.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.dropSoftDeletesDatetime();")),(0,i.kt)("td",{parentName:"tr",align:null},"Alias of ",(0,i.kt)("inlineCode",{parentName:"td"},"dropSoftDeletes()")," method.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.dropSoftDeletesTz();")),(0,i.kt)("td",{parentName:"tr",align:null},"Alias of ",(0,i.kt)("inlineCode",{parentName:"td"},"dropSoftDeletes()")," method.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.dropTimestamps();")),(0,i.kt)("td",{parentName:"tr",align:null},"Drop the ",(0,i.kt)("inlineCode",{parentName:"td"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"td"},"updated_at")," columns.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.dropTimestampsTz();")),(0,i.kt)("td",{parentName:"tr",align:null},"Alias of ",(0,i.kt)("inlineCode",{parentName:"td"},"dropTimestamps()")," method.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.dropDatetimes();")),(0,i.kt)("td",{parentName:"tr",align:null},"Alias of ",(0,i.kt)("inlineCode",{parentName:"td"},"dropTimestamps()")," method.")))),(0,i.kt)("h2",{id:"indexes"},"Indexes"),(0,i.kt)("h3",{id:"creating-indexes"},"Creating Indexes"),(0,i.kt)("p",null,"The TinyORM schema builder supports several types of indexes. The following example creates a new ",(0,i.kt)("inlineCode",{parentName:"p"},"email")," column and specifies that its values should be unique. To create the index, we can chain the ",(0,i.kt)("inlineCode",{parentName:"p"},"unique")," method onto the column definition:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nSchema::table("users", [](Blueprint &table)\n{\n table.string("email").unique();\n});\n')),(0,i.kt)("p",null,"Alternatively, you may create the index after defining the column. To do so, you should call the ",(0,i.kt)("inlineCode",{parentName:"p"},"unique")," method on the schema builder blueprint. This method accepts the name of the column that should receive a unique index:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.unique("email");\n')),(0,i.kt)("p",null,"You may even pass a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," of columns to an index method to create a compound (or composite) index:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.index({"account_id", "created_at"});\n')),(0,i.kt)("p",null,"When creating an index, TinyORM will automatically generate an index name based on the table, column names, and the index type (eg. users_email_unique), but you may pass a second argument to the method to specify the index name yourself:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.unique("email", "unique_email");\n')),(0,i.kt)("h4",{id:"available-index-types"},"Available Index Types"),(0,i.kt)("p",null,"TinyORM's schema builder blueprint class provides methods for creating each type of index supported by TinyORM. Each index method accepts an optional second argument to specify the name of the index. If omitted, the name will be derived from the names of the table and column(s) used for the index, as well as the index type (eg. users_email_fulltext). Each of the available index methods is described in the table below:"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"Command"),(0,i.kt)("th",{parentName:"tr",align:null},"Description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.primary("id");')),(0,i.kt)("td",{parentName:"tr",align:null},"Adds a primary key.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.primary({"id", "parent_id"});')),(0,i.kt)("td",{parentName:"tr",align:null},"Adds composite keys.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.unique("email");')),(0,i.kt)("td",{parentName:"tr",align:null},"Adds a unique index.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.index("state");')),(0,i.kt)("td",{parentName:"tr",align:null},"Adds an index.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.fullText("body");')),(0,i.kt)("td",{parentName:"tr",align:null},"Adds a full text index (MySQL/PostgreSQL).")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("small",null,(0,i.kt)("inlineCode",{parentName:"td"},'table.fullText("body").language("english");'))),(0,i.kt)("td",{parentName:"tr",align:null},"Adds a full text index of the specified language (PostgreSQL).")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.spatialIndex("location");')),(0,i.kt)("td",{parentName:"tr",align:null},"Adds a spatial index (except SQLite).")))),(0,i.kt)("h4",{id:"index-lengths--mysql--mariadb"},"Index Lengths & MySQL / MariaDB"),(0,i.kt)("p",null,"By default, TinyORM uses the ",(0,i.kt)("inlineCode",{parentName:"p"},"utf8mb4")," character set. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure the default string length by calling the ",(0,i.kt)("inlineCode",{parentName:"p"},"Schema::defaultStringLength")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#include \n\nSchema::defaultStringLength(191);\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"Alternatively, you may enable the ",(0,i.kt)("inlineCode",{parentName:"p"},"innodb_large_prefix")," option for your database (enabled by default in >=MySQL 5.7.7). Refer to your database's documentation for instructions on how to properly enable this option.")),(0,i.kt)("h3",{id:"renaming-indexes"},"Renaming Indexes"),(0,i.kt)("p",null,"To rename an index, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"renameIndex")," method provided by the schema builder blueprint. This method accepts the current index name as its first argument and the desired name as its second argument:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.renameIndex("from", "to");\n')),(0,i.kt)("h3",{id:"dropping-indexes"},"Dropping Indexes"),(0,i.kt)("p",null,"To drop an index, you must specify the index's name. By default, TinyORM automatically assigns an index name based on the table name, the name of the indexed column, and the index type (eg. users_email_unique). Here are some examples:"),(0,i.kt)("div",{id:"apitable-dropping-indexes"},(0,i.kt)(l.Z,{mdxType:"APITable"},(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"Command"),(0,i.kt)("th",{parentName:"tr",align:null},"Description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.dropPrimary("users_id_primary");')),(0,i.kt)("td",{parentName:"tr",align:null},'Drop a primary key from the "users" table.')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.dropUnique("users_email_unique");')),(0,i.kt)("td",{parentName:"tr",align:null},'Drop a unique index from the "users" table.')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},'table.dropIndex("geo_state_index");')),(0,i.kt)("td",{parentName:"tr",align:null},'Drop a basic index from the "geo" table.')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("small",null,(0,i.kt)("inlineCode",{parentName:"td"},'table.dropFullText("posts_body_fulltext");'))),(0,i.kt)("td",{parentName:"tr",align:null},'Drop a full text index from the "posts" table.')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("small",null,(0,i.kt)("inlineCode",{parentName:"td"},'.dropSpatialIndex("geo_location_spatialindex");'))),(0,i.kt)("td",{parentName:"tr",align:null},'Drop a spatial index from the "geo" table (except SQLite).')))))),(0,i.kt)("p",null,"I may also drop indexes by a column name or column names for composite keys, if you pass a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," of columns into a method that drops indexes, the conventional index name will be generated based on the table name, columns, and index type:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("geo", [](Blueprint &table)\n{\n table.dropIndex({"state"}); // Drops index \'geo_state_index\'\n});\n')),(0,i.kt)("h3",{id:"foreign-key-constraints"},"Foreign Key Constraints"),(0,i.kt)("p",null,"TinyORM also provides support for creating foreign key constraints, which are used to force referential integrity at the database level. For example, let's define a ",(0,i.kt)("inlineCode",{parentName:"p"},"user_id")," column on the ",(0,i.kt)("inlineCode",{parentName:"p"},"posts")," table that references the ",(0,i.kt)("inlineCode",{parentName:"p"},"id")," column on a ",(0,i.kt)("inlineCode",{parentName:"p"},"users")," table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Constants::ID;\n\nSchema::table("posts", [](Blueprint &table)\n{\n table.unsignedBigInteger("user_id");\n\n table.foreign("user_id").references(ID).on("users");\n});\n')),(0,i.kt)("p",null,"Since this syntax is rather verbose, TinyORM provides additional, terser methods that use conventions to provide a better developer experience. When using the ",(0,i.kt)("inlineCode",{parentName:"p"},"foreignId")," method to create your column, the example above can be rewritten like so:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("posts", [](Blueprint &table)\n{\n table.foreignId("user_id").constrained();\n});\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"foreignId")," method creates an ",(0,i.kt)("inlineCode",{parentName:"p"},"UNSIGNED BIGINT")," equivalent column, while the ",(0,i.kt)("inlineCode",{parentName:"p"},"constrained")," method will use conventions to determine the table and column name being referenced. If your table name does not match TinyORM's conventions, you may specify the table name by passing it as an argument to the ",(0,i.kt)("inlineCode",{parentName:"p"},"constrained")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("posts", [](Blueprint &table)\n{\n table.foreignId("user_id").constrained("users");\n});\n')),(0,i.kt)("p",null,'You may also specify the desired action for the "on delete" and "on update" properties of the constraint:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::SchemaNs::Constants::Cascade;\n\ntable.foreignId("user_id")\n .constrained()\n .onUpdate("cascade")\n .onDelete(Cascade);\n')),(0,i.kt)("p",null,"An alternative, expressive syntax is also provided for these actions:"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"Method"),(0,i.kt)("th",{parentName:"tr",align:null},"Description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.cascadeOnUpdate();")),(0,i.kt)("td",{parentName:"tr",align:null},"Updates should cascade.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.restrictOnUpdate();")),(0,i.kt)("td",{parentName:"tr",align:null},"Updates should be restricted.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.cascadeOnDelete();")),(0,i.kt)("td",{parentName:"tr",align:null},"Deletes should cascade.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.restrictOnDelete();")),(0,i.kt)("td",{parentName:"tr",align:null},"Deletes should be restricted.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"table.nullOnDelete();")),(0,i.kt)("td",{parentName:"tr",align:null},"Deletes should set the foreign key value to null.")))),(0,i.kt)("p",null,"Any additional ",(0,i.kt)("a",{parentName:"p",href:"#column-modifiers"},"column modifiers")," must be called before the ",(0,i.kt)("inlineCode",{parentName:"p"},"constrained")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.foreignId("user_id")\n .nullable()\n .constrained();\n')),(0,i.kt)("h4",{id:"dropping-foreign-keys"},"Dropping Foreign Keys"),(0,i.kt)("p",null,"To drop a foreign key, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"dropForeign"),' method, passing the name of the foreign key constraint to be deleted as an argument. Foreign key constraints use the same naming convention as indexes. In other words, the foreign key constraint name is based on the name of the table and the columns in the constraint, followed by a "_foreign" suffix:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.dropForeign("posts_user_id_foreign");\n')),(0,i.kt)("p",null,"Alternatively, you may pass a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," containing the column name that holds the foreign key to the ",(0,i.kt)("inlineCode",{parentName:"p"},"dropForeign")," method. The ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," will be converted to a foreign key constraint name using TinyORM's constraint naming conventions:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'table.dropForeign({"user_id"});\n')),(0,i.kt)("h4",{id:"toggling-foreign-key-constraints"},"Toggling Foreign Key Constraints"),(0,i.kt)("p",null,"You may enable or disable foreign key constraints within your migrations by using the following methods:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"Schema::enableForeignKeyConstraints();\n\nSchema::disableForeignKeyConstraints();\n\nSchema::withoutForeignKeyConstraints([]\n{\n // Constraints disabled within this lambda expression...\n});\n")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"The SQLite disables foreign key constraints by default. When using SQLite, make sure to ",(0,i.kt)("a",{parentName:"p",href:"/database/getting-started#sqlite-configuration"},"enable foreign key support")," in your database configuration before attempting to create them in your migrations. In addition, SQLite only supports creating foreign keys when creating tables and ",(0,i.kt)("a",{parentName:"p",href:"https://www.sqlite.org/omitted.html"},"not when tables are altered"),".")))}b.isMDXComponent=!0},9566:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/tom_cli-402f7dd4dfe7dbd0b20dfe5fb61838a2.png"}}]); \ No newline at end of file diff --git a/assets/js/3dd307b5.7b464df0.js b/assets/js/3dd307b5.7b464df0.js new file mode 100644 index 000000000..1cc1a9262 --- /dev/null +++ b/assets/js/3dd307b5.7b464df0.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[108],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>c});var o=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function l(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=o.createContext({}),d=function(e){var t=o.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=d(e.components);return o.createElement(s.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return o.createElement(o.Fragment,{},t)}},h=o.forwardRef((function(e,t){var n=e.components,a=e.mdxType,r=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),m=d(n),h=a,c=m["".concat(s,".").concat(h)]||m[h]||u[h]||r;return n?o.createElement(c,l(l({ref:t},p),{},{components:n})):o.createElement(c,l({ref:t},p))}));function c(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var r=n.length,l=new Array(r);l[0]=h;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[m]="string"==typeof e?e:a,l[1]=i;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>i,toc:()=>d});var o=n(7462),a=(n(7294),n(3905));const r={sidebar_position:2,sidebar_label:"Collections",description:"The ModelsCollection is specialized container which provides a fluent, convenient wrapper for working with vector of models. Is much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. All TinyORM methods that return more than one model result will return instances of the ModelsCollection class.",keywords:["c++ orm","orm","collections","collection","model","tinyorm"]},l="TinyORM: Collections",i={unversionedId:"tinyorm/collections",id:"tinyorm/collections",title:"TinyORM: Collections",description:"The ModelsCollection is specialized container which provides a fluent, convenient wrapper for working with vector of models. Is much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. All TinyORM methods that return more than one model result will return instances of the ModelsCollection class.",source:"@site/docs/tinyorm/collections.mdx",sourceDirName:"tinyorm",slug:"/tinyorm/collections",permalink:"/tinyorm/collections",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinyorm/collections.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,sidebar_label:"Collections",description:"The ModelsCollection is specialized container which provides a fluent, convenient wrapper for working with vector of models. Is much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. All TinyORM methods that return more than one model result will return instances of the ModelsCollection class.",keywords:["c++ orm","orm","collections","collection","model","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Relationships",permalink:"/tinyorm/relationships"},next:{title:"Casts",permalink:"/tinyorm/casts"}},s={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Collection Conversion",id:"collection-conversion",level:4},{value:"Creating Collections",id:"creating-collections",level:3},{value:"Available Methods",id:"available-methods",level:2},{value:"all()",id:"method-all",level:4},{value:"contains()",id:"method-contains",level:4},{value:"doesntContain()",id:"method-doesntcontain",level:4},{value:"each()",id:"method-each",level:4},{value:"except()",id:"method-except",level:4},{value:"filter()",id:"method-filter",level:4},{value:"find()",id:"method-find",level:4},{value:"first()",id:"method-first",level:4},{value:"firstWhere()",id:"method-first-where",level:4},{value:"fresh()",id:"method-fresh",level:4},{value:"implode()",id:"method-implode",level:4},{value:"isEmpty()",id:"method-isempty",level:4},{value:"isNotEmpty()",id:"method-isnotempty",level:4},{value:"last()",id:"method-last",level:4},{value:"load()",id:"method-load",level:4},{value:"map()",id:"method-map",level:4},{value:"mapWithKeys()",id:"method-mapwithkeys",level:4},{value:"mapWithModelKeys()",id:"method-mapwithmodelkeys",level:4},{value:"modelKeys()",id:"method-modelkeys",level:4},{value:"only()",id:"method-only",level:4},{value:"pluck()",id:"method-pluck",level:4},{value:"reject()",id:"method-reject",level:4},{value:"sort()",id:"method-sort",level:4},{value:"sortBy()",id:"method-sortby",level:4},{value:"sortByDesc()",id:"method-sortbydesc",level:4},{value:"sortDesc()",id:"method-sortdesc",level:4},{value:"stableSort()",id:"method-stablesort",level:4},{value:"stableSortBy()",id:"method-stablesortby",level:4},{value:"stableSortByDesc()",id:"method-stablesortbydesc",level:4},{value:"stableSortDesc()",id:"method-stablesortdesc",level:4},{value:"tap()",id:"method-tap",level:4},{value:"toBase()",id:"method-tobase",level:4},{value:"toJson()",id:"method-tojson",level:4},{value:"toJsonArray()",id:"method-tojsonarray",level:4},{value:"toJsonDocument()",id:"method-tojsondocument",level:4},{value:"toMap()",id:"method-tomap",level:4},{value:"toMapVariantList()",id:"method-tomapvariantlist",level:4},{value:"toQuery()",id:"method-toquery",level:4},{value:"toVector()",id:"method-tovector",level:4},{value:"toVectorVariantList()",id:"method-tovectorvariantlist",level:4},{value:"unique()",id:"method-unique",level:4},{value:"uniqueBy()",id:"method-uniqueby",level:4},{value:"uniqueRelaxed()",id:"method-uniquerelaxed",level:4},{value:"uniqueRelaxedBy()",id:"method-uniquerelaxedby",level:4},{value:"value()",id:"method-value",level:4},{value:"where()",id:"method-where",level:4},{value:"whereBetween()",id:"method-wherebetween",level:4},{value:"whereIn()",id:"method-wherein",level:4},{value:"whereNotBetween()",id:"method-wherenotbetween",level:4},{value:"whereNotIn()",id:"method-wherenotin",level:4},{value:"whereNotNull()",id:"method-wherenotnull",level:4},{value:"whereNull()",id:"method-wherenull",level:4}],p={toc:d},m="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,o.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"tinyorm-collections"},"TinyORM: Collections"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#introduction"},"Introduction"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#creating-collections"},"Creating Collections")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#available-methods"},"Available Methods"))),(0,a.kt)("h2",{id:"introduction"},"Introduction"),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Types::ModelsCollection")," is specialized container which provides a fluent, convenient wrapper for working with vector of models. All TinyORM methods that return more than one model result, will return instances of the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," class, including results retrieved via the ",(0,a.kt)("inlineCode",{parentName:"p"},"get")," method or methods that return relationships like the ",(0,a.kt)("inlineCode",{parentName:"p"},"getRelation")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"getRelationValue"),"."),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," class extends ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),", so it naturally inherits dozens of methods used to work with the underlying vector of TinyORM models. Be sure to review the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qlist.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QList"))," documentation to learn all about these helpful methods!"),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," template parameter can be declared only with the model type or a model type pointer, it also can't be ",(0,a.kt)("inlineCode",{parentName:"p"},"const")," and can't be a reference. It's constrained using the ",(0,a.kt)("inlineCode",{parentName:"p"},"DerivedCollectionModel")," concept.")),(0,a.kt)("p",null,"You can iterate over the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," the same way as over the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using Models::User;\n\nModelsCollection users = User::whereEq("active", true)->get();\n\nfor (const auto &user : users)\n qDebug() << user.getAttribute("name");\n')),(0,a.kt)("p",null,"However, as previously mentioned, collections are much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. For example, we may remove all active users and then gather the first name of each remaining user:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto names = User::all().reject([](User *const user)\n{\n return user->getAttribute("active");\n})\n .pluck("name");\n')),(0,a.kt)("p",null,"As you can see, the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," class allows you to chain its methods to perform fluent mapping and reducing of the underlying vector. In general, collections are immutable, meaning every ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," method returns an entirely new ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," instance."),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," is returning from the Models' methods like ",(0,a.kt)("inlineCode",{parentName:"p"},"get"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"all"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"findMany"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"chunk"),"; the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," is returning from the relationship-related methods as ",(0,a.kt)("inlineCode",{parentName:"p"},"getRelation")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"getRelationValue"),".")),(0,a.kt)("h4",{id:"collection-conversion"},"Collection Conversion"),(0,a.kt)("p",null,"While most TinyORM collection methods return a new instance of ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection"),", the ",(0,a.kt)("inlineCode",{parentName:"p"},"modelKeys"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"mapWithKeys"),", and ",(0,a.kt)("inlineCode",{parentName:"p"},"pluck")," methods return a base QVector or std unordered/map instances. Likewise, one of the ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," methods overload returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),"."),(0,a.kt)("h3",{id:"creating-collections"},"Creating Collections"),(0,a.kt)("p",null,"Creating a ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," is as simple as:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n};\n')),(0,a.kt)("p",null,"You can also create a collection of pointers, eg. ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection userPointers {\n &users[0], &users[1],\n};\n")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," is implicitly convertible and assignable from the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'QVector usersVector {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n};\n\nModelsCollection users(usersVector);\nusers = usersVector;\n')),(0,a.kt)("p",null,"Alternatively, you can use the ",(0,a.kt)("inlineCode",{parentName:"p"},"Orm::collect")," helper function to create a ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," from the given attributes:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users = Orm::collect({\n {{"name", "Kate"}, {"added_on", QDateTime::currentDateTimeUtc()}},\n {{"name", "John"}, {"added_on", QDateTime({2023, 6, 1}, {13, 46, 15}, Qt::UTC)}},\n});\n')),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"Orm::collect")," function is ",(0,a.kt)("strong",{parentName:"p"},"mandatory")," if your attributes contain the ",(0,a.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance, you can read more about this problem ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/getting-started#qdatetime-and-connection-name-problem"},"here"),".")),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The results of ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/getting-started"},"TinyORM")," queries are always returned as ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," instances.")),(0,a.kt)("h2",{id:"available-methods"},"Available Methods"),(0,a.kt)("p",null,"For the majority of the remaining collection documentation, we'll discuss each method available on the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," class. Remember, all of these methods may be chained to fluently manipulate the underlying vector."),(0,a.kt)("p",null,"Furthermore, almost every method returns a new ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," instance, allowing you to preserve the original copy of the collection when necessary:"),(0,a.kt)("div",{class:"collection-methods-list"},(0,a.kt)("p",null,(0,a.kt)("a",{parentName:"p",href:"#method-all"},"all"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-contains"},"contains"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-doesntcontain"},"doesntContain"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-each"},"each"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-except"},"except"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-filter"},"filter"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-find"},"find"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-first"},"first"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-first-where"},"firstWhere"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-fresh"},"fresh"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-implode"},"implode"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-isempty"},"isEmpty"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-isnotempty"},"isNotEmpty"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-last"},"last"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-load"},"load"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-map"},"map"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-mapwithkeys"},"mapWithKeys"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-mapwithmodelkeys"},"mapWithModelKeys"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-modelkeys"},"modelKeys"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-only"},"only"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-pluck"},"pluck"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-reject"},"reject"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-sort"},"sort"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-sortby"},"sortBy"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-sortbydesc"},"sortByDesc"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-sortdesc"},"sortDesc"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-stablesort"},"stableSort"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-stablesortby"},"stableSortBy"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-stablesortbydesc"},"stableSortByDesc"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-stablesortdesc"},"stableSortDesc"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tap"},"tap"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tobase"},"toBase"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tojson"},"toJson"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tojsonarray"},"toJsonArray"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tojsondocument"},"toJsonDocument"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tomap"},"toMap"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tomapvariantlist"},"toMapVariantList"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-toquery"},"toQuery"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tovector"},"toVector"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tovectorvariantlist"},"toVectorVariantList"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-unique"},"unique"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-uniqueby"},"uniqueBy"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-uniquerelaxed"},"uniqueRelaxed"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-uniquerelaxedby"},"uniqueRelaxedBy"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-value"},"value"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-where"},"where"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherebetween"},"whereBetween"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherein"},"whereIn"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherenotbetween"},"whereNotBetween"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherenotin"},"whereNotIn"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherenotnull"},"whereNotNull"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherenull"},"whereNull"))),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"For a better understanding of the following examples, many of the variable declarations below use actual types instead of the ",(0,a.kt)("inlineCode",{parentName:"p"},"auto")," keyword.")),(0,a.kt)("div",{class:"collection-methods"},(0,a.kt)("h4",{id:"method-all"},(0,a.kt)("inlineCode",{parentName:"h4"},"all()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"all")," method returns a copy of the underlying vector represented by the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"QVector = users.all();\n")),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("a",{parentName:"p",href:"#method-tobase"},(0,a.kt)("inlineCode",{parentName:"a"},"toBase"))," is an alias to the ",(0,a.kt)("inlineCode",{parentName:"p"},"all")," method.")),(0,a.kt)("h4",{id:"method-contains"},(0,a.kt)("inlineCode",{parentName:"h4"},"contains()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"contains")," method may be used to determine if a given model instance is contained by the collection. This method accepts a primary key or a model instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.contains(1);\n\nusers.contains(User::find(1));\n")),(0,a.kt)("p",null,"Alternatively, you may pass a lambda expression to the ",(0,a.kt)("inlineCode",{parentName:"p"},"contains")," method to determine if a model exists in the collection matching a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.contains([](const User *const user)\n{\n return user->getKeyCasted() == 2;\n});\n")),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"contains"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-doesntcontain"},"doesntContain")," method."),(0,a.kt)("h4",{id:"method-doesntcontain"},(0,a.kt)("inlineCode",{parentName:"h4"},"doesntContain()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"doesntContain")," method determines whether the collection does not contain a given item. This method accepts a primary key or a model instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.doesntContain(1);\n\nusers.doesntContain(User::find(1));\n")),(0,a.kt)("p",null,"Alternatively, you may pass a lambda expression to the ",(0,a.kt)("inlineCode",{parentName:"p"},"doesntContain")," method to determine if a model does not exist in the collection matching a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.doesntContain([](const User *const user)\n{\n return user->getKeyCasted() == 2;\n});\n")),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"doesntContain"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-contains"},"contains")," method."),(0,a.kt)("h4",{id:"method-each"},(0,a.kt)("inlineCode",{parentName:"h4"},"each()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"each")," method iterates over the models in the collection and passes each model to the lambda expression:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users = Post::whereEq("user_id", 1)->get();\n\nusers.each([](User *const user)\n{\n // ...\n});\n')),(0,a.kt)("p",null,"If you would like to stop iterating through the models, you may return ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," from your lambda expression:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.each([](User *const user)\n{\n if (/* condition */)\n return false;\n\n // Some logic\n\n return true;\n});\n")),(0,a.kt)("p",null,"You may also pass the lambda expression with two parameters, whereas the second one is an index:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.each([](User *const user, const std::size_t index)\n{\n // ...\n});\n")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"each")," method returns an lvalue ",(0,a.kt)("strong",{parentName:"p"},"reference")," to the currently processed collection."),(0,a.kt)("p",null,"It can be also called on ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," rvalues, it returns an rvalue reference in this case."),(0,a.kt)("h4",{id:"method-except"},(0,a.kt)("inlineCode",{parentName:"h4"},"except()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"except")," method returns all of the models that do not have the given primary keys:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection usersResult = users.except({1, 2, 3});\n")),(0,a.kt)("p",null,"All of the models are returned if the ",(0,a.kt)("inlineCode",{parentName:"p"},"ids")," argument is empty ",(0,a.kt)("inlineCode",{parentName:"p"},"except({})"),"."),(0,a.kt)("p",null,"The order of models in the collection is preserved."),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"except"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-only"},"only")," method."),(0,a.kt)("h4",{id:"method-filter"},(0,a.kt)("inlineCode",{parentName:"h4"},"filter()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"filter")," method filters the collection using the lambda expression, keeping only those models that pass a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto usersBanned = users.filter([](const User *const user)\n{\n return user->getAttribute("is_banned");\n});\n')),(0,a.kt)("p",null,"You may also pass the lambda expression with two parameters, whereas the second one is an index:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto usersBanned = users.filter([](const User *const user,\n const std::size_t index)\n{\n return index < 10 && user->getAttribute("is_banned");\n});\n')),(0,a.kt)("p",null,"If no lambda expression is supplied, all models of the collection that are equivalent to the ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr")," will be removed:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection usersRaw = User::findMany({1, 2});\nModelsCollection users {&usersRaw[0], nullptr, &usersRaw[1]};\n\nModelsCollection filtered = users.filter();\n\n// {1, 2}\n")),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"filter"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-reject"},"reject")," method."),(0,a.kt)("h4",{id:"method-find"},(0,a.kt)("inlineCode",{parentName:"h4"},"find()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"find")," method returns the model that has a primary key matching the given key:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"User *const user = users.find(1);\n")),(0,a.kt)("p",null,"If you pass a model instance, ",(0,a.kt)("inlineCode",{parentName:"p"},"find")," will attempt to return a model matching the primary key:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"User *user = users.find(anotherUser);\n")),(0,a.kt)("p",null,"The two overloads above also accept the second ",(0,a.kt)("inlineCode",{parentName:"p"},"defaultModel")," model argument, which will be returned if a model was not found in the collection, its default value is the ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr"),"."),(0,a.kt)("p",null,"Alternatively, may pass more IDs and ",(0,a.kt)("inlineCode",{parentName:"p"},"find")," will return all models which have a primary key within the given unordered set:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection usersMany = users.find({1, 2});\n")),(0,a.kt)("p",null,"This overload internally calls the ",(0,a.kt)("a",{parentName:"p",href:"#method-only"},(0,a.kt)("inlineCode",{parentName:"a"},"only"))," method."),(0,a.kt)("h4",{id:"method-first"},(0,a.kt)("inlineCode",{parentName:"h4"},"first()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"first")," method returns the first model in the collection that passes a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n};\n\nUser *user = users.first([](User *const user)\n{\n return user->getAttribute("votes") > 150;\n});\n\n// {{"name", "John"}, {"votes", 200}}\n')),(0,a.kt)("p",null,"If no model passes a given truth test then the value of the second ",(0,a.kt)("inlineCode",{parentName:"p"},"defaultModel")," argument will be returned, its default value is the ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr"),"."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using NullVariant = Orm::Utils::NullVariant;\n\nUser defaultUser {{"name", NullVariant::QString()},\n {"votes", NullVariant::ULongLong()}};\n\nUser *user = users.first([](User *const user)\n{\n return user->getAttribute("votes") > 500;\n},\n &defaultUser);\n\n/*\n {{"name", NullVariant::QString()},\n {"votes", NullVariant::ULongLong()}}\n*/\n')),(0,a.kt)("p",null,"You can also call all ",(0,a.kt)("inlineCode",{parentName:"p"},"first")," overloads provided by the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qlist.html#first"},(0,a.kt)("inlineCode",{parentName:"a"},"QList::first")),"."),(0,a.kt)("h4",{id:"method-first-where"},(0,a.kt)("inlineCode",{parentName:"h4"},"firstWhere()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"firstWhere")," method returns the first model in the collection with the given column / value pair:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using NullVariant = Orm::Utils::NullVariant;\n\nModelsCollection users {\n {{"name", "Leon"}, {"age", NullVariant::UShort()}},\n {{"name", "Jill"}, {"age", 14}},\n {{"name", "Jack"}, {"age", 23}},\n {{"name", "Jill"}, {"age", 84}},\n};\n\nauto user = users.firstWhereEq("name", "Linda");\n\n// {{"name", "Jill"}, {"age", 14}}\n')),(0,a.kt)("p",null,"You may also call the ",(0,a.kt)("inlineCode",{parentName:"p"},"firstWhere")," method with a comparison operator:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'users.firstWhere("age", ">=", 18);\n\n// {{"name", "Jack"}, {"age", 23}}\n')),(0,a.kt)("h4",{id:"method-fresh"},(0,a.kt)("inlineCode",{parentName:"h4"},"fresh()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"fresh")," method retrieves a fresh instance of each model in the collection from the database. In addition, any specified relationships will be eager loaded:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto usersFresh = users.fresh();\n\nauto usersFresh = users.fresh("comments");\n\nauto usersFresh = users.fresh("posts:id,name");\n\nauto usersFresh = users.fresh({"comments", "posts:id,name"});\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"relations")," argument format is the same as for TinyBuilder's ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/relationships#lazy-eager-loading"},(0,a.kt)("inlineCode",{parentName:"a"},"load"))," method."),(0,a.kt)("h4",{id:"method-implode"},(0,a.kt)("inlineCode",{parentName:"h4"},"implode()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"implode"),' method joins attributes by the given column and the "glue" string you wish to place between the values:'),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n};\n\nproducts.implode("product", ", ");\n\n// {Desk, Chair}\n')),(0,a.kt)("p",null,'The default "glue" value is an empty string "".'),(0,a.kt)("h4",{id:"method-isempty"},(0,a.kt)("inlineCode",{parentName:"h4"},"isEmpty()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"isEmpty")," method returns ",(0,a.kt)("inlineCode",{parentName:"p"},"true")," if the collection is empty; otherwise, ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," is returned:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection().isEmpty();\n\n// true\n")),(0,a.kt)("h4",{id:"method-isnotempty"},(0,a.kt)("inlineCode",{parentName:"h4"},"isNotEmpty()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"isNotEmpty")," method returns ",(0,a.kt)("inlineCode",{parentName:"p"},"true")," if the collection is not empty; otherwise, ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," is returned:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection().isNotEmpty();\n\n// false\n")),(0,a.kt)("h4",{id:"method-last"},(0,a.kt)("inlineCode",{parentName:"h4"},"last()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"last")," method returns the last model in the collection that passes a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n {{"name", "Rose"}, {"votes", 350}},\n};\n\nUser *user = users.last([](User *const user)\n{\n return user->getAttribute("votes") < 300;\n});\n\n// {{"name", "John"}, {"votes", 200}}\n')),(0,a.kt)("p",null,"If no model passes a given truth test then the value of the second ",(0,a.kt)("inlineCode",{parentName:"p"},"defaultModel")," argument will be returned, its default value is the ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr"),"."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using NullVariant = Orm::Utils::NullVariant;\n\nUser defaultUser {{"name", NullVariant::QString()},\n {"votes", NullVariant::ULongLong()}};\n\nUser *user = users.last([](User *const user)\n{\n return user->getAttribute("votes") < 100;\n},\n &defaultUser);\n\n/*\n {{"name", NullVariant::QString()},\n {"votes", NullVariant::ULongLong()}}\n*/\n')),(0,a.kt)("p",null,"You can also call all ",(0,a.kt)("inlineCode",{parentName:"p"},"last")," overloads provided by the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qlist.html#last"},(0,a.kt)("inlineCode",{parentName:"a"},"QList::last")),"."),(0,a.kt)("h4",{id:"method-load"},(0,a.kt)("inlineCode",{parentName:"h4"},"load()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"load")," method eager loads the given relationships for all models in the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'users.load({"comments", "posts"});\n\nusers.load("comments.author");\n\nusers.load({{"comments"}, {"posts", [](auto &query)\n{\n query.whereEq("active", true);\n}}});\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"relations")," argument format is the same as for TinyBuilder's ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/relationships#lazy-eager-loading"},(0,a.kt)("inlineCode",{parentName:"a"},"load"))," method."),(0,a.kt)("h4",{id:"method-map"},(0,a.kt)("inlineCode",{parentName:"h4"},"map()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," method iterates through the collection and passes a ",(0,a.kt)("strong",{parentName:"p"},"copy")," of each model to the given lambda expression. The lambda expression is free to modify the model and return it, thus forming a new collection of modified models:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n};\n\nauto usersAdded = users.map([](User &&userCopy)\n{\n if (userCopy.getAttribute("name") == "John")\n userCopy["votes"] = userCopy.getAttribute("votes") + 1;\n\n return std::move(userCopy);\n});\n\n/*\n {\n {{"name", "John"}, {"price", 201}},\n {{"name", "Jack"}, {"price", 400}},\n }\n*/\n')),(0,a.kt)("p",null,"The second ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," overload allows to return the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'QVector usersAdded = users.map([](User &&userCopy)\n{\n const auto votesRef = userCopy["votes"];\n\n if (userCopy.getAttribute("name") == "John")\n votesRef = userCopy.getAttribute("votes") + 1;\n\n return votesRef->value();\n});\n\n// {201, 400}\n')),(0,a.kt)("p",null,"Both overloads allow to pass the lambda expression with two arguments, whereas the second argument can be an index of the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::size_t")," type."),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"Like most other collection methods, ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," returns a new collection instance; it does not modify the collection it is called on. If you want to modify the original collection in place, use the ",(0,a.kt)("a",{parentName:"p",href:"#method-each"},(0,a.kt)("inlineCode",{parentName:"a"},"each"))," method.")),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"The model copy is passed to the lambda expression even if the ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," iterates over a collection of model pointers ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection"),". The models are dereferenced behind the scene.")),(0,a.kt)("h4",{id:"method-mapwithkeys"},(0,a.kt)("inlineCode",{parentName:"h4"},"mapWithKeys()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"mapWithKeys")," method iterates through the collection and passes each model to the given lambda expression. It returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::unordered_map")," and the lambda expression should return the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::pair")," containing a single column / value pair:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 1}, {"name", "John"}, {"email", "john@example.com"}},\n {{"id", 2}, {"name", "Jill"}, {"email", "jill@example.com"}},\n};\n\nauto usersMap = users.mapWithKeys(\n [](User *const user) -> std::pair\n{\n return {user->getKeyCasted(), user->getAttribute("name")};\n});\n\n// {{1, \'John\'}, {2, \'Jill\'}}\n')),(0,a.kt)("p",null,"You can also map IDs to the model pointers:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"auto usersMap = users.mapWithKeys(\n [](User *const user) -> std::pair\n{\n return {user->getKeyCasted(), user};\n});\n")),(0,a.kt)("h4",{id:"method-mapwithmodelkeys"},(0,a.kt)("inlineCode",{parentName:"h4"},"mapWithModelKeys()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"mapWithModelKeys")," maps the primary keys to the ",(0,a.kt)("inlineCode",{parentName:"p"},"Model *"),", it returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::unordered_map"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"auto usersMap = users.mapWithModelKeys();\n")),(0,a.kt)("h4",{id:"method-modelkeys"},(0,a.kt)("inlineCode",{parentName:"h4"},"modelKeys()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"modelKeys")," method returns the primary keys for all models in the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 1}, {"name", "John"}},\n {{"id", 2}, {"name", "Jill"}},\n {{"id", 3}, {"name", "Kate"}},\n {{"id", 5}, {"name", "Rose"}},\n};\n\nusers.modelKeys(); // Returns QVector\nusers.modelKeys();\n\n// {1, 2, 3, 5}\n')),(0,a.kt)("h4",{id:"method-only"},(0,a.kt)("inlineCode",{parentName:"h4"},"only()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"only")," method returns all of the models that have the given primary keys:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection usersResult = users.only({1, 2, 3});\n")),(0,a.kt)("p",null,"An empty collection is returned if the ",(0,a.kt)("inlineCode",{parentName:"p"},"ids")," argument is empty ",(0,a.kt)("inlineCode",{parentName:"p"},"only({})"),"."),(0,a.kt)("p",null,"The order of models in the collection is preserved."),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"only"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-except"},"except")," method."),(0,a.kt)("h4",{id:"method-pluck"},(0,a.kt)("inlineCode",{parentName:"h4"},"pluck()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"pluck")," method retrieves all of the values for a given column, the following overload returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"id", 1}, {"name", "Desk"}},\n {{"id", 2}, {"name", "Chair"}},\n};\n\nauto plucked = products.pluck("name");\n\n// {Desk, Chair}\n')),(0,a.kt)("p",null,"The second overload allows returning the custom type ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto plucked = products.pluck("name");\n')),(0,a.kt)("p",null,"You may also specify how you wish the resulting collection to be keyed, this overload returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::map"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto plucked = products.pluck("name", "id");\n\n// {{1, "Desk"}, {2, "Chair"}}\n')),(0,a.kt)("p",null,"If duplicate keys exist, the last matching attribute will be inserted into the plucked collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection collection {\n {{"brand", "Tesla"}, {"color", "red"}},\n {{"brand", "Pagani"}, {"color", "white"}},\n {{"brand", "Tesla"}, {"color", "black"}},\n {{"brand", "Pagani"}, {"color", "orange"}},\n};\n\nauto plucked = collection.pluck("color", "brand");\n\n// {{\'Tesla\', \'black\'}, {\'Pagani\', \'orange"}}\n')),(0,a.kt)("h4",{id:"method-reject"},(0,a.kt)("inlineCode",{parentName:"h4"},"reject()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"reject")," method filters the collection using the given lambda expression. The lambda should return ",(0,a.kt)("inlineCode",{parentName:"p"},"true")," if the model should be removed from the resulting collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto usersWithNote = users.reject([](const User *const user)\n{\n return user->getAttribute("note").isNull();\n});\n')),(0,a.kt)("p",null,"You may also pass the lambda expression with two arguments, whereas the second argument can be an index of the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::size_t")," type."),(0,a.kt)("p",null,"For the inverse of the ",(0,a.kt)("inlineCode",{parentName:"p"},"reject")," method, see the ",(0,a.kt)("a",{parentName:"p",href:"#method-filter"},(0,a.kt)("inlineCode",{parentName:"a"},"filter"))," method."),(0,a.kt)("h4",{id:"method-sort"},(0,a.kt)("inlineCode",{parentName:"h4"},"sort()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," method sorts the models collection by primary keys:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nauto sorted = users.sort();\n\n/*\n {\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n }\n*/\n')),(0,a.kt)("p",null,"You may pass a predicate and projection callbacks to the ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," method with your own algorithms. Refer to the CPP reference documentation on ",(0,a.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/algorithm/ranges/sort"},(0,a.kt)("inlineCode",{parentName:"a"},"ranges::sort")),", which is what the ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," method calls internally."),(0,a.kt)("p",null,"You can eg. sort by multiple columns, for an alternative method of multi-column sorting look at ",(0,a.kt)("a",{parentName:"p",href:"#method-sortby"},"sortBy"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 350}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "John"}, {"votes", 150}},\n {{"name", "Kate"}, {"votes", 200}},\n};\n\nauto sorted = users.sort([](const User *const left,\n const User *const right)\n{\n const auto leftValue = left->getAttribute("name");\n const auto rightValue = right->getAttribute("name");\n\n if (leftValue == rightValue)\n return left->getAttribute("votes") <\n right->getAttribute("votes");\n\n return leftValue < rightValue;\n});\n\n/*\n {\n {{"name", "John"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Kate"}, {"votes", 200}},\n {{"name", "Kate"}, {"votes", 350}},\n }\n*/\n')),(0,a.kt)("p",null,"The order of equal elements is not guaranteed to be preserved."),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"You can use the ",(0,a.kt)("a",{parentName:"p",href:"#method-stablesort"},"stable")," sort method variants to preserve the order of equal models.")),(0,a.kt)("h4",{id:"method-sortby"},(0,a.kt)("inlineCode",{parentName:"h4"},"sortBy()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"sortBy")," method sorts the collection by the given column, this overload needs the template argument so it can cast the attribute value before comparing:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n};\n\nauto sorted = users.sortBy("name");\n\n/*\n {\n {{"name", "Jack"}, {"votes", 400}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Kate"}, {"votes", 150}},\n }\n*/\n')),(0,a.kt)("p",null,"You may pass the projection callback to determine how to sort the collection's models:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto sorted = users.sortBy([](User *const user)\n{\n return user->getAttribute("votes");\n});\n\n/*\n {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n }\n*/\n')),(0,a.kt)("p",null,"If you would like to sort your collection by multiple columns, you may pass a vector of comparison lambda expressions that define each sort operation to the ",(0,a.kt)("inlineCode",{parentName:"p"},"sortBy")," method, in the following example is the ",(0,a.kt)("inlineCode",{parentName:"p"},"name")," column sorted in ascending order and the second ",(0,a.kt)("inlineCode",{parentName:"p"},"votes")," column is sorted in descending order:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using AttributeUtils = Orm::Tiny::Utils::Attribute;\n\nModelsCollection users {\n {{"name", "Kate"}, {"votes", 350}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "John"}, {"votes", 150}},\n {{"name", "Kate"}, {"votes", 200}},\n};\n\nauto sorted = users.sortBy({\n [](const User *const left, const User *const right)\n {\n return AttributeUtils::compareForSortBy(\n left->getAttribute("name"),\n right->getAttribute("name"));\n },\n [](const User *const left, const User *const right)\n {\n return AttributeUtils::compareForSortByDesc(\n left->getAttribute("votes"),\n right->getAttribute("votes"));\n },\n});\n\n/*\n {\n {{"name", "John"}, {"votes", 200}},\n {{"name", "John"}, {"votes", 150}},\n {{"name", "Kate"}, {"votes", 350}},\n {{"name", "Kate"}, {"votes", 200}},\n }\n*/\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"AttributeUtils::compareForSortBy")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"compareForSortByDesc")," methods are helper methods, they are needed because the Qt framework doesn't define ",(0,a.kt)("inlineCode",{parentName:"p"},"<=>")," spaceship operator on its types, it doesn't support the three-way comparison."),(0,a.kt)("p",null,"The order of equal elements is not guaranteed to be preserved."),(0,a.kt)("h4",{id:"method-sortbydesc"},(0,a.kt)("inlineCode",{parentName:"h4"},"sortByDesc()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sortby"},(0,a.kt)("inlineCode",{parentName:"a"},"sortBy"))," method but will sort the collection in the opposite order."),(0,a.kt)("p",null,"The order of equal elements is not guaranteed to be preserved."),(0,a.kt)("h4",{id:"method-sortdesc"},(0,a.kt)("inlineCode",{parentName:"h4"},"sortDesc()")),(0,a.kt)("p",null,"This method will sort the collection in the opposite order as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sort"},(0,a.kt)("inlineCode",{parentName:"a"},"sort"))," method:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nauto sorted = users.sortDesc();\n\n/*\n {\n {{"id", 3}, {"name", "John"}},\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 1}, {"name", "Jack"}},\n }\n*/\n')),(0,a.kt)("p",null,"The order of equal elements is not guaranteed to be preserved."),(0,a.kt)("h4",{id:"method-stablesort"},(0,a.kt)("inlineCode",{parentName:"h4"},"stableSort()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sort"},(0,a.kt)("inlineCode",{parentName:"a"},"sort"))," method but will preserve the order of equal elements (guaranteed to be preserved)."),(0,a.kt)("h4",{id:"method-stablesortby"},(0,a.kt)("inlineCode",{parentName:"h4"},"stableSortBy()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sortby"},(0,a.kt)("inlineCode",{parentName:"a"},"sortBy"))," method but will preserve the order of equal elements (guaranteed to be preserved)."),(0,a.kt)("h4",{id:"method-stablesortbydesc"},(0,a.kt)("inlineCode",{parentName:"h4"},"stableSortByDesc()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sortbydesc"},(0,a.kt)("inlineCode",{parentName:"a"},"sortByDesc"))," method but will sort the collection in the opposite order and preserve the order of equal elements (guaranteed to be preserved)."),(0,a.kt)("h4",{id:"method-stablesortdesc"},(0,a.kt)("inlineCode",{parentName:"h4"},"stableSortDesc()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sortdesc"},(0,a.kt)("inlineCode",{parentName:"a"},"sortDesc"))," method but will sort the collection in the opposite order and preserve the order of equal elements (guaranteed to be preserved)."),(0,a.kt)("h4",{id:"method-tap"},(0,a.kt)("inlineCode",{parentName:"h4"},"tap()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"tap"),' method passes a collection to the given lambda expression, allowing you to "tap" into the collection at a specific point and do something with the models while not affecting the collection itself:'),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nusers.sort()\n .tap([](/*const */ModelsCollection &usersRef)\n{\n qDebug() << "IDs after sorting:"\n << usersRef.template modelKeys();\n})\n .value("id");\n\n// 1\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"tap")," method returns an lvalue ",(0,a.kt)("strong",{parentName:"p"},"reference")," to the currently processed collection."),(0,a.kt)("p",null,"It can be also called on ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," rvalues, it returns an rvalue reference in this case."),(0,a.kt)("h4",{id:"method-tobase"},(0,a.kt)("inlineCode",{parentName:"h4"},"toBase()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toBase")," method returns a copy of the underlying vector represented by the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"QVector = users.toBase();\n")),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("a",{parentName:"p",href:"#method-tobase"},(0,a.kt)("inlineCode",{parentName:"a"},"toBase"))," is an alias to the ",(0,a.kt)("inlineCode",{parentName:"p"},"all")," method.")),(0,a.kt)("h4",{id:"method-tojson"},(0,a.kt)("inlineCode",{parentName:"h4"},"toJson()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," method converts the collection of models with all nested relations into a JSON serialized ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qbytearray.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QByteArray")),"."),(0,a.kt)("p",null,"It returns an empty array for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," method accepts the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qjsondocument.html#JsonFormat-enum"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonDocument::JsonFormat")),", possible values are ",(0,a.kt)("inlineCode",{parentName:"p"},"QJsonDocument::Indented")," or ",(0,a.kt)("inlineCode",{parentName:"p"},"QJsonDocument::Compact"),".")),(0,a.kt)("h4",{id:"method-tojsonarray"},(0,a.kt)("inlineCode",{parentName:"h4"},"toJsonArray()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toJsonArray")," method converts the collection of models with all nested relations into a ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qjsonarray.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonArray")),"."),(0,a.kt)("h4",{id:"method-tojsondocument"},(0,a.kt)("inlineCode",{parentName:"h4"},"toJsonDocument()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toJsonDocument")," method converts the collection of models with all nested relations into a ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qjsondocument.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonDocument")),"."),(0,a.kt)("h4",{id:"method-tomap"},(0,a.kt)("inlineCode",{parentName:"h4"},"toMap()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toMap")," method converts the collection of models with all nested relations into an attributes map ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),"."),(0,a.kt)("p",null,"It returns an empty ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and a null ",(0,a.kt)("abbr",{title:"QVariant::fromValue(nullptr)"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariant"))," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("h4",{id:"method-tomapvariantlist"},(0,a.kt)("inlineCode",{parentName:"h4"},"toMapVariantList()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toMapVariantList")," method converts the collection of models with all nested relations into an attributes map, but it returns the ",(0,a.kt)("abbr",{title:"QList"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList"))," instead of the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),"."),(0,a.kt)("p",null,"It returns an empty ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and a null ",(0,a.kt)("abbr",{title:"QVariant::fromValue(nullptr)"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariant"))," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toMapVariantList")," method is internally needed by the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," related methods.")),(0,a.kt)("h4",{id:"method-toquery"},(0,a.kt)("inlineCode",{parentName:"h4"},"toQuery()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toQuery")," method returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"TinyBuilder")," instance containing a ",(0,a.kt)("inlineCode",{parentName:"p"},"whereIn")," constraint with the collection of models' primary keys:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using Models::User;\n\nModelsCollection users = User::whereEq("status", "VIP")->get();\n\nusers.toQuery()->update({\n {"status", "Administrator"},\n});\n')),(0,a.kt)("h4",{id:"method-tovector"},(0,a.kt)("inlineCode",{parentName:"h4"},"toVector()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toVector")," method converts the collection of models with all nested relations into an attributes vector ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector>"),"."),(0,a.kt)("p",null,"It returns an empty ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and a null ",(0,a.kt)("abbr",{title:"QVariant::fromValue(nullptr)"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariant"))," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("h4",{id:"method-tovectorvariantlist"},(0,a.kt)("inlineCode",{parentName:"h4"},"toVectorVariantList()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toVectorVariantList")," method converts the collection of models with all nested relations into an attributes vector, but it returns the ",(0,a.kt)("abbr",{title:"QList"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList"))," instead of the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector>"),"."),(0,a.kt)("p",null,"It returns an empty ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and a null ",(0,a.kt)("abbr",{title:"QVariant::fromValue(nullptr)"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariant"))," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toVectorVariantList")," method is internally needed by the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," related methods.")),(0,a.kt)("h4",{id:"method-unique"},(0,a.kt)("inlineCode",{parentName:"h4"},"unique()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"unique")," method returns all of the unique models in the ",(0,a.kt)("strong",{parentName:"p"},"sorted")," collection. Any models with the same primary key as another model in the collection are removed:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nauto unique = users.unique();\n\n/*\n {\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n }\n*/\n')),(0,a.kt)("p",null,"It sorts the collection internally because the ",(0,a.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/algorithm/ranges/unique"},(0,a.kt)("inlineCode",{parentName:"a"},"ranges::unique"))," can correctly operate only on the sorted container. You can disable it by passing ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," using the first ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," parameter:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto unique = users.sort().unique(false);\n\n/*\n {\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-uniqueby"},(0,a.kt)("inlineCode",{parentName:"h4"},"uniqueBy()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"uniqueBy")," method returns all of the unique models in the ",(0,a.kt)("strong",{parentName:"p"},"sorted")," collection by the given column. Any models with the same column value as another model in the collection are removed. It needs the template argument, so it can cast the attribute value before comparing:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}},\n {{"name", "Jack"}},\n {{"name", "John"}},\n {{"name", "Jack"}},\n};\n\nauto unique = users.uniqueBy("name");\n\n/*\n {\n {{"name", "Jack"}},\n {{"name", "John"}},\n {{"name", "Kate"}},\n }\n*/\n')),(0,a.kt)("p",null,"It sorts the collection internally because the ",(0,a.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/algorithm/ranges/unique"},(0,a.kt)("inlineCode",{parentName:"a"},"ranges::unique"))," can correctly operate only on the sorted container. You can disable it by passing ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," using the second ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," parameter:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto unique = users.sortBy("name")\n .uniqueBy("name", false);\n\n/*\n {\n {{"name", "Jack"}},\n {{"name", "John"}},\n {{"name", "Kate"}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-uniquerelaxed"},(0,a.kt)("inlineCode",{parentName:"h4"},"uniqueRelaxed()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"uniqueRelaxed")," method returns all of the unique models in the collection, it doesn't need a sorted collection. Any models with the same primary key as another model in the collection are removed:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nauto unique = users.uniqueRelaxed();\n\n/*\n {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 3}, {"name", "John"}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-uniquerelaxedby"},(0,a.kt)("inlineCode",{parentName:"h4"},"uniqueRelaxedBy()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"uniqueRelaxedBy")," method returns all of the unique models in the collection by the given column, it doesn't need a sorted collection, but it needs the template argument, so it can cast the attribute value before comparing:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}},\n {{"name", "Jack"}},\n {{"name", "John"}},\n {{"name", "Jack"}},\n};\n\nauto unique = users.uniqueRelaxedBy("name");\n\n/*\n {\n {{"name", "Kate"}},\n {{"name", "Jack"}},\n {{"name", "John"}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-value"},(0,a.kt)("inlineCode",{parentName:"h4"},"value()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"value")," method retrieves a given value from the first model of the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n};\n\nQVariant votes = users.value("votes");\n\n// 200\n')),(0,a.kt)("p",null,"Alternatively, you can cast an obtained ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant")," value to the given type by the second ",(0,a.kt)("inlineCode",{parentName:"p"},"value")," overload:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'quint64 votes = users.value("votes");\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"value")," method also accepts the second ",(0,a.kt)("inlineCode",{parentName:"p"},"defaultValue")," argument, which will be returned if a collection is empty, the first model is ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr"),", or a model doesn't contain the given column:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto votes = ModelsCollection().value("votes", 0);\n\n// 0\n')),(0,a.kt)("p",null,"You can also call all ",(0,a.kt)("inlineCode",{parentName:"p"},"value")," overloads provided by the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qlist.html#value"},(0,a.kt)("inlineCode",{parentName:"a"},"QList::value")),"."),(0,a.kt)("h4",{id:"method-where"},(0,a.kt)("inlineCode",{parentName:"h4"},"where()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"where")," method filters the collection by a given column / value pair:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 100}},\n};\n\nauto filtered = products.where("price", "=", 100);\n\n/*\n {\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Door"}, {"price", 100}},\n }\n*/\n')),(0,a.kt)("p",null,"For convenience, if you want to verify that a column is ",(0,a.kt)("inlineCode",{parentName:"p"},"=")," to a given value, you may call ",(0,a.kt)("inlineCode",{parentName:"p"},"whereEq")," method. Similar ",(0,a.kt)("inlineCode",{parentName:"p"},"XxxEq")," methods are also defined for other commands:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto filtered = products.whereEq("price", 100);\n')),(0,a.kt)("p",null,"Optionally, you may pass a comparison operator as the second argument.",(0,a.kt)("br",null),"Supported operators are ",(0,a.kt)("inlineCode",{parentName:"p"},"="),", ",(0,a.kt)("inlineCode",{parentName:"p"},"!="),", ",(0,a.kt)("inlineCode",{parentName:"p"},"<"),", ",(0,a.kt)("inlineCode",{parentName:"p"},">"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"<="),", and ",(0,a.kt)("inlineCode",{parentName:"p"},">="),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 250}},\n};\n\nauto filtered = products.where("price", ">", 150);\n\n/*\n {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Door"}, {"price", 250}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-wherebetween"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereBetween()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereBetween")," method filters the collection by determining if a specified models' attribute value is within a given range:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 80}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Pencil"}, {"price", 30}},\n {{"product", "Door"}, {"price", 100}},\n};\n\nauto filtered = products.whereBetween("price", {100, 200});\n\n/*\n {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 100}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-wherein"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereIn()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereIn")," method filters models from the collection that have a specified attribute value that is contained within the given unordered set:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 250}},\n};\n\nauto filtered = products.whereIn("price", {100, 200});\n\n/*\n {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n }\n*/\n')),(0,a.kt)("p",null,"An empty collection is returned if the ",(0,a.kt)("inlineCode",{parentName:"p"},"values")," argument is empty ",(0,a.kt)("inlineCode",{parentName:"p"},'whereIn("price", {})'),"."),(0,a.kt)("p",null,"The order of models in the collection is preserved."),(0,a.kt)("h4",{id:"method-wherenotbetween"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereNotBetween()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereNotBetween")," method filters the collection by determining if a specified models' attribute value is outside of a given range:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 80}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Pencil"}, {"price", 30}},\n {{"product", "Door"}, {"price", 100}},\n};\n\nauto filtered = products.whereNotBetween("price", {100, 200});\n\n/*\n {\n {{"product", "Chair"}, {"price", 80}},\n {{"product", "Pencil"}, {"price", 30}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-wherenotin"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereNotIn()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereNotIn")," method removes models from the collection that have a specified attribute value that is contained within the given unordered set:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 250}},\n};\n\nauto filtered = products.whereNotIn("price", {100, 200});\n\n/*\n {\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 250}},\n }\n*/\n')),(0,a.kt)("p",null,"All of the models are returned if the ",(0,a.kt)("inlineCode",{parentName:"p"},"values")," argument is empty ",(0,a.kt)("inlineCode",{parentName:"p"},'whereNotIn("price", {})'),"."),(0,a.kt)("p",null,"The order of models in the collection is preserved."),(0,a.kt)("h4",{id:"method-wherenotnull"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereNotNull()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereNotNull")," method returns models from the collection where the given column is not ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," QVariant:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing NullVariant = Orm::Utils::NullVariant;\n\nModelsCollection users {\n {{"name", "John"}},\n {{"name", NullVariant::QString()}},\n {{"name", "Jack"}},\n};\n\nauto filtered = users.whereNotNull("name");\n\n/*\n {\n {{"name", "John"}},\n {{"name", "Jack"}},\n }\n*/\n')),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"NullVariant")," class returns the correct ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," QVariant for both Qt 5 ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant(QVariant::String)")," and also Qt 6 ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant(QMetaType(QMetaType::QString))"),".")),(0,a.kt)("h4",{id:"method-wherenull"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereNull()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereNull")," method returns models from the collection where the given column is ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," QVariant:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing NullVariant = Orm::Utils::NullVariant;\n\nModelsCollection users {\n {{"name", "John"}},\n {{"name", NullVariant::QString()}},\n {{"name", "Jack"}},\n};\n\nauto filtered = users.whereNotNull("name");\n\n// {{"name", NullVariant::QString()}}\n')),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"NullVariant")," class returns the correct ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," QVariant for both Qt 5 ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant(QVariant::String)")," and also Qt 6 ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant(QMetaType(QMetaType::QString))"),"."))))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/3dd307b5.94a0d662.js b/assets/js/3dd307b5.94a0d662.js deleted file mode 100644 index 40657f6e7..000000000 --- a/assets/js/3dd307b5.94a0d662.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[108],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>c});var o=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function l(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=o.createContext({}),d=function(e){var t=o.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=d(e.components);return o.createElement(s.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return o.createElement(o.Fragment,{},t)}},h=o.forwardRef((function(e,t){var n=e.components,a=e.mdxType,r=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),m=d(n),h=a,c=m["".concat(s,".").concat(h)]||m[h]||u[h]||r;return n?o.createElement(c,l(l({ref:t},p),{},{components:n})):o.createElement(c,l({ref:t},p))}));function c(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var r=n.length,l=new Array(r);l[0]=h;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[m]="string"==typeof e?e:a,l[1]=i;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>i,toc:()=>d});var o=n(7462),a=(n(7294),n(3905));const r={sidebar_position:2,sidebar_label:"Collections",description:"The ModelsCollection is specialized container which provides a fluent, convenient wrapper for working with vector of models. Is much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. All TinyORM methods that return more than one model result will return instances of the ModelsCollection class.",keywords:["c++ orm","orm","collections","collection","model","tinyorm"]},l="TinyORM: Collections",i={unversionedId:"tinyorm/collections",id:"tinyorm/collections",title:"TinyORM: Collections",description:"The ModelsCollection is specialized container which provides a fluent, convenient wrapper for working with vector of models. Is much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. All TinyORM methods that return more than one model result will return instances of the ModelsCollection class.",source:"@site/docs/tinyorm/collections.mdx",sourceDirName:"tinyorm",slug:"/tinyorm/collections",permalink:"/tinyorm/collections",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinyorm/collections.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,sidebar_label:"Collections",description:"The ModelsCollection is specialized container which provides a fluent, convenient wrapper for working with vector of models. Is much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. All TinyORM methods that return more than one model result will return instances of the ModelsCollection class.",keywords:["c++ orm","orm","collections","collection","model","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Relationships",permalink:"/tinyorm/relationships"},next:{title:"Casts",permalink:"/tinyorm/casts"}},s={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Collection Conversion",id:"collection-conversion",level:4},{value:"Creating Collections",id:"creating-collections",level:3},{value:"Available Methods",id:"available-methods",level:2},{value:"all()",id:"method-all",level:4},{value:"contains()",id:"method-contains",level:4},{value:"doesntContain()",id:"method-doesntcontain",level:4},{value:"each()",id:"method-each",level:4},{value:"except()",id:"method-except",level:4},{value:"filter()",id:"method-filter",level:4},{value:"find()",id:"method-find",level:4},{value:"first()",id:"method-first",level:4},{value:"firstWhere()",id:"method-first-where",level:4},{value:"fresh()",id:"method-fresh",level:4},{value:"implode()",id:"method-implode",level:4},{value:"isEmpty()",id:"method-isempty",level:4},{value:"isNotEmpty()",id:"method-isnotempty",level:4},{value:"last()",id:"method-last",level:4},{value:"load()",id:"method-load",level:4},{value:"map()",id:"method-map",level:4},{value:"mapWithKeys()",id:"method-mapwithkeys",level:4},{value:"mapWithModelKeys()",id:"method-mapwithmodelkeys",level:4},{value:"modelKeys()",id:"method-modelkeys",level:4},{value:"only()",id:"method-only",level:4},{value:"pluck()",id:"method-pluck",level:4},{value:"reject()",id:"method-reject",level:4},{value:"sort()",id:"method-sort",level:4},{value:"sortBy()",id:"method-sortby",level:4},{value:"sortByDesc()",id:"method-sortbydesc",level:4},{value:"sortDesc()",id:"method-sortdesc",level:4},{value:"stableSort()",id:"method-stablesort",level:4},{value:"stableSortBy()",id:"method-stablesortby",level:4},{value:"stableSortByDesc()",id:"method-stablesortbydesc",level:4},{value:"stableSortDesc()",id:"method-stablesortdesc",level:4},{value:"tap()",id:"method-tap",level:4},{value:"toBase()",id:"method-tobase",level:4},{value:"toJson()",id:"method-tojson",level:4},{value:"toJsonArray()",id:"method-tojsonarray",level:4},{value:"toJsonDocument()",id:"method-tojsondocument",level:4},{value:"toMap()",id:"method-tomap",level:4},{value:"toMapVariantList()",id:"method-tomapvariantlist",level:4},{value:"toQuery()",id:"method-toquery",level:4},{value:"toVector()",id:"method-tovector",level:4},{value:"toVectorVariantList()",id:"method-tovectorvariantlist",level:4},{value:"unique()",id:"method-unique",level:4},{value:"uniqueBy()",id:"method-uniqueby",level:4},{value:"uniqueRelaxed()",id:"method-uniquerelaxed",level:4},{value:"uniqueRelaxedBy()",id:"method-uniquerelaxedby",level:4},{value:"value()",id:"method-value",level:4},{value:"where()",id:"method-where",level:4},{value:"whereBetween()",id:"method-wherebetween",level:4},{value:"whereIn()",id:"method-wherein",level:4},{value:"whereNotBetween()",id:"method-wherenotbetween",level:4},{value:"whereNotIn()",id:"method-wherenotin",level:4},{value:"whereNotNull()",id:"method-wherenotnull",level:4},{value:"whereNull()",id:"method-wherenull",level:4}],p={toc:d},m="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(m,(0,o.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"tinyorm-collections"},"TinyORM: Collections"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#introduction"},"Introduction"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#creating-collections"},"Creating Collections")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#available-methods"},"Available Methods"))),(0,a.kt)("h2",{id:"introduction"},"Introduction"),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Types::ModelsCollection")," is specialized container which provides a fluent, convenient wrapper for working with vector of models. All TinyORM methods that return more than one model result, will return instances of the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," class, including results retrieved via the ",(0,a.kt)("inlineCode",{parentName:"p"},"get")," method or methods that return relationships like the ",(0,a.kt)("inlineCode",{parentName:"p"},"getRelation")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"getRelationValue"),"."),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," class extends ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),", so it naturally inherits dozens of methods used to work with the underlying vector of TinyORM models. Be sure to review the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qlist.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QList"))," documentation to learn all about these helpful methods!"),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," template parameter can be declared only with the model type or a model type pointer, it also can't be ",(0,a.kt)("inlineCode",{parentName:"p"},"const")," and can't be a reference. It's constrained using the ",(0,a.kt)("inlineCode",{parentName:"p"},"DerivedCollectionModel")," concept.")),(0,a.kt)("p",null,"You can iterate over the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," the same way as over the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using Models::User;\n\nModelsCollection users = User::whereEq("active", true)->get();\n\nfor (const auto &user : users)\n qDebug() << user.getAttribute("name");\n')),(0,a.kt)("p",null,"However, as previously mentioned, collections are much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. For example, we may remove all active users and then gather the first name of each remaining user:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto names = User::all().reject([](User *const user)\n{\n return user->getAttribute("active");\n})\n .pluck("name");\n')),(0,a.kt)("p",null,"As you can see, the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," class allows you to chain its methods to perform fluent mapping and reducing of the underlying vector. In general, collections are immutable, meaning every ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," method returns an entirely new ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," instance."),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," is returning from the Models' methods like ",(0,a.kt)("inlineCode",{parentName:"p"},"get"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"all"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"findMany"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"chunk"),"; the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," is returning from the relationship-related methods as ",(0,a.kt)("inlineCode",{parentName:"p"},"getRelation")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"getRelationValue"),".")),(0,a.kt)("h4",{id:"collection-conversion"},"Collection Conversion"),(0,a.kt)("p",null,"While most TinyORM collection methods return a new instance of ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection"),", the ",(0,a.kt)("inlineCode",{parentName:"p"},"modelKeys"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"mapWithKeys"),", and ",(0,a.kt)("inlineCode",{parentName:"p"},"pluck")," methods return a base QVector or std unordered/map instances. Likewise, one of the ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," methods overload returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),"."),(0,a.kt)("h3",{id:"creating-collections"},"Creating Collections"),(0,a.kt)("p",null,"Creating a ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," is as simple as:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n};\n')),(0,a.kt)("p",null,"You can also create a collection of pointers, eg. ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection userPointers {\n &users[0], &users[1],\n};\n")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," is implicitly convertible and assignable from the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'QVector usersVector {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n};\n\nModelsCollection users(usersVector);\nusers = usersVector;\n')),(0,a.kt)("p",null,"Alternatively, you can use the ",(0,a.kt)("inlineCode",{parentName:"p"},"Orm::collect")," helper function to create a ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," from the given attributes:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users = Orm::collect({\n {{"name", "Kate"}, {"added_on", QDateTime::currentDateTimeUtc()}},\n {{"name", "John"}, {"added_on", QDateTime({2023, 6, 1}, {13, 46, 15}, Qt::UTC)}},\n});\n')),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"Orm::collect")," function is ",(0,a.kt)("strong",{parentName:"p"},"mandatory")," if your attributes contain the ",(0,a.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance, you can read more about this problem ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/getting-started#qdatetime-and-connection-name-problem"},"here"),".")),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The results of ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/getting-started"},"TinyORM")," queries are always returned as ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," instances.")),(0,a.kt)("h2",{id:"available-methods"},"Available Methods"),(0,a.kt)("p",null,"For the majority of the remaining collection documentation, we'll discuss each method available on the ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," class. Remember, all of these methods may be chained to fluently manipulate the underlying vector."),(0,a.kt)("p",null,"Furthermore, almost every method returns a new ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," instance, allowing you to preserve the original copy of the collection when necessary:"),(0,a.kt)("div",{class:"collection-methods-list"},(0,a.kt)("p",null,(0,a.kt)("a",{parentName:"p",href:"#method-all"},"all"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-contains"},"contains"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-doesntcontain"},"doesntContain"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-each"},"each"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-except"},"except"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-filter"},"filter"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-find"},"find"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-first"},"first"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-first-where"},"firstWhere"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-fresh"},"fresh"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-implode"},"implode"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-isempty"},"isEmpty"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-isnotempty"},"isNotEmpty"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-last"},"last"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-load"},"load"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-map"},"map"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-mapwithkeys"},"mapWithKeys"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-mapwithmodelkeys"},"mapWithModelKeys"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-modelkeys"},"modelKeys"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-only"},"only"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-pluck"},"pluck"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-reject"},"reject"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-sort"},"sort"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-sortby"},"sortBy"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-sortbydesc"},"sortByDesc"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-sortdesc"},"sortDesc"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-stablesort"},"stableSort"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-stablesortby"},"stableSortBy"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-stablesortbydesc"},"stableSortByDesc"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-stablesortdesc"},"stableSortDesc"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tap"},"tap"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tobase"},"toBase"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tojson"},"toJson"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tojsonarray"},"toJsonArray"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tojsondocument"},"toJsonDocument"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tomap"},"toMap"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tomapvariantlist"},"toMapVariantList"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-toquery"},"toQuery"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tovector"},"toVector"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-tovectorvariantlist"},"toVectorVariantList"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-unique"},"unique"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-uniqueby"},"uniqueBy"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-uniquerelaxed"},"uniqueRelaxed"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-uniquerelaxedby"},"uniqueRelaxedBy"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-value"},"value"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-where"},"where"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherebetween"},"whereBetween"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherein"},"whereIn"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherenotbetween"},"whereNotBetween"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherenotin"},"whereNotIn"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherenotnull"},"whereNotNull"),"\n",(0,a.kt)("a",{parentName:"p",href:"#method-wherenull"},"whereNull"))),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"For a better understanding of the following examples, many of the variable declarations below use actual types instead of the ",(0,a.kt)("inlineCode",{parentName:"p"},"auto")," keyword.")),(0,a.kt)("div",{class:"collection-methods"},(0,a.kt)("h4",{id:"method-all"},(0,a.kt)("inlineCode",{parentName:"h4"},"all()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"all")," method returns a copy of the underlying vector represented by the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"QVector = users.all();\n")),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("a",{parentName:"p",href:"#method-tobase"},(0,a.kt)("inlineCode",{parentName:"a"},"toBase"))," is an alias to the ",(0,a.kt)("inlineCode",{parentName:"p"},"all")," method.")),(0,a.kt)("h4",{id:"method-contains"},(0,a.kt)("inlineCode",{parentName:"h4"},"contains()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"contains")," method may be used to determine if a given model instance is contained by the collection. This method accepts a primary key or a model instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.contains(1);\n\nusers.contains(User::find(1));\n")),(0,a.kt)("p",null,"Alternatively, you may pass a lambda expression to the ",(0,a.kt)("inlineCode",{parentName:"p"},"contains")," method to determine if a model exists in the collection matching a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.contains([](const User *const user)\n{\n return user->getKeyCasted() == 2;\n});\n")),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"contains"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-doesntcontain"},"doesntContain")," method."),(0,a.kt)("h4",{id:"method-doesntcontain"},(0,a.kt)("inlineCode",{parentName:"h4"},"doesntContain()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"doesntContain")," method determines whether the collection does not contain a given item. This method accepts a primary key or a model instance:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.doesntContain(1);\n\nusers.doesntContain(User::find(1));\n")),(0,a.kt)("p",null,"Alternatively, you may pass a lambda expression to the ",(0,a.kt)("inlineCode",{parentName:"p"},"doesntContain")," method to determine if a model does not exist in the collection matching a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.doesntContain([](const User *const user)\n{\n return user->getKeyCasted() == 2;\n});\n")),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"doesntContain"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-contains"},"contains")," method."),(0,a.kt)("h4",{id:"method-each"},(0,a.kt)("inlineCode",{parentName:"h4"},"each()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"each")," method iterates over the models in the collection and passes each model to the lambda expression:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users = Post::whereEq("user_id", 1)->get();\n\nusers.each([](User *const user)\n{\n // ...\n});\n')),(0,a.kt)("p",null,"If you would like to stop iterating through the models, you may return ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," from your lambda expression:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.each([](User *const user)\n{\n if (/* condition */)\n return false;\n\n // Some logic\n\n return true;\n});\n")),(0,a.kt)("p",null,"You may also pass the lambda expression with two parameters, whereas the second one is an index:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"users.each([](User *const user, const std::size_t index)\n{\n // ...\n});\n")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"each")," method returns an lvalue ",(0,a.kt)("strong",{parentName:"p"},"reference")," to the currently processed collection."),(0,a.kt)("p",null,"It can be also called on ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," rvalues, it returns an rvalue reference in this case."),(0,a.kt)("h4",{id:"method-except"},(0,a.kt)("inlineCode",{parentName:"h4"},"except()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"except")," method returns all of the models that do not have the given primary keys:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection usersResult = users.except({1, 2, 3});\n")),(0,a.kt)("p",null,"All of the models are returned if the ",(0,a.kt)("inlineCode",{parentName:"p"},"ids")," argument is empty ",(0,a.kt)("inlineCode",{parentName:"p"},"except({})"),"."),(0,a.kt)("p",null,"The order of models in the collection is preserved."),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"except"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-only"},"only")," method."),(0,a.kt)("h4",{id:"method-filter"},(0,a.kt)("inlineCode",{parentName:"h4"},"filter()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"filter")," method filters the collection using the lambda expression, keeping only those models that pass a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto usersBanned = users.filter([](const User *const user)\n{\n return user->getAttribute("is_banned");\n});\n')),(0,a.kt)("p",null,"You may also pass the lambda expression with two parameters, whereas the second one is an index:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto usersBanned = users.filter([](const User *const user,\n const std::size_t index)\n{\n return index < 10 && user->getAttribute("is_banned");\n});\n')),(0,a.kt)("p",null,"If no lambda expression is supplied, all models of the collection that are equivalent to the ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr")," will be removed:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection usersRaw = User::findMany({1, 2});\nModelsCollection users {&usersRaw[0], nullptr, &usersRaw[1]};\n\nModelsCollection filtered = users.filter();\n\n// {1, 2}\n")),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"filter"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-reject"},"reject")," method."),(0,a.kt)("h4",{id:"method-find"},(0,a.kt)("inlineCode",{parentName:"h4"},"find()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"find")," method returns the model that has a primary key matching the given key:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"User *const user = users.find(1);\n")),(0,a.kt)("p",null,"If you pass a model instance, ",(0,a.kt)("inlineCode",{parentName:"p"},"find")," will attempt to return a model matching the primary key:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"User *user = users.find(anotherUser);\n")),(0,a.kt)("p",null,"The two overloads above also accept the second ",(0,a.kt)("inlineCode",{parentName:"p"},"defaultModel")," model argument, which will be returned if a model was not found in the collection, its default value is the ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr"),"."),(0,a.kt)("p",null,"Alternatively, may pass more IDs and ",(0,a.kt)("inlineCode",{parentName:"p"},"find")," will return all models which have a primary key within the given unordered set:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection usersMany = users.find({1, 2});\n")),(0,a.kt)("p",null,"This overload internally calls the ",(0,a.kt)("a",{parentName:"p",href:"#method-only"},(0,a.kt)("inlineCode",{parentName:"a"},"only"))," method."),(0,a.kt)("h4",{id:"method-first"},(0,a.kt)("inlineCode",{parentName:"h4"},"first()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"first")," method returns the first model in the collection that passes a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n};\n\nUser *user = users.first([](User *const user)\n{\n return user->getAttribute("votes") > 150;\n});\n\n// {{"name", "John"}, {"votes", 200}}\n')),(0,a.kt)("p",null,"If no model passes a given truth test then the value of the second ",(0,a.kt)("inlineCode",{parentName:"p"},"defaultModel")," argument will be returned, its default value is the ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr"),"."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using NullVariant = Orm::Utils::NullVariant;\n\nUser defaultUser {{"name", NullVariant::QString()},\n {"votes", NullVariant::ULongLong()}};\n\nUser *user = users.first([](User *const user)\n{\n return user->getAttribute("votes") > 500;\n},\n &defaultUser);\n\n/*\n {{"name", NullVariant::QString()},\n {"votes", NullVariant::ULongLong()}}\n*/\n')),(0,a.kt)("p",null,"You can also call all ",(0,a.kt)("inlineCode",{parentName:"p"},"first")," overloads provided by the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qlist.html#first"},(0,a.kt)("inlineCode",{parentName:"a"},"QList::first")),"."),(0,a.kt)("h4",{id:"method-first-where"},(0,a.kt)("inlineCode",{parentName:"h4"},"firstWhere()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"firstWhere")," method returns the first model in the collection with the given column / value pair:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using NullVariant = Orm::Utils::NullVariant;\n\nModelsCollection users {\n {{"name", "Leon"}, {"age", NullVariant::UShort()}},\n {{"name", "Jill"}, {"age", 14}},\n {{"name", "Jack"}, {"age", 23}},\n {{"name", "Jill"}, {"age", 84}},\n};\n\nauto user = users.firstWhereEq("name", "Linda");\n\n// {{"name", "Jill"}, {"age", 14}}\n')),(0,a.kt)("p",null,"You may also call the ",(0,a.kt)("inlineCode",{parentName:"p"},"firstWhere")," method with a comparison operator:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'users.firstWhere("age", ">=", 18);\n\n// {{"name", "Jack"}, {"age", 23}}\n')),(0,a.kt)("h4",{id:"method-fresh"},(0,a.kt)("inlineCode",{parentName:"h4"},"fresh()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"fresh")," method retrieves a fresh instance of each model in the collection from the database. In addition, any specified relationships will be eager loaded:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto usersFresh = users.fresh();\n\nauto usersFresh = users.fresh("comments");\n\nauto usersFresh = users.fresh("posts:id,name");\n\nauto usersFresh = users.fresh({"comments", "posts:id,name"});\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"relations")," argument format is the same as for TinyBuilder's ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/relationships#lazy-eager-loading"},(0,a.kt)("inlineCode",{parentName:"a"},"load"))," method."),(0,a.kt)("h4",{id:"method-implode"},(0,a.kt)("inlineCode",{parentName:"h4"},"implode()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"implode"),' method joins attributes by the given column and the "glue" string you wish to place between the values:'),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n};\n\nproducts.implode("product", ", ");\n\n// {Desk, Chair}\n')),(0,a.kt)("p",null,'The default "glue" value is an empty string "".'),(0,a.kt)("h4",{id:"method-isempty"},(0,a.kt)("inlineCode",{parentName:"h4"},"isEmpty()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"isEmpty")," method returns ",(0,a.kt)("inlineCode",{parentName:"p"},"true")," if the collection is empty; otherwise, ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," is returned:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection().isEmpty();\n\n// true\n")),(0,a.kt)("h4",{id:"method-isnotempty"},(0,a.kt)("inlineCode",{parentName:"h4"},"isNotEmpty()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"isNotEmpty")," method returns ",(0,a.kt)("inlineCode",{parentName:"p"},"true")," if the collection is not empty; otherwise, ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," is returned:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection().isNotEmpty();\n\n// false\n")),(0,a.kt)("h4",{id:"method-last"},(0,a.kt)("inlineCode",{parentName:"h4"},"last()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"last")," method returns the last model in the collection that passes a given truth test:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n {{"name", "Rose"}, {"votes", 350}},\n};\n\nUser *user = users.last([](User *const user)\n{\n return user->getAttribute("votes") < 300;\n});\n\n// {{"name", "John"}, {"votes", 200}}\n')),(0,a.kt)("p",null,"If no model passes a given truth test then the value of the second ",(0,a.kt)("inlineCode",{parentName:"p"},"defaultModel")," argument will be returned, its default value is the ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr"),"."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using NullVariant = Orm::Utils::NullVariant;\n\nUser defaultUser {{"name", NullVariant::QString()},\n {"votes", NullVariant::ULongLong()}};\n\nUser *user = users.last([](User *const user)\n{\n return user->getAttribute("votes") < 100;\n},\n &defaultUser);\n\n/*\n {{"name", NullVariant::QString()},\n {"votes", NullVariant::ULongLong()}}\n*/\n')),(0,a.kt)("p",null,"You can also call all ",(0,a.kt)("inlineCode",{parentName:"p"},"last")," overloads provided by the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qlist.html#last"},(0,a.kt)("inlineCode",{parentName:"a"},"QList::last")),"."),(0,a.kt)("h4",{id:"method-load"},(0,a.kt)("inlineCode",{parentName:"h4"},"load()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"load")," method eager loads the given relationships for all models in the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'users.load({"comments", "posts"});\n\nusers.load("comments.author");\n\nusers.load({{"comments"}, {"posts", [](auto &query)\n{\n query.whereEq("active", true);\n}}});\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"relations")," argument format is the same as for TinyBuilder's ",(0,a.kt)("a",{parentName:"p",href:"/tinyorm/relationships#lazy-eager-loading"},(0,a.kt)("inlineCode",{parentName:"a"},"load"))," method."),(0,a.kt)("h4",{id:"method-map"},(0,a.kt)("inlineCode",{parentName:"h4"},"map()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," method iterates through the collection and passes a ",(0,a.kt)("strong",{parentName:"p"},"copy")," of each model to the given lambda expression. The lambda expression is free to modify the model and return it, thus forming a new collection of modified models:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n};\n\nauto usersAdded = users.map([](User &&userCopy)\n{\n if (userCopy.getAttribute("name") == "John")\n userCopy["votes"] = userCopy.getAttribute("votes") + 1;\n\n return std::move(userCopy);\n});\n\n/*\n {\n {{"name", "John"}, {"price", 201}},\n {{"name", "Jack"}, {"price", 400}},\n }\n*/\n')),(0,a.kt)("p",null,"The second ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," overload allows to return the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'QVector usersAdded = users.map([](User &&userCopy)\n{\n const auto votesRef = userCopy["votes"];\n\n if (userCopy.getAttribute("name") == "John")\n votesRef = userCopy.getAttribute("votes") + 1;\n\n return votesRef->value();\n});\n\n// {201, 400}\n')),(0,a.kt)("p",null,"Both overloads allow to pass the lambda expression with two arguments, whereas the second argument can be an index of the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::size_t")," type."),(0,a.kt)("admonition",{type:"caution"},(0,a.kt)("p",{parentName:"admonition"},"Like most other collection methods, ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," returns a new collection instance; it does not modify the collection it is called on. If you want to modify the original collection in place, use the ",(0,a.kt)("a",{parentName:"p",href:"#method-each"},(0,a.kt)("inlineCode",{parentName:"a"},"each"))," method.")),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"The model copy is passed to the lambda expression even if the ",(0,a.kt)("inlineCode",{parentName:"p"},"map")," iterates over a collection of model pointers ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection"),". The models are dereferenced behind the scene.")),(0,a.kt)("h4",{id:"method-mapwithkeys"},(0,a.kt)("inlineCode",{parentName:"h4"},"mapWithKeys()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"mapWithKeys")," method iterates through the collection and passes each model to the given lambda expression. It returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::unordered_map")," and the lambda expression should return the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::pair")," containing a single column / value pair:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 1}, {"name", "John"}, {"email", "john@example.com"}},\n {{"id", 2}, {"name", "Jill"}, {"email", "jill@example.com"}},\n};\n\nauto usersMap = users.mapWithKeys(\n [](User *const user) -> std::pair\n{\n return {user->getKeyCasted(), user->getAttribute("name")};\n});\n\n// {{1, \'John\'}, {2, \'Jill\'}}\n')),(0,a.kt)("p",null,"You can also map IDs to the model pointers:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"auto usersMap = users.mapWithKeys(\n [](User *const user) -> std::pair\n{\n return {user->getKeyCasted(), user};\n});\n")),(0,a.kt)("h4",{id:"method-mapwithmodelkeys"},(0,a.kt)("inlineCode",{parentName:"h4"},"mapWithModelKeys()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"mapWithModelKeys")," maps the primary keys to the ",(0,a.kt)("inlineCode",{parentName:"p"},"Model *"),", it returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::unordered_map"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"auto usersMap = users.mapWithModelKeys();\n")),(0,a.kt)("h4",{id:"method-modelkeys"},(0,a.kt)("inlineCode",{parentName:"h4"},"modelKeys()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"modelKeys")," method returns the primary keys for all models in the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 1}, {"name", "John"}},\n {{"id", 2}, {"name", "Jill"}},\n {{"id", 3}, {"name", "Kate"}},\n {{"id", 5}, {"name", "Rose"}},\n};\n\nusers.modelKeys(); // Returns QVector\nusers.modelKeys();\n\n// {1, 2, 3, 5}\n')),(0,a.kt)("h4",{id:"method-only"},(0,a.kt)("inlineCode",{parentName:"h4"},"only()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"only")," method returns all of the models that have the given primary keys:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"ModelsCollection usersResult = users.only({1, 2, 3});\n")),(0,a.kt)("p",null,"An empty collection is returned if the ",(0,a.kt)("inlineCode",{parentName:"p"},"ids")," argument is empty ",(0,a.kt)("inlineCode",{parentName:"p"},"only({})"),"."),(0,a.kt)("p",null,"The order of models in the collection is preserved."),(0,a.kt)("p",null,"For the inverse of ",(0,a.kt)("inlineCode",{parentName:"p"},"only"),", see the ",(0,a.kt)("a",{parentName:"p",href:"#method-except"},"except")," method."),(0,a.kt)("h4",{id:"method-pluck"},(0,a.kt)("inlineCode",{parentName:"h4"},"pluck()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"pluck")," method retrieves all of the values for a given column, the following overload returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"id", 1}, {"name", "Desk"}},\n {{"id", 2}, {"name", "Chair"}},\n};\n\nauto plucked = products.pluck("name");\n\n// {Desk, Chair}\n')),(0,a.kt)("p",null,"The second overload allows returning the custom type ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto plucked = products.pluck("name");\n')),(0,a.kt)("p",null,"You may also specify how you wish the resulting collection to be keyed, this overload returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::map"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto plucked = products.pluck("name", "id");\n\n// {{1, "Desk"}, {2, "Chair"}}\n')),(0,a.kt)("p",null,"If duplicate keys exist, the last matching attribute will be inserted into the plucked collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection collection {\n {{"brand", "Tesla"}, {"color", "red"}},\n {{"brand", "Pagani"}, {"color", "white"}},\n {{"brand", "Tesla"}, {"color", "black"}},\n {{"brand", "Pagani"}, {"color", "orange"}},\n};\n\nauto plucked = collection.pluck("color", "brand");\n\n// {{\'Tesla\', \'black\'}, {\'Pagani\', \'orange"}}\n')),(0,a.kt)("h4",{id:"method-reject"},(0,a.kt)("inlineCode",{parentName:"h4"},"reject()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"reject")," method filters the collection using the given lambda expression. The lambda should return ",(0,a.kt)("inlineCode",{parentName:"p"},"true")," if the model should be removed from the resulting collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto usersWithNote = users.reject([](const User *const user)\n{\n return user->getAttribute("note").isNull();\n});\n')),(0,a.kt)("p",null,"You may also pass the lambda expression with two arguments, whereas the second argument can be an index of the ",(0,a.kt)("inlineCode",{parentName:"p"},"std::size_t")," type."),(0,a.kt)("p",null,"For the inverse of the ",(0,a.kt)("inlineCode",{parentName:"p"},"reject")," method, see the ",(0,a.kt)("a",{parentName:"p",href:"#method-filter"},(0,a.kt)("inlineCode",{parentName:"a"},"filter"))," method."),(0,a.kt)("h4",{id:"method-sort"},(0,a.kt)("inlineCode",{parentName:"h4"},"sort()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," method sorts the models collection by primary keys:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nauto sorted = users.sort();\n\n/*\n {\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n }\n*/\n')),(0,a.kt)("p",null,"You may pass a predicate and projection callbacks to the ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," method with your own algorithms. Refer to the CPP reference documentation on ",(0,a.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/algorithm/ranges/sort"},(0,a.kt)("inlineCode",{parentName:"a"},"ranges::sort")),", which is what the ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," method calls internally."),(0,a.kt)("p",null,"You can eg. sort by multiple columns, for an alternative method of multi-column sorting look at ",(0,a.kt)("a",{parentName:"p",href:"#method-sortby"},"sortBy"),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 350}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "John"}, {"votes", 150}},\n {{"name", "Kate"}, {"votes", 200}},\n};\n\nauto sorted = users.sort([](const User *const left,\n const User *const right)\n{\n const auto leftValue = left->getAttribute("name");\n const auto rightValue = right->getAttribute("name");\n\n if (leftValue == rightValue)\n return left->getAttribute("votes") <\n right->getAttribute("votes");\n\n return leftValue < rightValue;\n});\n\n/*\n {\n {{"name", "John"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Kate"}, {"votes", 200}},\n {{"name", "Kate"}, {"votes", 350}},\n }\n*/\n')),(0,a.kt)("p",null,"The order of equal elements is not guaranteed to be preserved."),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"You can use the ",(0,a.kt)("a",{parentName:"p",href:"#method-stablesort"},"stable")," sort method variants to preserve the order of equal models.")),(0,a.kt)("h4",{id:"method-sortby"},(0,a.kt)("inlineCode",{parentName:"h4"},"sortBy()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"sortBy")," method sorts the collection by the given column, this overload needs the template argument so it can cast the attribute value before comparing:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n};\n\nauto sorted = users.sortBy("name");\n\n/*\n {\n {{"name", "Jack"}, {"votes", 400}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Kate"}, {"votes", 150}},\n }\n*/\n')),(0,a.kt)("p",null,"You may pass the projection callback to determine how to sort the collection's models:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto sorted = users.sortBy([](User *const user)\n{\n return user->getAttribute("votes");\n});\n\n/*\n {\n {{"name", "Kate"}, {"votes", 150}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n }\n*/\n')),(0,a.kt)("p",null,"If you would like to sort your collection by multiple columns, you may pass a vector of comparison lambda expressions that define each sort operation to the ",(0,a.kt)("inlineCode",{parentName:"p"},"sortBy")," method, in the following example is the ",(0,a.kt)("inlineCode",{parentName:"p"},"name")," column sorted in ascending order and the second ",(0,a.kt)("inlineCode",{parentName:"p"},"votes")," column is sorted in descending order:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using AttributeUtils = Orm::Tiny::Utils::Attribute;\n\nModelsCollection users {\n {{"name", "Kate"}, {"votes", 350}},\n {{"name", "John"}, {"votes", 200}},\n {{"name", "John"}, {"votes", 150}},\n {{"name", "Kate"}, {"votes", 200}},\n};\n\nauto sorted = users.sortBy({\n [](const User *const left, const User *const right)\n {\n return AttributeUtils::compareForSortBy(\n left->getAttribute("name"),\n right->getAttribute("name"));\n },\n [](const User *const left, const User *const right)\n {\n return AttributeUtils::compareForSortByDesc(\n left->getAttribute("votes"),\n right->getAttribute("votes"));\n },\n});\n\n/*\n {\n {{"name", "John"}, {"votes", 200}},\n {{"name", "John"}, {"votes", 150}},\n {{"name", "Kate"}, {"votes", 350}},\n {{"name", "Kate"}, {"votes", 200}},\n }\n*/\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"AttributeUtils::compareForSortBy")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"compareForSortByDesc")," methods are helper methods, they are needed because the Qt framework doesn't define ",(0,a.kt)("inlineCode",{parentName:"p"},"<=>")," spaceship operator on its types, it doesn't support the three-way comparison."),(0,a.kt)("p",null,"The order of equal elements is not guaranteed to be preserved."),(0,a.kt)("h4",{id:"method-sortbydesc"},(0,a.kt)("inlineCode",{parentName:"h4"},"sortByDesc()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sortby"},(0,a.kt)("inlineCode",{parentName:"a"},"sortBy"))," method but will sort the collection in the opposite order."),(0,a.kt)("p",null,"The order of equal elements is not guaranteed to be preserved."),(0,a.kt)("h4",{id:"method-sortdesc"},(0,a.kt)("inlineCode",{parentName:"h4"},"sortDesc()")),(0,a.kt)("p",null,"This method will sort the collection in the opposite order as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sort"},(0,a.kt)("inlineCode",{parentName:"a"},"sort"))," method:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nauto sorted = users.sortDesc();\n\n/*\n {\n {{"id", 3}, {"name", "John"}},\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 1}, {"name", "Jack"}},\n }\n*/\n')),(0,a.kt)("p",null,"The order of equal elements is not guaranteed to be preserved."),(0,a.kt)("h4",{id:"method-stablesort"},(0,a.kt)("inlineCode",{parentName:"h4"},"stableSort()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sort"},(0,a.kt)("inlineCode",{parentName:"a"},"sort"))," method but will preserve the order of equal elements (guaranteed to be preserved)."),(0,a.kt)("h4",{id:"method-stablesortby"},(0,a.kt)("inlineCode",{parentName:"h4"},"stableSortBy()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sortby"},(0,a.kt)("inlineCode",{parentName:"a"},"sortBy"))," method but will preserve the order of equal elements (guaranteed to be preserved)."),(0,a.kt)("h4",{id:"method-stablesortbydesc"},(0,a.kt)("inlineCode",{parentName:"h4"},"stableSortByDesc()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sortbydesc"},(0,a.kt)("inlineCode",{parentName:"a"},"sortByDesc"))," method but will sort the collection in the opposite order and preserve the order of equal elements (guaranteed to be preserved)."),(0,a.kt)("h4",{id:"method-stablesortdesc"},(0,a.kt)("inlineCode",{parentName:"h4"},"stableSortDesc()")),(0,a.kt)("p",null,"This method has the same signature as the ",(0,a.kt)("a",{parentName:"p",href:"#method-sortdesc"},(0,a.kt)("inlineCode",{parentName:"a"},"sortDesc"))," method but will sort the collection in the opposite order and preserve the order of equal elements (guaranteed to be preserved)."),(0,a.kt)("h4",{id:"method-tap"},(0,a.kt)("inlineCode",{parentName:"h4"},"tap()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"tap"),' method passes a collection to the given lambda expression, allowing you to "tap" into the collection at a specific point and do something with the models while not affecting the collection itself:'),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nusers.sort()\n .tap([](/*const */ModelsCollection &usersRef)\n{\n qDebug() << "IDs after sorting:"\n << usersRef.template modelKeys();\n})\n .value("id");\n\n// 1\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"tap")," method returns an lvalue ",(0,a.kt)("strong",{parentName:"p"},"reference")," to the currently processed collection."),(0,a.kt)("p",null,"It can be also called on ",(0,a.kt)("inlineCode",{parentName:"p"},"ModelsCollection")," rvalues, it returns an rvalue reference in this case."),(0,a.kt)("h4",{id:"method-tobase"},(0,a.kt)("inlineCode",{parentName:"h4"},"toBase()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toBase")," method returns a copy of the underlying vector represented by the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},"QVector = users.toBase();\n")),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("a",{parentName:"p",href:"#method-tobase"},(0,a.kt)("inlineCode",{parentName:"a"},"toBase"))," is an alias to the ",(0,a.kt)("inlineCode",{parentName:"p"},"all")," method.")),(0,a.kt)("h4",{id:"method-tojson"},(0,a.kt)("inlineCode",{parentName:"h4"},"toJson()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," method converts the collection of models with all nested relations into a JSON serialized ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qbytearray.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QByteArray")),"."),(0,a.kt)("p",null,"It returns an empty array for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("admonition",{type:"info"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," method accepts the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qjsondocument.html#JsonFormat-enum"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonDocument::JsonFormat")),", possible values are ",(0,a.kt)("inlineCode",{parentName:"p"},"QJsonDocument::Indented")," or ",(0,a.kt)("inlineCode",{parentName:"p"},"QJsonDocument::Compact"),".")),(0,a.kt)("h4",{id:"method-tojsonarray"},(0,a.kt)("inlineCode",{parentName:"h4"},"toJsonArray()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toJsonArray")," method converts the collection of models with all nested relations into a ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qjsonarray.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonArray")),"."),(0,a.kt)("h4",{id:"method-tojsondocument"},(0,a.kt)("inlineCode",{parentName:"h4"},"toJsonDocument()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toJsonDocument")," method converts the collection of models with all nested relations into a ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qjsondocument.html"},(0,a.kt)("inlineCode",{parentName:"a"},"QJsonDocument")),"."),(0,a.kt)("h4",{id:"method-tomap"},(0,a.kt)("inlineCode",{parentName:"h4"},"toMap()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toMap")," method converts the collection of models with all nested relations into an attributes map ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),"."),(0,a.kt)("p",null,"It returns an empty ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and a null ",(0,a.kt)("abbr",{title:"QVariant::fromValue(nullptr)"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariant"))," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("h4",{id:"method-tomapvariantlist"},(0,a.kt)("inlineCode",{parentName:"h4"},"toMapVariantList()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toMapVariantList")," method converts the collection of models with all nested relations into an attributes map, but it returns the ",(0,a.kt)("abbr",{title:"QList"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList"))," instead of the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector"),"."),(0,a.kt)("p",null,"It returns an empty ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and a null ",(0,a.kt)("abbr",{title:"QVariant::fromValue(nullptr)"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariant"))," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toMapVariantList")," method is internally needed by the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," related methods.")),(0,a.kt)("h4",{id:"method-toquery"},(0,a.kt)("inlineCode",{parentName:"h4"},"toQuery()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toQuery")," method returns the ",(0,a.kt)("inlineCode",{parentName:"p"},"TinyBuilder")," instance containing a ",(0,a.kt)("inlineCode",{parentName:"p"},"whereIn")," constraint with the collection of models' primary keys:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'using Models::User;\n\nModelsCollection users = User::whereEq("status", "VIP")->get();\n\nusers.toQuery()->update({\n {"status", "Administrator"},\n});\n')),(0,a.kt)("h4",{id:"method-tovector"},(0,a.kt)("inlineCode",{parentName:"h4"},"toVector()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toVector")," method converts the collection of models with all nested relations into an attributes vector ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector>"),"."),(0,a.kt)("p",null,"It returns an empty ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and a null ",(0,a.kt)("abbr",{title:"QVariant::fromValue(nullptr)"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariant"))," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("h4",{id:"method-tovectorvariantlist"},(0,a.kt)("inlineCode",{parentName:"h4"},"toVectorVariantList()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toVectorVariantList")," method converts the collection of models with all nested relations into an attributes vector, but it returns the ",(0,a.kt)("abbr",{title:"QList"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList"))," instead of the ",(0,a.kt)("inlineCode",{parentName:"p"},"QVector>"),"."),(0,a.kt)("p",null,"It returns an empty ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariantList")," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"many")," type relations and a null ",(0,a.kt)("abbr",{title:"QVariant::fromValue(nullptr)"},(0,a.kt)("inlineCode",{parentName:"p"},"QVariant"))," for empty ",(0,a.kt)("inlineCode",{parentName:"p"},"one")," type relations."),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"toVectorVariantList")," method is internally needed by the ",(0,a.kt)("inlineCode",{parentName:"p"},"toJson")," related methods.")),(0,a.kt)("h4",{id:"method-unique"},(0,a.kt)("inlineCode",{parentName:"h4"},"unique()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"unique")," method returns all of the unique models in the ",(0,a.kt)("strong",{parentName:"p"},"sorted")," collection. Any models with the same primary key as another model in the collection are removed:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nauto unique = users.unique();\n\n/*\n {\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n }\n*/\n')),(0,a.kt)("p",null,"It sorts the collection internally because the ",(0,a.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/algorithm/ranges/unique"},(0,a.kt)("inlineCode",{parentName:"a"},"ranges::unique"))," can correctly operate only on the sorted container. You can disable it by passing ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," using the first ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," parameter:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto unique = users.sort().unique(false);\n\n/*\n {\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 3}, {"name", "John"}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-uniqueby"},(0,a.kt)("inlineCode",{parentName:"h4"},"uniqueBy()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"uniqueBy")," method returns all of the unique models in the ",(0,a.kt)("strong",{parentName:"p"},"sorted")," collection by the given column. Any models with the same column value as another model in the collection are removed. It needs the template argument, so it can cast the attribute value before comparing:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}},\n {{"name", "Jack"}},\n {{"name", "John"}},\n {{"name", "Jack"}},\n};\n\nauto unique = users.uniqueBy("name");\n\n/*\n {\n {{"name", "Jack"}},\n {{"name", "John"}},\n {{"name", "Kate"}},\n }\n*/\n')),(0,a.kt)("p",null,"It sorts the collection internally because the ",(0,a.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/algorithm/ranges/unique"},(0,a.kt)("inlineCode",{parentName:"a"},"ranges::unique"))," can correctly operate only on the sorted container. You can disable it by passing ",(0,a.kt)("inlineCode",{parentName:"p"},"false")," using the second ",(0,a.kt)("inlineCode",{parentName:"p"},"sort")," parameter:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto unique = users.sortBy("name")\n .uniqueBy("name", false);\n\n/*\n {\n {{"name", "Jack"}},\n {{"name", "John"}},\n {{"name", "Kate"}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-uniquerelaxed"},(0,a.kt)("inlineCode",{parentName:"h4"},"uniqueRelaxed()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"uniqueRelaxed")," method returns all of the unique models in the collection, it doesn't need a sorted collection. Any models with the same primary key as another model in the collection are removed:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 3}, {"name", "John"}},\n {{"id", 1}, {"name", "Jack"}},\n};\n\nauto unique = users.uniqueRelaxed();\n\n/*\n {\n {{"id", 2}, {"name", "Kate"}},\n {{"id", 1}, {"name", "Jack"}},\n {{"id", 3}, {"name", "John"}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-uniquerelaxedby"},(0,a.kt)("inlineCode",{parentName:"h4"},"uniqueRelaxedBy()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"uniqueRelaxedBy")," method returns all of the unique models in the collection by the given column, it doesn't need a sorted collection, but it needs the template argument, so it can cast the attribute value before comparing:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "Kate"}},\n {{"name", "Jack"}},\n {{"name", "John"}},\n {{"name", "Jack"}},\n};\n\nauto unique = users.uniqueRelaxedBy("name");\n\n/*\n {\n {{"name", "Kate"}},\n {{"name", "Jack"}},\n {{"name", "John"}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-value"},(0,a.kt)("inlineCode",{parentName:"h4"},"value()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"value")," method retrieves a given value from the first model of the collection:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection users {\n {{"name", "John"}, {"votes", 200}},\n {{"name", "Jack"}, {"votes", 400}},\n};\n\nQVariant votes = users.value("votes");\n\n// 200\n')),(0,a.kt)("p",null,"Alternatively, you can cast an obtained ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant")," value to the given type by the second ",(0,a.kt)("inlineCode",{parentName:"p"},"value")," overload:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'quint64 votes = users.value("votes");\n')),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"value")," method also accepts the second ",(0,a.kt)("inlineCode",{parentName:"p"},"defaultValue")," argument, which will be returned if a collection is empty, the first model is ",(0,a.kt)("inlineCode",{parentName:"p"},"nullptr"),", or a model doesn't contain the given column:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto votes = ModelsCollection().value("votes", 0);\n\n// 0\n')),(0,a.kt)("p",null,"You can also call all ",(0,a.kt)("inlineCode",{parentName:"p"},"value")," overloads provided by the ",(0,a.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt-6/qlist.html#value"},(0,a.kt)("inlineCode",{parentName:"a"},"QList::value")),"."),(0,a.kt)("h4",{id:"method-where"},(0,a.kt)("inlineCode",{parentName:"h4"},"where()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"where")," method filters the collection by a given column / value pair:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 100}},\n};\n\nauto filtered = products.where("price", "=", 100);\n\n/*\n {\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Door"}, {"price", 100}},\n }\n*/\n')),(0,a.kt)("p",null,"For convenience, if you want to verify that a column is ",(0,a.kt)("inlineCode",{parentName:"p"},"=")," to a given value, you may call ",(0,a.kt)("inlineCode",{parentName:"p"},"whereEq")," method. Similar ",(0,a.kt)("inlineCode",{parentName:"p"},"XxxEq")," methods are also defined for other commands:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'auto filtered = products.whereEq("price", 100);\n')),(0,a.kt)("p",null,"Optionally, you may pass a comparison operator as the second argument.",(0,a.kt)("br",null),"Supported operators are ",(0,a.kt)("inlineCode",{parentName:"p"},"="),", ",(0,a.kt)("inlineCode",{parentName:"p"},"!="),", ",(0,a.kt)("inlineCode",{parentName:"p"},"<"),", ",(0,a.kt)("inlineCode",{parentName:"p"},">"),", ",(0,a.kt)("inlineCode",{parentName:"p"},"<="),", and ",(0,a.kt)("inlineCode",{parentName:"p"},">="),":"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 250}},\n};\n\nauto filtered = products.where("price", ">", 150);\n\n/*\n {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Door"}, {"price", 250}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-wherebetween"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereBetween()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereBetween")," method filters the collection by determining if a specified models' attribute value is within a given range:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 80}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Pencil"}, {"price", 30}},\n {{"product", "Door"}, {"price", 100}},\n};\n\nauto filtered = products.whereBetween("price", {100, 200});\n\n/*\n {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 100}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-wherein"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereIn()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereIn")," method filters models from the collection that have a specified attribute value that is contained within the given unordered set:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 250}},\n};\n\nauto filtered = products.whereIn("price", {100, 200});\n\n/*\n {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n }\n*/\n')),(0,a.kt)("p",null,"An empty collection is returned if the ",(0,a.kt)("inlineCode",{parentName:"p"},"values")," argument is empty ",(0,a.kt)("inlineCode",{parentName:"p"},'whereIn("price", {})'),"."),(0,a.kt)("p",null,"The order of models in the collection is preserved."),(0,a.kt)("h4",{id:"method-wherenotbetween"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereNotBetween()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereNotBetween")," method filters the collection by determining if a specified models' attribute value is outside of a given range:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 80}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Pencil"}, {"price", 30}},\n {{"product", "Door"}, {"price", 100}},\n};\n\nauto filtered = products.whereNotBetween("price", {100, 200});\n\n/*\n {\n {{"product", "Chair"}, {"price", 80}},\n {{"product", "Pencil"}, {"price", 30}},\n }\n*/\n')),(0,a.kt)("h4",{id:"method-wherenotin"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereNotIn()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereNotIn")," method removes models from the collection that have a specified attribute value that is contained within the given unordered set:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'ModelsCollection products {\n {{"product", "Desk"}, {"price", 200}},\n {{"product", "Chair"}, {"price", 100}},\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 250}},\n};\n\nauto filtered = products.whereNotIn("price", {100, 200});\n\n/*\n {\n {{"product", "Bookcase"}, {"price", 150}},\n {{"product", "Door"}, {"price", 250}},\n }\n*/\n')),(0,a.kt)("p",null,"All of the models are returned if the ",(0,a.kt)("inlineCode",{parentName:"p"},"values")," argument is empty ",(0,a.kt)("inlineCode",{parentName:"p"},'whereNotIn("price", {})'),"."),(0,a.kt)("p",null,"The order of models in the collection is preserved."),(0,a.kt)("h4",{id:"method-wherenotnull"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereNotNull()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereNotNull")," method returns models from the collection where the given column is not ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," QVariant:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing NullVariant = Orm::Utils::NullVariant;\n\nModelsCollection users {\n {{"name", "John"}},\n {{"name", NullVariant::QString()}},\n {{"name", "Jack"}},\n};\n\nauto filtered = users.whereNotNull("name");\n\n/*\n {\n {{"name", "John"}},\n {{"name", "Jack"}},\n }\n*/\n')),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"NullVariant")," class returns the correct ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," QVariant for both Qt 5 ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant(QVariant::String)")," and also Qt 6 ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant(QMetaType(QMetaType::QString))"),".")),(0,a.kt)("h4",{id:"method-wherenull"},(0,a.kt)("inlineCode",{parentName:"h4"},"whereNull()")),(0,a.kt)("p",null,"The ",(0,a.kt)("inlineCode",{parentName:"p"},"whereNull")," method returns models from the collection where the given column is ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," QVariant:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre"},'#include \n\nusing NullVariant = Orm::Utils::NullVariant;\n\nModelsCollection users {\n {{"name", "John"}},\n {{"name", NullVariant::QString()}},\n {{"name", "Jack"}},\n};\n\nauto filtered = users.whereNotNull("name");\n\n// {{"name", NullVariant::QString()}}\n')),(0,a.kt)("admonition",{type:"note"},(0,a.kt)("p",{parentName:"admonition"},"The ",(0,a.kt)("inlineCode",{parentName:"p"},"NullVariant")," class returns the correct ",(0,a.kt)("inlineCode",{parentName:"p"},"null")," QVariant for both Qt 5 ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant(QVariant::String)")," and also Qt 6 ",(0,a.kt)("inlineCode",{parentName:"p"},"QVariant(QMetaType(QMetaType::QString))"),"."))))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/59b1a96c.def9b0a5.js b/assets/js/59b1a96c.6afbbfdf.js similarity index 85% rename from assets/js/59b1a96c.def9b0a5.js rename to assets/js/59b1a96c.6afbbfdf.js index a16bf425a..84aaf9e88 100644 --- a/assets/js/59b1a96c.def9b0a5.js +++ b/assets/js/59b1a96c.6afbbfdf.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[67],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>y});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var s=r.createContext({}),p=function(e){var t=r.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},u=function(e){var t=p(e.components);return r.createElement(s.Provider,{value:t},e.children)},m="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},c=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,i=e.originalType,s=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),m=p(a),c=n,y=m["".concat(s,".").concat(c)]||m[c]||d[c]||i;return a?r.createElement(y,o(o({ref:t},u),{},{components:a})):r.createElement(y,o({ref:t},u))}));function y(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var i=a.length,o=new Array(i);o[0]=c;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[m]="string"==typeof e?e:n,o[1]=l;for(var p=2;p{a.r(t),a.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>d,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var r=a(7462),n=(a(7294),a(3905));const i={sidebar_position:0,sidebar_label:"\ud83d\udd25 Prologue",slug:"/",hide_table_of_contents:!0,description:"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the QtCore and QtSql libraries. The code is written in the modern C++20 way and is heavily tested with 3269 unit and functional tests.",keywords:["c++ orm","prologue","tinyorm"]},o="Prologue",l={unversionedId:"README",id:"README",title:"Prologue",description:"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the QtCore and QtSql libraries. The code is written in the modern C++20 way and is heavily tested with 3269 unit and functional tests.",source:"@site/docs/README.mdx",sourceDirName:".",slug:"/",permalink:"/",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/README.mdx",tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"\ud83d\udd25 Prologue",slug:"/",hide_table_of_contents:!0,description:"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the QtCore and QtSql libraries. The code is written in the modern C++20 way and is heavily tested with 3269 unit and functional tests.",keywords:["c++ orm","prologue","tinyorm"]},sidebar:"tinyormSidebar",next:{title:"\ud83d\udd27 Dependencies",permalink:"/dependencies"}},s={},p=[{value:"Documentation Sitemap",id:"documentation-sitemap",level:5},{value:"Current versions",id:"current-versions",level:5}],u={toc:p},m="wrapper";function d(e){let{components:t,...a}=e;return(0,n.kt)(m,(0,r.Z)({},u,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("h1",{id:"prologue"},"Prologue"),(0,n.kt)("p",null,"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the ",(0,n.kt)("inlineCode",{parentName:"p"},"QtCore")," and ",(0,n.kt)("inlineCode",{parentName:"p"},"QtSql")," libraries."),(0,n.kt)("p",null,"The code is written in the modern C++20 way and is ",(0,n.kt)("strong",{parentName:"p"},"heavily")," tested with ",(0,n.kt)("strong",{parentName:"p"},"3269")," unit and functional tests. Almost all the query builder methods are unit tested. The TinyORM's query builder code and the code which is responsible for obtaining relationships, is tested by functional tests against all supported databases. The code coverage is good enough to guarantee API and behavior compatibility."),(0,n.kt)("admonition",{type:"tip"},(0,n.kt)("p",{parentName:"admonition"},"For a quick look at what's inside, check out the ",(0,n.kt)("a",{parentName:"p",href:"/features-summary"},"Features Summary"),".")),(0,n.kt)("admonition",{type:"info"},(0,n.kt)("p",{parentName:"admonition"},"If you don't want to use full ",(0,n.kt)("a",{parentName:"p",href:"/tinyorm/getting-started"},(0,n.kt)("inlineCode",{parentName:"a"},"ORM")),", then you can use only the ",(0,n.kt)("a",{parentName:"p",href:"/database/query-builder"},(0,n.kt)("inlineCode",{parentName:"a"},"Query Builder")),", which is outstanding. \ud83d\udd25 This way you can avoid writing raw SQL queries and your code will run on all ",(0,n.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"supported databases"),".")),(0,n.kt)("h5",{id:"documentation-sitemap"},"Documentation Sitemap"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/dependencies"},"Dependencies")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/supported-compilers"},"Supported Compilers")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/getting-started"},"Database"),(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/getting-started"},"Getting Started")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/query-builder"},"Query Builder")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/migrations"},"Migrations")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/seeding"},"Seeding")))),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/getting-started"},"TinyORM"),(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/getting-started"},"Getting Started")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/relationships"},"Relationships")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/collections"},"Collections")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/casts"},"Casts")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/serialization"},"Serialization")))),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/building/tinyorm"},"Building"),(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/building/tinyorm"},"TinyORM")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/building/hello-world"},"Hello world")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/building/migrations"},"Migrations")))),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/features-summary"},"Features Summary")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/sponsors"},"Sponsors"))),(0,n.kt)("h5",{id:"current-versions"},"Current versions"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("strong",{parentName:"li"},"TinyORM")," v0.36.5"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("strong",{parentName:"li"},"tom")," v0.7.0")))}d.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[67],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>y});var r=a(7294);function n(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}var s=r.createContext({}),p=function(e){var t=r.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},m=function(e){var t=p(e.components);return r.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},c=r.forwardRef((function(e,t){var a=e.components,n=e.mdxType,i=e.originalType,s=e.parentName,m=l(e,["components","mdxType","originalType","parentName"]),u=p(a),c=n,y=u["".concat(s,".").concat(c)]||u[c]||d[c]||i;return a?r.createElement(y,o(o({ref:t},m),{},{components:a})):r.createElement(y,o({ref:t},m))}));function y(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var i=a.length,o=new Array(i);o[0]=c;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[u]="string"==typeof e?e:n,o[1]=l;for(var p=2;p{a.r(t),a.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>d,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var r=a(7462),n=(a(7294),a(3905));const i={sidebar_position:0,sidebar_label:"\ud83d\udd25 Prologue",slug:"/",hide_table_of_contents:!0,description:"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the QtCore and QtSql libraries. The code is written in the modern C++20 way and is heavily tested with 3366 unit and functional tests.",keywords:["c++ orm","prologue","tinyorm"]},o="Prologue",l={unversionedId:"README",id:"README",title:"Prologue",description:"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the QtCore and QtSql libraries. The code is written in the modern C++20 way and is heavily tested with 3366 unit and functional tests.",source:"@site/docs/README.mdx",sourceDirName:".",slug:"/",permalink:"/",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/README.mdx",tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,sidebar_label:"\ud83d\udd25 Prologue",slug:"/",hide_table_of_contents:!0,description:"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the QtCore and QtSql libraries. The code is written in the modern C++20 way and is heavily tested with 3366 unit and functional tests.",keywords:["c++ orm","prologue","tinyorm"]},sidebar:"tinyormSidebar",next:{title:"\ud83d\udd27 Dependencies",permalink:"/dependencies"}},s={},p=[{value:"Documentation Sitemap",id:"documentation-sitemap",level:5},{value:"Current versions",id:"current-versions",level:5}],m={toc:p},u="wrapper";function d(e){let{components:t,...a}=e;return(0,n.kt)(u,(0,r.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,n.kt)("h1",{id:"prologue"},"Prologue"),(0,n.kt)("p",null,"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the ",(0,n.kt)("inlineCode",{parentName:"p"},"QtCore")," and ",(0,n.kt)("inlineCode",{parentName:"p"},"QtSql")," libraries."),(0,n.kt)("p",null,"The code is written in the modern C++20 way and is ",(0,n.kt)("strong",{parentName:"p"},"heavily")," tested with ",(0,n.kt)("strong",{parentName:"p"},"3366")," unit and functional tests. Almost all the query builder methods are unit tested. The TinyORM's query builder code and the code which is responsible for obtaining relationships, is tested by functional tests against all supported databases. The code coverage is good enough to guarantee API and behavior compatibility."),(0,n.kt)("admonition",{type:"tip"},(0,n.kt)("p",{parentName:"admonition"},"For a quick look at what's inside, check out the ",(0,n.kt)("a",{parentName:"p",href:"/features-summary"},"Features Summary"),".")),(0,n.kt)("admonition",{type:"info"},(0,n.kt)("p",{parentName:"admonition"},"If you don't want to use full ",(0,n.kt)("a",{parentName:"p",href:"/tinyorm/getting-started"},(0,n.kt)("inlineCode",{parentName:"a"},"ORM")),", then you can use only the ",(0,n.kt)("a",{parentName:"p",href:"/database/query-builder"},(0,n.kt)("inlineCode",{parentName:"a"},"Query Builder")),", which is outstanding. \ud83d\udd25 This way you can avoid writing raw SQL queries and your code will run on all ",(0,n.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"supported databases"),".")),(0,n.kt)("h5",{id:"documentation-sitemap"},"Documentation Sitemap"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/dependencies"},"Dependencies")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/supported-compilers"},"Supported Compilers")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/getting-started"},"Database"),(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/getting-started"},"Getting Started")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/query-builder"},"Query Builder")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/migrations"},"Migrations")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/database/seeding"},"Seeding")))),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/getting-started"},"TinyORM"),(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/getting-started"},"Getting Started")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/relationships"},"Relationships")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/collections"},"Collections")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/casts"},"Casts")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/tinyorm/serialization"},"Serialization")))),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/building/tinyorm"},"Building"),(0,n.kt)("ul",{parentName:"li"},(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/building/tinyorm"},"TinyORM")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/building/hello-world"},"Hello world")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/building/migrations"},"Migrations")))),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/features-summary"},"Features Summary")),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("a",{parentName:"li",href:"/sponsors"},"Sponsors"))),(0,n.kt)("h5",{id:"current-versions"},"Current versions"),(0,n.kt)("ul",null,(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("strong",{parentName:"li"},"TinyORM")," v0.37.0"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("strong",{parentName:"li"},"tom")," v0.8.0"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("strong",{parentName:"li"},"TinyDrivers")," v0.1.0"),(0,n.kt)("li",{parentName:"ul"},(0,n.kt)("strong",{parentName:"li"},"TinyMySql")," v0.1.0")))}d.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/5b254f70.287f094d.js b/assets/js/5b254f70.287f094d.js new file mode 100644 index 000000000..d4894921f --- /dev/null +++ b/assets/js/5b254f70.287f094d.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[116],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>c});var a=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},m=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},h=a.forwardRef((function(e,t){var n=e.components,i=e.mdxType,l=e.originalType,s=e.parentName,m=r(e,["components","mdxType","originalType","parentName"]),p=d(n),h=i,c=p["".concat(s,".").concat(h)]||p[h]||u[h]||l;return n?a.createElement(c,o(o({ref:t},m),{},{components:n})):a.createElement(c,o({ref:t},m))}));function c(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var l=n.length,o=new Array(l);o[0]=h;var r={};for(var s in t)hasOwnProperty.call(t,s)&&(r[s]=t[s]);r.originalType=e,r[p]="string"==typeof e?e:i,o[1]=r;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>u,frontMatter:()=>l,metadata:()=>r,toc:()=>d});var a=n(7462),i=(n(7294),n(3905));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"]},o="TinyORM: Getting Started",r={unversionedId:"tinyorm/getting-started",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,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinyorm/getting-started.mdx",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"}},s={},d=[{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}],m={toc:d},p="wrapper";function u(e){let{components:t,...n}=e;return(0,i.kt)(p,(0,a.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"tinyorm-getting-started"},"TinyORM: Getting Started"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#generating-model-classes"},"Generating Model Classes")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#tinyorm-model-conventions"},"TinyORM Model Conventions"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#table-names"},"Table Names")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#primary-keys"},"Primary Keys")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#timestamps"},"Timestamps")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#database-connections"},"Database Connections")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#default-attribute-values"},"Default Attribute Values")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#retrieving-models"},"Retrieving Models"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#containers"},"Containers")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#chunking-results"},"Chunking Results")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#advanced-subqueries"},"Advanced Subqueries")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#retrieving-single-models-and-aggregates"},"Retrieving Single Models / Aggregates"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#retrieving-or-creating-models"},"Retrieving Or Creating Models")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#retrieving-aggregates"},"Retrieving Aggregates")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#inserting-and-updating-models"},"Inserting & Updating Models"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#inserts"},"Inserts")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#updates"},"Updates")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#mass-assignment"},"Mass Assignment")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#upserts"},"Upserts")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#deleting-models"},"Deleting Models"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#soft-deleting"},"Soft Deleting")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#querying-soft-deleted-models"},"Querying Soft Deleted Models")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#truncate-table"},"Truncate Table")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#replicating-models"},"Replicating Models")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#comparing-models"},"Comparing Models"))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,'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.'),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"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.kt)("a",{parentName:"p",href:"/database/getting-started#configuration"},"database configuration documentation"),".")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"If you want to see a model in which are used all possible TinyORM features you can look at the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tests/models/models/torrent.hpp"},(0,i.kt)("inlineCode",{parentName:"a"},"torrent.hpp"))," in the TinyORM's tests, this ",(0,i.kt)("inlineCode",{parentName:"p"},"Models::Torrent")," class serves also as a showcase, so all possible features are defined in it.")),(0,i.kt)("h2",{id:"generating-model-classes"},"Generating Model Classes"),(0,i.kt)("p",null,"To get started, let's create the simplest TinyORM model. Models typically live in the ",(0,i.kt)("inlineCode",{parentName:"p"},"database\\models")," directory and extend the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Model")," class. You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"make:model")," command to generate a new model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:model User\n")),(0,i.kt)("p",null,"If you would like to generate a database ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},"migration")," or ",(0,i.kt)("a",{parentName:"p",href:"/database/seeding"},"seeder")," when you generate the model, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"--migration"),"/",(0,i.kt)("inlineCode",{parentName:"p"},"-m")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"--seeder"),"/",(0,i.kt)("inlineCode",{parentName:"p"},"-s")," options:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:model User --migration --seeder\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"--force")," option forces overwriting of existing files:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:model User --migration --seeder --force\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"make:model")," help command:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:model --help\n")),(0,i.kt)("p",null,"Few examples:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-powershell"},"# 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")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"Writing a ",(0,i.kt)("inlineCode",{parentName:"p"},"make:model")," commands is superb with the ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#tab-completion"},"tab completion"),".")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"--path")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"--realpath")," options work the same as for the ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#generating-migrations"},(0,i.kt)("inlineCode",{parentName:"a"},"make:migration"))," command.")),(0,i.kt)("h2",{id:"tinyorm-model-conventions"},"TinyORM Model Conventions"),(0,i.kt)("p",null,"Let's examine a basic model class and discuss some of TinyORM's key conventions:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#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")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source tree contains the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tests/models/models/torrent.hpp#L43"},(0,i.kt)("inlineCode",{parentName:"a"},"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.")),(0,i.kt)("h3",{id:"table-names"},"Table Names"),(0,i.kt)("p",null,"After glancing at the example above, you may have noticed that we did not tell TinyORM which database table corresponds to our ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"Flight")," model stores records in the ",(0,i.kt)("inlineCode",{parentName:"p"},"flights")," table, while an ",(0,i.kt)("inlineCode",{parentName:"p"},"AirTrafficController")," model would store records in an ",(0,i.kt)("inlineCode",{parentName:"p"},"air_traffic_controllers")," table."),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"u_table")," data member on the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h3",{id:"primary-keys"},"Primary Keys"),(0,i.kt)("p",null,"TinyORM will also assume that each model's corresponding database table has a primary key column named ",(0,i.kt)("inlineCode",{parentName:"p"},"id"),". If necessary, you may define a private ",(0,i.kt)("inlineCode",{parentName:"p"},"u_primaryKey")," data member on your model to specify a different column that serves as your model's primary key:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"u_incrementing")," data member on your model that is set to ",(0,i.kt)("inlineCode",{parentName:"p"},"false"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#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")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"Non-numeric primary keys are not currently implemented, ",(0,i.kt)("inlineCode",{parentName:"p"},"u_incrementing")," code logic is fully implemented, but it is only one part to make it fully work.")),(0,i.kt)("h4",{id:"composite-primary-keys"},'"Composite" Primary Keys'),(0,i.kt)("p",null,'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.'),(0,i.kt)("h3",{id:"timestamps"},"Timestamps"),(0,i.kt)("p",null,"By default, TinyORM expects ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"u_timestamps")," data member on your model with a value of ",(0,i.kt)("inlineCode",{parentName:"p"},"false"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#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")),(0,i.kt)("a",{id:"timestamps-u_dates"}),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates")," static data member controls the casting of timestamp attributes. The ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," columns are automatically added to the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates")," string list when the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_timestamps")," is ",(0,i.kt)("inlineCode",{parentName:"p"},"true"),". Also, the ",(0,i.kt)("a",{parentName:"p",href:"#soft-deleting"},(0,i.kt)("inlineCode",{parentName:"a"},"Soft Deleting"))," feature adds the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," column to the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates"),"."),(0,i.kt)("p",null,"You may add additional columns to the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates")," list. After that, these columns will be automatically formatted using the format in the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dateFormat")," data member during the ",(0,i.kt)("inlineCode",{parentName:"p"},"setAttribute")," method call:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("p",null,"If you need to customize the format of your model's timestamps, set the private ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"QDateTime")," documentation:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"If you need to customize the format of your model's time columns, set the private ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"QTime")," documentation. The default value for ",(0,i.kt)("inlineCode",{parentName:"p"},"u_timeFormat")," is ",(0,i.kt)("inlineCode",{parentName:"p"},"HH:mm:ss"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! The storage format of the model\'s time columns. */\nQString u_timeFormat {"HH:mm:ss.zzz"};\n')),(0,i.kt)("p",null,"The default value for datetime or timestamp columns is ",(0,i.kt)("inlineCode",{parentName:"p"},"yyyy-MM-dd HH:mm:ss")," and for time columns is ",(0,i.kt)("inlineCode",{parentName:"p"},"HH:mm:ss"),"."),(0,i.kt)("h5",{id:"unix-timestamps"},"Unix timestamps"),(0,i.kt)("p",null,"You can set the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dateFormat")," to ",(0,i.kt)("inlineCode",{parentName:"p"},"U")," if you want to store dates in the database as unix timestamps:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"QString u_dateFormat {QLatin1Char('U')};\n")),(0,i.kt)("p",null,"In this case ",(0,i.kt)("strong",{parentName:"p"},"all")," date attributes set in the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates")," will be handled as unix timestamps, so also the ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," timestamp attributes."),(0,i.kt)("p",null,"To create unix timestamp columns using the ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},"tom migrations")," you should use ",(0,i.kt)("inlineCode",{parentName:"p"},"integer")," types:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("flights", [](Blueprint &table)\n{\n table.bigInteger("created_at").nullable();\n table.bigInteger("updated_at").nullable();\n});\n')),(0,i.kt)("h5",{id:"custom-timestamp-column-names"},"Custom timestamp column names"),(0,i.kt)("p",null,"If you need to customize the names of the columns used to store the timestamps, you may define ",(0,i.kt)("inlineCode",{parentName:"p"},"CREATED_AT")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"UPDATED_AT")," private static getter methods on your model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"touching-timestamps"},"Touching timestamps"),(0,i.kt)("p",null,"You can explicitly touch timestamps using the ",(0,i.kt)("inlineCode",{parentName:"p"},"touch")," method defined on the Model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::find(1);\n\nflight->touch();\nflight->touch("added_on"); // Custom column name\n')),(0,i.kt)("p",null,"You can also touch multiple rows at once using the ",(0,i.kt)("inlineCode",{parentName:"p"},"touch")," method defined on the TinyBuilder:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto [affected, query] = Flight::whereEq("status", "new")->touch();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"touch")," method may also be called when building a ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'flight->history()->touch();\nflight->history()->whereEq("status", "new").touch();\n')),(0,i.kt)("h3",{id:"database-connections"},"Database Connections"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"u_connection")," private data member on the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"In special cases, when you want to query the database through a different connection, you can use ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::on")," method, which takes the connection name as the first argument:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto user = User::on("sqlite")->find(1);\n')),(0,i.kt)("h2",{id:"default-attribute-values"},"Default Attribute Values"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"u_attributes")," data member on your model, it has to be ",(0,i.kt)("strong",{parentName:"p"},"static")," and can be ",(0,i.kt)("strong",{parentName:"p"},"const"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"Use the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::instance")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::instanceHeap")," related methods to instantiate a model that contains a ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," in Default Attribute Values, or if attributes you want to pass to the model's constructor contain a ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance ",(0,i.kt)("small",null,"(problem is described below)"),".")),(0,i.kt)("h5",{id:"qdatetime-and-connection-name-problem"},"QDateTime and connection name problem"),(0,i.kt)("p",null,"If your Default Attribute Values or attributes that you can pass to the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model")," constructor contain the ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance, then ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," throws an exception. You have to use the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::instance")," related methods to create such a Model."),(0,i.kt)("p",null,"Virtually everything important is covered in the thrown exception, but let me summarize it. The problem is that the ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance is converted to a string based on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::u_dateFormat"),", or if not defined, the date format from ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Query::Grammars::Grammar")," will be used. This ",(0,i.kt)("inlineCode",{parentName:"p"},"QueryGrammar")," is obtained from ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::DatabaseConnection")," and because of that TinyORM needs to know the ",(0,i.kt)("strong",{parentName:"p"},"connection name")," and that's the crux of this problem. You can define your connection name using the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::u_connection")," in your derived model class, but this derived model ",(0,i.kt)("strong",{parentName:"p"},"is not yet initialized"),", so the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::u_connection")," is also not initialized."),(0,i.kt)("p",null,"So if the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::u_connection")," is not yet initialized, ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," can't obtain the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::DatabaseConnection")," -> ",(0,i.kt)("inlineCode",{parentName:"p"},"QueryGrammar")," -> ",(0,i.kt)("inlineCode",{parentName:"p"},"dateFormat"),"."),(0,i.kt)("h2",{id:"retrieving-models"},"Retrieving Models"),(0,i.kt)("p",null,"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.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder")," allowing you to fluently query the database table associated with the model. The model's ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," method will retrieve all of the records from the model's associated database table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\n#include "models/flight.hpp"\n\nfor (const auto &flight : Flight::all())\n qDebug() << flight["name"].toString();\n')),(0,i.kt)("h4",{id:"building-queries"},"Building Queries"),(0,i.kt)("p",null,"The TinyORM ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," method will return all of the results in the model's table. However, since each TinyORM model serves as a ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder"),", you may add additional constraints to queries and then invoke the ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," method to retrieve the results:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flights = Flight::whereEq("active", 1)\n ->orderBy("name")\n .take(10)\n .get();\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"Since TinyORM models are query builders, you should review all of the methods provided by TinyORM's ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder"),". You may use any of these methods when writing your TinyORM queries.")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"All the static methods defined on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Model")," class, which start building queries like ",(0,i.kt)("inlineCode",{parentName:"p"},"where"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"latest"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"oldest"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"with"),", ... return ",(0,i.kt)("inlineCode",{parentName:"p"},"std::unique_ptr>"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyBuilder = Orm::Tiny::Builder")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"Model")," template argument is queried model class.")),(0,i.kt)("h4",{id:"refreshing-models"},"Refreshing Models"),(0,i.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"fresh")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"refresh")," methods. The ",(0,i.kt)("inlineCode",{parentName:"p"},"fresh")," method will re-retrieve the model from the database. The existing model instance will not be affected:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::whereEq("number", "FR 900")->first();\n\nauto freshFlight = flight->fresh();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::whereEq("number", "FR 900")->first();\n\nflight->setAttribute("number", "FR 456");\n\nflight->refresh();\n\nflight->getAttribute("number"); // "FR 900"\n')),(0,i.kt)("h3",{id:"containers"},"Containers"),(0,i.kt)("p",null,"As we have seen, TinyORM methods like ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," retrieve multiple records from the database. Since these methods return a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector"),", you can iterate it like any other container with the ",(0,i.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/language/range-for"},"Range-based for loop"),", ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/containers.html#stl-style-iterators"},"STL-Style Iterators"),", ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/containers.html#java-style-iterators"},"Java-Style Iterators")," or ",(0,i.kt)("a",{parentName:"p",href:"https://www.walletfox.com/course/quickref_range_v3.php"},"Ranges"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\n#include "models/flight.hpp"\n\nfor (const auto &flight : Flight::all())\n qDebug() << flight["name"].toString();\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"An ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," method is defined on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Model")," class and ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," method is defined on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Builder"),", may be also referred as ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyBuilder"),", and on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Query::Builder")," alias ",(0,i.kt)("inlineCode",{parentName:"p"},"QueryBuilder"),".")),(0,i.kt)("h3",{id:"chunking-results"},"Chunking Results"),(0,i.kt)("p",null,"Your application may run out of memory if you attempt to load tens of thousands of TinyORM records via the ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," methods. Instead of using these methods, the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunk")," method may be used to process large numbers of models more efficiently."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"chunk")," method will provide significantly reduced memory usage when working with a large number of models:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"Flight::chunk(200, [](QVector &&flights, const int /*unused*/)\n{\n for (auto &&flight : flights) {\n //\n }\n\n return true;\n});\n")),(0,i.kt)("p",null,"The first argument passed to the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.'),(0,i.kt)("p",null,"If you are filtering the results of the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunk")," method based on a column that you will also be updating while iterating over the results, you should use the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunkById")," method. Using the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunk")," method in these scenarios could lead to unexpected and inconsistent results. Internally, the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunkById")," method will always retrieve models with an ",(0,i.kt)("inlineCode",{parentName:"p"},"id")," column greater than the last model in the previous chunk:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("h3",{id:"advanced-subqueries"},"Advanced Subqueries"),(0,i.kt)("h4",{id:"subquery-selects"},"Subquery Selects"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"destinations")," and a table of ",(0,i.kt)("inlineCode",{parentName:"p"},"flights")," to destinations. The ",(0,i.kt)("inlineCode",{parentName:"p"},"flights")," table contains an ",(0,i.kt)("inlineCode",{parentName:"p"},"arrived_at")," column which indicates when the flight arrived at the destination."),(0,i.kt)("p",null,"Using the subquery functionality available to the query builder's ",(0,i.kt)("inlineCode",{parentName:"p"},"select")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"addSelect")," methods, we can select all of the ",(0,i.kt)("inlineCode",{parentName:"p"},"destinations")," and the name of the flight that most recently arrived at that destination using a single query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"subquery-ordering"},"Subquery Ordering"),(0,i.kt)("p",null,"In addition, the query builder's ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("h2",{id:"retrieving-single-models-and-aggregates"},"Retrieving Single Models / Aggregates"),(0,i.kt)("p",null,"In addition to retrieving all of the records matching a given query, you may also retrieve single records using the ",(0,i.kt)("inlineCode",{parentName:"p"},"find"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"first"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"firstWhere"),", or ",(0,i.kt)("inlineCode",{parentName:"p"},"firstWhereEq")," methods. Instead of returning a vector of models, these methods return a single model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"Sometimes you may wish to perform some other action if no results are found. The ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"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")),(0,i.kt)("p",null,"To obtain only a subset of the model's attributes you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::only")," method, it returns the ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"not-found-exceptions"},"Not Found Exceptions"),(0,i.kt)("p",null,"Sometimes you may wish to throw an exception if a model is not found. The ",(0,i.kt)("inlineCode",{parentName:"p"},"findOrFail")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"firstOrFail")," methods will retrieve the first result of the query; however, if no result is found, an ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::ModelNotFoundError")," will be thrown:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::findOrFail(1);\n\nauto flight = Flight::where("legs", ">", 3)->firstOrFail();\n')),(0,i.kt)("h3",{id:"retrieving-or-creating-models"},"Retrieving Or Creating Models"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"QVector")," argument with the optional second ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," argument:"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"firstOrNew")," method, like ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"firstOrNew")," has not yet been persisted to the database. You will need to manually call the ",(0,i.kt)("inlineCode",{parentName:"p"},"save")," method to persist it:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h3",{id:"retrieving-aggregates"},"Retrieving Aggregates"),(0,i.kt)("p",null,"When interacting with TinyORM models, you may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"count"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"sum"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"max"),", and other ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder#aggregates"},"aggregate methods")," provided by the ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder"),". As you might expect, these methods return a scalar value instead of a TinyORM model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto count = Flight::whereEq("active", 1)->count();\n\nauto max = Flight::whereEq("active", 1)->max("price");\n')),(0,i.kt)("h2",{id:"inserting-and-updating-models"},"Inserting & Updating Models"),(0,i.kt)("h3",{id:"inserts"},"Inserts"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"save")," method on the model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\n// Store a new flight in the database\nFlight flight;\nflight.setAttribute("name", "Slovakia to Czech");\nflight.save();\n')),(0,i.kt)("p",null,"In this example, we assign the ",(0,i.kt)("inlineCode",{parentName:"p"},"name")," attribute of the ",(0,i.kt)("inlineCode",{parentName:"p"},"Flight")," model instance. When we call the ",(0,i.kt)("inlineCode",{parentName:"p"},"save")," method, a record will be inserted into the database. The model's ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," timestamps will automatically be set when the ",(0,i.kt)("inlineCode",{parentName:"p"},"save")," method is called, so there is no need to set them manually."),(0,i.kt)("p",null,"Alternatively, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"create")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\nauto flight = Flight::create({\n {"name", "London to Paris"},\n});\n')),(0,i.kt)("p",null,"However, before using the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method, you will need to specify either a ",(0,i.kt)("inlineCode",{parentName:"p"},"u_fillable")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("a",{parentName:"p",href:"#mass-assignment"},"mass assignment documentation"),"."),(0,i.kt)("h3",{id:"updates"},"Updates"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"save")," method. Again, the ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," timestamp will automatically be updated, so there is no need to manually set its value:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\nauto flight = Flight::find(1);\n\nflight->setAttribute("name", "Paris to London");\n\nflight->save();\n')),(0,i.kt)("h4",{id:"mass-updates"},"Mass Updates"),(0,i.kt)("p",null,"Updates can also be performed against models that match a given query. In this example, all flights that are ",(0,i.kt)("inlineCode",{parentName:"p"},"active")," and have a ",(0,i.kt)("inlineCode",{parentName:"p"},"destination")," of ",(0,i.kt)("inlineCode",{parentName:"p"},"San Diego")," will be marked as delayed:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Flight::whereEq("active", 1)\n ->whereEq("destination", "San Diego")\n .update({{"delayed", 1}});\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"update")," method expects the ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," of column and value pairs representing the columns that should be updated."),(0,i.kt)("h4",{id:"examining-attribute-changes"},"Examining Attribute Changes"),(0,i.kt)("p",null,"TinyORM provides the ",(0,i.kt)("inlineCode",{parentName:"p"},"isDirty"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"isClean"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"wasChanged")," methods to examine the internal state of your model and determine how its attributes have changed from when the model was originally retrieved."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"isDirty")," method to determine if a particular attribute is dirty. The ",(0,i.kt)("inlineCode",{parentName:"p"},"isClean")," will determine if an attribute has remained unchanged since the model was retrieved. This method also accepts an optional attribute argument:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("h3",{id:"mass-assignment"},"Mass Assignment"),(0,i.kt)("p",null,"You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"create"),' method to "save" a new model using a single C++ statement. The inserted model instance will be returned to you by the method:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\nauto flight = Flight::create({\n {"name", "London to Paris"},\n});\n')),(0,i.kt)("p",null,"However, before using the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method, you will need to specify either a ",(0,i.kt)("inlineCode",{parentName:"p"},"u_fillable")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"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."),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"is_admin")," parameter through an HTTP request, which is then passed to your model's ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method, allowing the user to escalate themselves to an administrator."),(0,i.kt)("p",null,"So, to get started, you should define which model attributes you want to make mass assignable. You may do this using the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_fillable")," static data member on the model. For example, let's make the ",(0,i.kt)("inlineCode",{parentName:"p"},"name")," attribute of our ",(0,i.kt)("inlineCode",{parentName:"p"},"Flight")," model mass assignable:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"Once you have specified which attributes are mass assignable, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method to insert a new record in the database. The ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method returns the newly created model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::create({{"name", "London to Paris"}});\n')),(0,i.kt)("p",null,"If you already have a model instance, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"fill")," method to populate it with the vector of attributes:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'flight.fill({{"name", "Amsterdam to Frankfurt"}});\n')),(0,i.kt)("h4",{id:"allowing-mass-assignment"},"Allowing Mass Assignment"),(0,i.kt)("p",null,"If you would like to make all of your attributes mass assignable, you may define your model's ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"fill"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"create"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"update")," methods:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#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")),(0,i.kt)("h3",{id:"upserts"},"Upserts"),(0,i.kt)("p",null,"Occasionally, you may need to update an existing model or create a new model if no matching model exists."),(0,i.kt)("p",null,"In the example below, if a flight exists with a ",(0,i.kt)("inlineCode",{parentName:"p"},"departure")," location of ",(0,i.kt)("inlineCode",{parentName:"p"},"Oakland")," and a ",(0,i.kt)("inlineCode",{parentName:"p"},"destination")," location of ",(0,i.kt)("inlineCode",{parentName:"p"},"San Diego"),", its ",(0,i.kt)("inlineCode",{parentName:"p"},"price")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::updateOrCreate(\n {{"departure", "Oakland"}, {"destination", "San Diego"}},\n {{"price", 99}, {"discounted", 1}}\n);\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"firstOrCreate")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updateOrCreate")," methods persist the model, so there's no need to manually call the ",(0,i.kt)("inlineCode",{parentName:"p"},"save")," method.")),(0,i.kt)("p",null,'If you would like to perform multiple "upserts" in a single query, then you should use the ',(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"upsert")," method will automatically set the ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," timestamps if timestamps are enabled on the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"All databases except SQL Server require the columns in the second argument of the ",(0,i.kt)("inlineCode",{parentName:"p"},"upsert"),' method to have a "primary" or "unique" index. In addition, the MySQL database driver ignores the second argument of the ',(0,i.kt)("inlineCode",{parentName:"p"},"upsert"),' method and always uses the "primary" and "unique" indexes of the table to detect existing records.')),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"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.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.3/en/insert-on-duplicate.html"},"documentation"),". The MySQL server version is auto-detected and can be overridden in the ",(0,i.kt)("a",{parentName:"p",href:"/database/getting-started#configuration"},"configuration"),".")),(0,i.kt)("h2",{id:"deleting-models"},"Deleting Models"),(0,i.kt)("p",null,"To delete a model, you may call the ",(0,i.kt)("inlineCode",{parentName:"p"},"remove"),", or an alias ",(0,i.kt)("inlineCode",{parentName:"p"},"deleteRow")," method on the model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\nauto flight = Flight::find(1);\n\nflight->remove();\n')),(0,i.kt)("h4",{id:"deleting-an-existing-model-by-its-primary-key"},"Deleting An Existing Model By Its Primary Key"),(0,i.kt)("p",null,"In the example above, we are retrieving the model from the database before calling the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"destroy")," method. In addition to accepting the single primary key, the ",(0,i.kt)("inlineCode",{parentName:"p"},"destroy")," method can accept multiple primary keys:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"Flight::destroy(1);\n\nFlight::destroy({1, 2, 3});\n")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"destroy")," method loads models from the database and calls the ",(0,i.kt)("inlineCode",{parentName:"p"},"remove")," method on each model individually, the reason for this is future compatibility with events.")),(0,i.kt)("h4",{id:"deleting-models-using-queries"},"Deleting Models Using Queries"),(0,i.kt)("p",null,"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto deletedRows = Flight::whereEq("active", 0)->remove();\n')),(0,i.kt)("h3",{id:"soft-deleting"},"Soft Deleting"),(0,i.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::SoftDeletes")," base class to the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"SoftDeletes")," base class will automatically cast the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," attribute to the ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance for you (it adds the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," column to the model's ",(0,i.kt)("a",{parentName:"p",href:"#timestamps-u_dates"},(0,i.kt)("inlineCode",{parentName:"a"},"u_dates"))," list).")),(0,i.kt)("p",null,"You should also add the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," column to your database table. The TinyORM ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},"schema builder")," contains a helper method to create this column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("flights", [](Blueprint &table)\n{\n table.softDeletes();\n});\n\nSchema::table("flights", [](Blueprint &table)\n{\n table.dropSoftDeletes();\n});\n')),(0,i.kt)("p",null,"Now, when you call the ",(0,i.kt)("inlineCode",{parentName:"p"},"remove")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"deleteModel")," method on the model, the ",(0,i.kt)("inlineCode",{parentName:"p"},"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."),(0,i.kt)("p",null,"To determine if a given model instance has been soft deleted, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"trashed")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"if (flight->trashed()) {\n //\n}\n")),(0,i.kt)("h4",{id:"restoring-soft-deleted-models"},"Restoring Soft Deleted Models"),(0,i.kt)("p",null,'Sometimes you may wish to "un-delete" a soft deleted model. To restore a soft deleted model, you may call the ',(0,i.kt)("inlineCode",{parentName:"p"},"restore")," method on a model instance. The ",(0,i.kt)("inlineCode",{parentName:"p"},"restore")," method will set the model's ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," column to ",(0,i.kt)("inlineCode",{parentName:"p"},"null"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->restore();\n")),(0,i.kt)("p",null,"You may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"restore")," method in a query to restore multiple models:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Flight::withTrashed()\n ->whereEq("airline_id", 1)\n .restore();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"restore")," method may also be used when building ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," queries:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->restore();\n")),(0,i.kt)("h4",{id:"permanently-deleting-models"},"Permanently Deleting Models"),(0,i.kt)("p",null,"Sometimes you may need to truly remove a model from your database. You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"forceDelete")," method (or it's alias ",(0,i.kt)("inlineCode",{parentName:"p"},"forceRemove"),") to permanently remove a soft deleted model from the database table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->forceDelete();\n")),(0,i.kt)("p",null,"You may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"forceDelete")," method when building TinyORM relationship queries:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->forceDelete();\n")),(0,i.kt)("h3",{id:"querying-soft-deleted-models"},"Querying Soft Deleted Models"),(0,i.kt)("h4",{id:"including-soft-deleted-models"},"Including Soft Deleted Models"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"withTrashed")," method on the query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flights = Flight::withTrashed()\n ->whereEq("account_id", 1)\n .get();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"withTrashed")," method may also be called when building a ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->withTrashed().get();\n")),(0,i.kt)("h4",{id:"retrieving-only-soft-deleted-models"},"Retrieving Only Soft Deleted Models"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"onlyTrashed")," method will retrieve ",(0,i.kt)("strong",{parentName:"p"},"only")," soft deleted models:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flights = Flight::onlyTrashed()\n ->whereEq("airline_id", 1)\n .get();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"onlyTrashed")," method may also be called when building a ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->onlyTrashed().get();\n")),(0,i.kt)("h4",{id:"excluding-soft-deleted-models"},"Excluding Soft Deleted Models"),(0,i.kt)("p",null,"As noted above, soft deleted models will automatically be excluded from query results. However, you may force soft deleted models to be ",(0,i.kt)("strong",{parentName:"p"},"excluded")," in a query's results by calling the ",(0,i.kt)("inlineCode",{parentName:"p"},"withoutTrashed")," method on the query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flights = Flight::withoutTrashed()\n ->whereEq("account_id", 1)\n .get();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"withoutTrashed")," method may also be called when building a ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->withoutTrashed().get();\n")),(0,i.kt)("h3",{id:"truncate-table"},"Truncate Table"),(0,i.kt)("p",null,"You may call the ",(0,i.kt)("inlineCode",{parentName:"p"},"truncate")," method to delete all of the model's associated database records. The ",(0,i.kt)("inlineCode",{parentName:"p"},"truncate")," operation will also reset any auto-incrementing IDs on the model's associated table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"Flight::truncate();\n")),(0,i.kt)("h2",{id:"replicating-models"},"Replicating Models"),(0,i.kt)("p",null,"You may create an unsaved copy of an existing model instance using the ",(0,i.kt)("inlineCode",{parentName:"p"},"replicate")," method. This method is particularly useful when you have model instances that share many of the same attributes:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("p",null,"To exclude one or more attributes from being replicated to the new model, you may pass an unordered_set to the ",(0,i.kt)("inlineCode",{parentName:"p"},"replicate")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("h2",{id:"comparing-models"},"Comparing Models"),(0,i.kt)("p",null,'Sometimes you may need to determine if two models are the "same" or not. The ',(0,i.kt)("inlineCode",{parentName:"p"},"is")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"isNot")," methods may be used to quickly verify two models have the same primary key, table, and database connection or not:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"if (post->is(anotherPost)) {\n //\n}\n\nif (post->isNot(anotherPost)) {\n //\n}\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"is")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"isNot")," methods are also available when using the ",(0,i.kt)("inlineCode",{parentName:"p"},"belongsTo")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"hasOne")," ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationships"),". This method is particularly helpful when you would like to compare a related model without issuing a query to retrieve that model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"if (post->author()->is(user)) {\n //\n}\n")),(0,i.kt)("h5",{id:"equality-comparison"},"Equality comparison"),(0,i.kt)("p",null,"The base ",(0,i.kt)("inlineCode",{parentName:"p"},"Model")," class also defines the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"model1 == model2")," expression guarantees that these two models are exactly the same."),(0,i.kt)("p",null,"It would be appropriate to mention that this comparison also includes relations, which means it will also compare ",(0,i.kt)("strong",{parentName:"p"},"all")," models (including their data members) these relations contain."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/5b254f70.a04863b0.js b/assets/js/5b254f70.a04863b0.js deleted file mode 100644 index 53aa500cb..000000000 --- a/assets/js/5b254f70.a04863b0.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[116],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>c});var a=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},m=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},h=a.forwardRef((function(e,t){var n=e.components,i=e.mdxType,l=e.originalType,s=e.parentName,m=r(e,["components","mdxType","originalType","parentName"]),p=d(n),h=i,c=p["".concat(s,".").concat(h)]||p[h]||u[h]||l;return n?a.createElement(c,o(o({ref:t},m),{},{components:n})):a.createElement(c,o({ref:t},m))}));function c(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var l=n.length,o=new Array(l);o[0]=h;var r={};for(var s in t)hasOwnProperty.call(t,s)&&(r[s]=t[s]);r.originalType=e,r[p]="string"==typeof e?e:i,o[1]=r;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>u,frontMatter:()=>l,metadata:()=>r,toc:()=>d});var a=n(7462),i=(n(7294),n(3905));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"]},o="TinyORM: Getting Started",r={unversionedId:"tinyorm/getting-started",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,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinyorm/getting-started.mdx",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"}},s={},d=[{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}],m={toc:d},p="wrapper";function u(e){let{components:t,...n}=e;return(0,i.kt)(p,(0,a.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"tinyorm-getting-started"},"TinyORM: Getting Started"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#generating-model-classes"},"Generating Model Classes")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#tinyorm-model-conventions"},"TinyORM Model Conventions"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#table-names"},"Table Names")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#primary-keys"},"Primary Keys")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#timestamps"},"Timestamps")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#database-connections"},"Database Connections")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#default-attribute-values"},"Default Attribute Values")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#retrieving-models"},"Retrieving Models"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#containers"},"Containers")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#chunking-results"},"Chunking Results")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#advanced-subqueries"},"Advanced Subqueries")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#retrieving-single-models-and-aggregates"},"Retrieving Single Models / Aggregates"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#retrieving-or-creating-models"},"Retrieving Or Creating Models")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#retrieving-aggregates"},"Retrieving Aggregates")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#inserting-and-updating-models"},"Inserting & Updating Models"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#inserts"},"Inserts")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#updates"},"Updates")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#mass-assignment"},"Mass Assignment")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#upserts"},"Upserts")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#deleting-models"},"Deleting Models"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#soft-deleting"},"Soft Deleting")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#querying-soft-deleted-models"},"Querying Soft Deleted Models")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#truncate-table"},"Truncate Table")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#replicating-models"},"Replicating Models")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#comparing-models"},"Comparing Models"))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,'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.'),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"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.kt)("a",{parentName:"p",href:"/database/getting-started#configuration"},"database configuration documentation"),".")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"If you want to see a model in which are used all possible TinyORM features you can look at the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tests/models/models/torrent.hpp"},(0,i.kt)("inlineCode",{parentName:"a"},"torrent.hpp"))," in the TinyORM's tests, this ",(0,i.kt)("inlineCode",{parentName:"p"},"Models::Torrent")," class serves also as a showcase, so all possible features are defined in it.")),(0,i.kt)("h2",{id:"generating-model-classes"},"Generating Model Classes"),(0,i.kt)("p",null,"To get started, let's create the simplest TinyORM model. Models typically live in the ",(0,i.kt)("inlineCode",{parentName:"p"},"database\\models")," directory and extend the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Model")," class. You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"make:model")," command to generate a new model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:model User\n")),(0,i.kt)("p",null,"If you would like to generate a database ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},"migration")," or ",(0,i.kt)("a",{parentName:"p",href:"/database/seeding"},"seeder")," when you generate the model, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"--migration"),"/",(0,i.kt)("inlineCode",{parentName:"p"},"-m")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"--seeder"),"/",(0,i.kt)("inlineCode",{parentName:"p"},"-s")," options:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:model User --migration --seeder\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"--force")," option forces overwriting of existing files:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:model User --migration --seeder --force\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"make:model")," help command:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:model --help\n")),(0,i.kt)("p",null,"Few examples:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-powershell"},"# 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")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"Writing a ",(0,i.kt)("inlineCode",{parentName:"p"},"make:model")," commands is superb with the ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#tab-completion"},"tab completion"),".")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"--path")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"--realpath")," options work the same as for the ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#generating-migrations"},(0,i.kt)("inlineCode",{parentName:"a"},"make:migration"))," command.")),(0,i.kt)("h2",{id:"tinyorm-model-conventions"},"TinyORM Model Conventions"),(0,i.kt)("p",null,"Let's examine a basic model class and discuss some of TinyORM's key conventions:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#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")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source tree contains the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tests/models/models/torrent.hpp#L43"},(0,i.kt)("inlineCode",{parentName:"a"},"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.")),(0,i.kt)("h3",{id:"table-names"},"Table Names"),(0,i.kt)("p",null,"After glancing at the example above, you may have noticed that we did not tell TinyORM which database table corresponds to our ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"Flight")," model stores records in the ",(0,i.kt)("inlineCode",{parentName:"p"},"flights")," table, while an ",(0,i.kt)("inlineCode",{parentName:"p"},"AirTrafficController")," model would store records in an ",(0,i.kt)("inlineCode",{parentName:"p"},"air_traffic_controllers")," table."),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"u_table")," data member on the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h3",{id:"primary-keys"},"Primary Keys"),(0,i.kt)("p",null,"TinyORM will also assume that each model's corresponding database table has a primary key column named ",(0,i.kt)("inlineCode",{parentName:"p"},"id"),". If necessary, you may define a private ",(0,i.kt)("inlineCode",{parentName:"p"},"u_primaryKey")," data member on your model to specify a different column that serves as your model's primary key:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"u_incrementing")," data member on your model that is set to ",(0,i.kt)("inlineCode",{parentName:"p"},"false"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#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")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"Non-numeric primary keys are not currently implemented, ",(0,i.kt)("inlineCode",{parentName:"p"},"u_incrementing")," code logic is fully implemented, but it is only one part to make it fully work.")),(0,i.kt)("h4",{id:"composite-primary-keys"},'"Composite" Primary Keys'),(0,i.kt)("p",null,'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.'),(0,i.kt)("h3",{id:"timestamps"},"Timestamps"),(0,i.kt)("p",null,"By default, TinyORM expects ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"u_timestamps")," data member on your model with a value of ",(0,i.kt)("inlineCode",{parentName:"p"},"false"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#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")),(0,i.kt)("a",{id:"timestamps-u_dates"}),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates")," static data member controls the casting of timestamp attributes. The ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," columns are automatically added to the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates")," string list when the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_timestamps")," is ",(0,i.kt)("inlineCode",{parentName:"p"},"true"),". Also, the ",(0,i.kt)("a",{parentName:"p",href:"#soft-deleting"},(0,i.kt)("inlineCode",{parentName:"a"},"Soft Deleting"))," feature adds the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," column to the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates"),"."),(0,i.kt)("p",null,"You may add additional columns to the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates")," list. After that, these columns will be automatically formatted using the format in the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dateFormat")," data member during the ",(0,i.kt)("inlineCode",{parentName:"p"},"setAttribute")," method call:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("p",null,"If you need to customize the format of your model's timestamps, set the private ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"QDateTime")," documentation:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h5",{id:"unix-timestamps"},"Unix timestamps"),(0,i.kt)("p",null,"You can set the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dateFormat")," to ",(0,i.kt)("inlineCode",{parentName:"p"},"U")," if you want to store dates in the database as unix timestamps:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"QString u_dateFormat {QLatin1Char('U')};\n")),(0,i.kt)("p",null,"In this case ",(0,i.kt)("strong",{parentName:"p"},"all")," date attributes set in the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dates")," will be handled as unix timestamps, so also the ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," timestamp attributes."),(0,i.kt)("p",null,"To create unix timestamp columns using the ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},"tom migrations")," you should use ",(0,i.kt)("inlineCode",{parentName:"p"},"integer")," types:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("flights", [](Blueprint &table)\n{\n table.bigInteger("created_at").nullable();\n table.bigInteger("updated_at").nullable();\n});\n')),(0,i.kt)("h5",{id:"custom-timestamp-column-names"},"Custom timestamp column names"),(0,i.kt)("p",null,"If you need to customize the names of the columns used to store the timestamps, you may define ",(0,i.kt)("inlineCode",{parentName:"p"},"CREATED_AT")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"UPDATED_AT")," private static getter methods on your model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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 inline static QString CREATED_AT() { return QStringLiteral("creation_date"); }\n /*! The name of the "updated at" column. */\n inline static QString UPDATED_AT() { return QStringLiteral("updated_date"); }\n};\n')),(0,i.kt)("h4",{id:"touching-timestamps"},"Touching timestamps"),(0,i.kt)("p",null,"You can explicitly touch timestamps using the ",(0,i.kt)("inlineCode",{parentName:"p"},"touch")," method defined on the Model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::find(1);\n\nflight->touch();\nflight->touch("added_on"); // Custom column name\n')),(0,i.kt)("p",null,"You can also touch multiple rows at once using the ",(0,i.kt)("inlineCode",{parentName:"p"},"touch")," method defined on the TinyBuilder:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto [affected, query] = Flight::whereEq("status", "new")->touch();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"touch")," method may also be called when building a ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'flight->history()->touch();\nflight->history()->whereEq("status", "new").touch();\n')),(0,i.kt)("h3",{id:"database-connections"},"Database Connections"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"u_connection")," private data member on the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"In special cases, when you want to query the database through a different connection, you can use ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::on")," method, which takes the connection name as the first argument:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto user = User::on("sqlite")->find(1);\n')),(0,i.kt)("h2",{id:"default-attribute-values"},"Default Attribute Values"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"u_attributes")," data member on your model, it has to be ",(0,i.kt)("strong",{parentName:"p"},"static")," and can be ",(0,i.kt)("strong",{parentName:"p"},"const"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"Use the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::instance")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::instanceHeap")," related methods to instantiate a model that contains a ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," in Default Attribute Values, or if attributes you want to pass to the model's constructor contain a ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance ",(0,i.kt)("small",null,"(problem is described below)"),".")),(0,i.kt)("h5",{id:"qdatetime-and-connection-name-problem"},"QDateTime and connection name problem"),(0,i.kt)("p",null,"If your Default Attribute Values or attributes that you can pass to the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model")," constructor contain the ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance, then ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," throws an exception. You have to use the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::instance")," related methods to create such a Model."),(0,i.kt)("p",null,"Virtually everything important is covered in the thrown exception, but let me summarize it. The problem is that the ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance is converted to a string based on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::u_dateFormat"),", or if not defined, the date format from ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Query::Grammars::Grammar")," will be used. This ",(0,i.kt)("inlineCode",{parentName:"p"},"QueryGrammar")," is obtained from ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::DatabaseConnection")," and because of that TinyORM needs to know the ",(0,i.kt)("strong",{parentName:"p"},"connection name")," and that's the crux of this problem. You can define your connection name using the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::u_connection")," in your derived model class, but this derived model ",(0,i.kt)("strong",{parentName:"p"},"is not yet initialized"),", so the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::u_connection")," is also not initialized."),(0,i.kt)("p",null,"So if the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::u_connection")," is not yet initialized, ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," can't obtain the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::DatabaseConnection")," -> ",(0,i.kt)("inlineCode",{parentName:"p"},"QueryGrammar")," -> ",(0,i.kt)("inlineCode",{parentName:"p"},"dateFormat"),"."),(0,i.kt)("h2",{id:"retrieving-models"},"Retrieving Models"),(0,i.kt)("p",null,"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.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder")," allowing you to fluently query the database table associated with the model. The model's ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," method will retrieve all of the records from the model's associated database table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\n#include "models/flight.hpp"\n\nfor (const auto &flight : Flight::all())\n qDebug() << flight["name"].toString();\n')),(0,i.kt)("h4",{id:"building-queries"},"Building Queries"),(0,i.kt)("p",null,"The TinyORM ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," method will return all of the results in the model's table. However, since each TinyORM model serves as a ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder"),", you may add additional constraints to queries and then invoke the ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," method to retrieve the results:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flights = Flight::whereEq("active", 1)\n ->orderBy("name")\n .take(10)\n .get();\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"Since TinyORM models are query builders, you should review all of the methods provided by TinyORM's ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder"),". You may use any of these methods when writing your TinyORM queries.")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"All the static methods defined on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Model")," class, which start building queries like ",(0,i.kt)("inlineCode",{parentName:"p"},"where"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"latest"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"oldest"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"with"),", ... return ",(0,i.kt)("inlineCode",{parentName:"p"},"std::unique_ptr>"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyBuilder = Orm::Tiny::Builder")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"Model")," template argument is queried model class.")),(0,i.kt)("h4",{id:"refreshing-models"},"Refreshing Models"),(0,i.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"fresh")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"refresh")," methods. The ",(0,i.kt)("inlineCode",{parentName:"p"},"fresh")," method will re-retrieve the model from the database. The existing model instance will not be affected:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::whereEq("number", "FR 900")->first();\n\nauto freshFlight = flight->fresh();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::whereEq("number", "FR 900")->first();\n\nflight->setAttribute("number", "FR 456");\n\nflight->refresh();\n\nflight->getAttribute("number"); // "FR 900"\n')),(0,i.kt)("h3",{id:"containers"},"Containers"),(0,i.kt)("p",null,"As we have seen, TinyORM methods like ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," retrieve multiple records from the database. Since these methods return a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector"),", you can iterate it like any other container with the ",(0,i.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/language/range-for"},"Range-based for loop"),", ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/containers.html#stl-style-iterators"},"STL-Style Iterators"),", ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/containers.html#java-style-iterators"},"Java-Style Iterators")," or ",(0,i.kt)("a",{parentName:"p",href:"https://www.walletfox.com/course/quickref_range_v3.php"},"Ranges"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\n#include "models/flight.hpp"\n\nfor (const auto &flight : Flight::all())\n qDebug() << flight["name"].toString();\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"An ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," method is defined on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Model")," class and ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," method is defined on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Builder"),", may be also referred as ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyBuilder"),", and on the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Query::Builder")," alias ",(0,i.kt)("inlineCode",{parentName:"p"},"QueryBuilder"),".")),(0,i.kt)("h3",{id:"chunking-results"},"Chunking Results"),(0,i.kt)("p",null,"Your application may run out of memory if you attempt to load tens of thousands of TinyORM records via the ",(0,i.kt)("inlineCode",{parentName:"p"},"all")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," methods. Instead of using these methods, the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunk")," method may be used to process large numbers of models more efficiently."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"chunk")," method will provide significantly reduced memory usage when working with a large number of models:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"Flight::chunk(200, [](QVector &&flights, const int /*unused*/)\n{\n for (auto &&flight : flights) {\n //\n }\n\n return true;\n});\n")),(0,i.kt)("p",null,"The first argument passed to the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.'),(0,i.kt)("p",null,"If you are filtering the results of the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunk")," method based on a column that you will also be updating while iterating over the results, you should use the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunkById")," method. Using the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunk")," method in these scenarios could lead to unexpected and inconsistent results. Internally, the ",(0,i.kt)("inlineCode",{parentName:"p"},"chunkById")," method will always retrieve models with an ",(0,i.kt)("inlineCode",{parentName:"p"},"id")," column greater than the last model in the previous chunk:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("h3",{id:"advanced-subqueries"},"Advanced Subqueries"),(0,i.kt)("h4",{id:"subquery-selects"},"Subquery Selects"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"destinations")," and a table of ",(0,i.kt)("inlineCode",{parentName:"p"},"flights")," to destinations. The ",(0,i.kt)("inlineCode",{parentName:"p"},"flights")," table contains an ",(0,i.kt)("inlineCode",{parentName:"p"},"arrived_at")," column which indicates when the flight arrived at the destination."),(0,i.kt)("p",null,"Using the subquery functionality available to the query builder's ",(0,i.kt)("inlineCode",{parentName:"p"},"select")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"addSelect")," methods, we can select all of the ",(0,i.kt)("inlineCode",{parentName:"p"},"destinations")," and the name of the flight that most recently arrived at that destination using a single query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"subquery-ordering"},"Subquery Ordering"),(0,i.kt)("p",null,"In addition, the query builder's ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("h2",{id:"retrieving-single-models-and-aggregates"},"Retrieving Single Models / Aggregates"),(0,i.kt)("p",null,"In addition to retrieving all of the records matching a given query, you may also retrieve single records using the ",(0,i.kt)("inlineCode",{parentName:"p"},"find"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"first"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"firstWhere"),", or ",(0,i.kt)("inlineCode",{parentName:"p"},"firstWhereEq")," methods. Instead of returning a vector of models, these methods return a single model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"Sometimes you may wish to perform some other action if no results are found. The ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"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")),(0,i.kt)("p",null,"To obtain only a subset of the model's attributes you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"Model::only")," method, it returns the ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"not-found-exceptions"},"Not Found Exceptions"),(0,i.kt)("p",null,"Sometimes you may wish to throw an exception if a model is not found. The ",(0,i.kt)("inlineCode",{parentName:"p"},"findOrFail")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"firstOrFail")," methods will retrieve the first result of the query; however, if no result is found, an ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::ModelNotFoundError")," will be thrown:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::findOrFail(1);\n\nauto flight = Flight::where("legs", ">", 3)->firstOrFail();\n')),(0,i.kt)("h3",{id:"retrieving-or-creating-models"},"Retrieving Or Creating Models"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"QVector")," argument with the optional second ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," argument:"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"firstOrNew")," method, like ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"firstOrNew")," has not yet been persisted to the database. You will need to manually call the ",(0,i.kt)("inlineCode",{parentName:"p"},"save")," method to persist it:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h3",{id:"retrieving-aggregates"},"Retrieving Aggregates"),(0,i.kt)("p",null,"When interacting with TinyORM models, you may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"count"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"sum"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"max"),", and other ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder#aggregates"},"aggregate methods")," provided by the ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder"),". As you might expect, these methods return a scalar value instead of a TinyORM model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto count = Flight::whereEq("active", 1)->count();\n\nauto max = Flight::whereEq("active", 1)->max("price");\n')),(0,i.kt)("h2",{id:"inserting-and-updating-models"},"Inserting & Updating Models"),(0,i.kt)("h3",{id:"inserts"},"Inserts"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"save")," method on the model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\n// Store a new flight in the database\nFlight flight;\nflight.setAttribute("name", "Slovakia to Czech");\nflight.save();\n')),(0,i.kt)("p",null,"In this example, we assign the ",(0,i.kt)("inlineCode",{parentName:"p"},"name")," attribute of the ",(0,i.kt)("inlineCode",{parentName:"p"},"Flight")," model instance. When we call the ",(0,i.kt)("inlineCode",{parentName:"p"},"save")," method, a record will be inserted into the database. The model's ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," timestamps will automatically be set when the ",(0,i.kt)("inlineCode",{parentName:"p"},"save")," method is called, so there is no need to set them manually."),(0,i.kt)("p",null,"Alternatively, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"create")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\nauto flight = Flight::create({\n {"name", "London to Paris"},\n});\n')),(0,i.kt)("p",null,"However, before using the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method, you will need to specify either a ",(0,i.kt)("inlineCode",{parentName:"p"},"u_fillable")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("a",{parentName:"p",href:"#mass-assignment"},"mass assignment documentation"),"."),(0,i.kt)("h3",{id:"updates"},"Updates"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"save")," method. Again, the ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," timestamp will automatically be updated, so there is no need to manually set its value:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\nauto flight = Flight::find(1);\n\nflight->setAttribute("name", "Paris to London");\n\nflight->save();\n')),(0,i.kt)("h4",{id:"mass-updates"},"Mass Updates"),(0,i.kt)("p",null,"Updates can also be performed against models that match a given query. In this example, all flights that are ",(0,i.kt)("inlineCode",{parentName:"p"},"active")," and have a ",(0,i.kt)("inlineCode",{parentName:"p"},"destination")," of ",(0,i.kt)("inlineCode",{parentName:"p"},"San Diego")," will be marked as delayed:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Flight::whereEq("active", 1)\n ->whereEq("destination", "San Diego")\n .update({{"delayed", 1}});\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"update")," method expects the ",(0,i.kt)("inlineCode",{parentName:"p"},"QVector")," of column and value pairs representing the columns that should be updated."),(0,i.kt)("h4",{id:"examining-attribute-changes"},"Examining Attribute Changes"),(0,i.kt)("p",null,"TinyORM provides the ",(0,i.kt)("inlineCode",{parentName:"p"},"isDirty"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"isClean"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"wasChanged")," methods to examine the internal state of your model and determine how its attributes have changed from when the model was originally retrieved."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"isDirty")," method to determine if a particular attribute is dirty. The ",(0,i.kt)("inlineCode",{parentName:"p"},"isClean")," will determine if an attribute has remained unchanged since the model was retrieved. This method also accepts an optional attribute argument:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("h3",{id:"mass-assignment"},"Mass Assignment"),(0,i.kt)("p",null,"You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"create"),' method to "save" a new model using a single C++ statement. The inserted model instance will be returned to you by the method:'),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\nauto flight = Flight::create({\n {"name", "London to Paris"},\n});\n')),(0,i.kt)("p",null,"However, before using the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method, you will need to specify either a ",(0,i.kt)("inlineCode",{parentName:"p"},"u_fillable")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"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."),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"is_admin")," parameter through an HTTP request, which is then passed to your model's ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method, allowing the user to escalate themselves to an administrator."),(0,i.kt)("p",null,"So, to get started, you should define which model attributes you want to make mass assignable. You may do this using the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_fillable")," static data member on the model. For example, let's make the ",(0,i.kt)("inlineCode",{parentName:"p"},"name")," attribute of our ",(0,i.kt)("inlineCode",{parentName:"p"},"Flight")," model mass assignable:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"Once you have specified which attributes are mass assignable, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method to insert a new record in the database. The ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method returns the newly created model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::create({{"name", "London to Paris"}});\n')),(0,i.kt)("p",null,"If you already have a model instance, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"fill")," method to populate it with the vector of attributes:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'flight.fill({{"name", "Amsterdam to Frankfurt"}});\n')),(0,i.kt)("h4",{id:"allowing-mass-assignment"},"Allowing Mass Assignment"),(0,i.kt)("p",null,"If you would like to make all of your attributes mass assignable, you may define your model's ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"fill"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"create"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"update")," methods:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#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")),(0,i.kt)("h3",{id:"upserts"},"Upserts"),(0,i.kt)("p",null,"Occasionally, you may need to update an existing model or create a new model if no matching model exists."),(0,i.kt)("p",null,"In the example below, if a flight exists with a ",(0,i.kt)("inlineCode",{parentName:"p"},"departure")," location of ",(0,i.kt)("inlineCode",{parentName:"p"},"Oakland")," and a ",(0,i.kt)("inlineCode",{parentName:"p"},"destination")," location of ",(0,i.kt)("inlineCode",{parentName:"p"},"San Diego"),", its ",(0,i.kt)("inlineCode",{parentName:"p"},"price")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flight = Flight::updateOrCreate(\n {{"departure", "Oakland"}, {"destination", "San Diego"}},\n {{"price", 99}, {"discounted", 1}}\n);\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"firstOrCreate")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updateOrCreate")," methods persist the model, so there's no need to manually call the ",(0,i.kt)("inlineCode",{parentName:"p"},"save")," method.")),(0,i.kt)("p",null,'If you would like to perform multiple "upserts" in a single query, then you should use the ',(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"upsert")," method will automatically set the ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," timestamps if timestamps are enabled on the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"All databases except SQL Server require the columns in the second argument of the ",(0,i.kt)("inlineCode",{parentName:"p"},"upsert"),' method to have a "primary" or "unique" index. In addition, the MySQL database driver ignores the second argument of the ',(0,i.kt)("inlineCode",{parentName:"p"},"upsert"),' method and always uses the "primary" and "unique" indexes of the table to detect existing records.')),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"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.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.1/en/insert-on-duplicate.html"},"documentation"),". The MySQL server version is auto-detected and can be overridden in the ",(0,i.kt)("a",{parentName:"p",href:"/database/getting-started#configuration"},"configuration"),".")),(0,i.kt)("h2",{id:"deleting-models"},"Deleting Models"),(0,i.kt)("p",null,"To delete a model, you may call the ",(0,i.kt)("inlineCode",{parentName:"p"},"remove"),", or an alias ",(0,i.kt)("inlineCode",{parentName:"p"},"deleteRow")," method on the model instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include "models/flight.hpp"\n\nauto flight = Flight::find(1);\n\nflight->remove();\n')),(0,i.kt)("h4",{id:"deleting-an-existing-model-by-its-primary-key"},"Deleting An Existing Model By Its Primary Key"),(0,i.kt)("p",null,"In the example above, we are retrieving the model from the database before calling the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"destroy")," method. In addition to accepting the single primary key, the ",(0,i.kt)("inlineCode",{parentName:"p"},"destroy")," method can accept multiple primary keys:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"Flight::destroy(1);\n\nFlight::destroy({1, 2, 3});\n")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"destroy")," method loads models from the database and calls the ",(0,i.kt)("inlineCode",{parentName:"p"},"remove")," method on each model individually, the reason for this is future compatibility with events.")),(0,i.kt)("h4",{id:"deleting-models-using-queries"},"Deleting Models Using Queries"),(0,i.kt)("p",null,"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto deletedRows = Flight::whereEq("active", 0)->remove();\n')),(0,i.kt)("h3",{id:"soft-deleting"},"Soft Deleting"),(0,i.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::SoftDeletes")," base class to the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"SoftDeletes")," base class will automatically cast the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," attribute to the ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance for you (it adds the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," column to the model's ",(0,i.kt)("a",{parentName:"p",href:"#timestamps-u_dates"},(0,i.kt)("inlineCode",{parentName:"a"},"u_dates"))," list).")),(0,i.kt)("p",null,"You should also add the ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," column to your database table. The TinyORM ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},"schema builder")," contains a helper method to create this column:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Schema::table("flights", [](Blueprint &table)\n{\n table.softDeletes();\n});\n\nSchema::table("flights", [](Blueprint &table)\n{\n table.dropSoftDeletes();\n});\n')),(0,i.kt)("p",null,"Now, when you call the ",(0,i.kt)("inlineCode",{parentName:"p"},"remove")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"deleteModel")," method on the model, the ",(0,i.kt)("inlineCode",{parentName:"p"},"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."),(0,i.kt)("p",null,"To determine if a given model instance has been soft deleted, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"trashed")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"if (flight->trashed()) {\n //\n}\n")),(0,i.kt)("h4",{id:"restoring-soft-deleted-models"},"Restoring Soft Deleted Models"),(0,i.kt)("p",null,'Sometimes you may wish to "un-delete" a soft deleted model. To restore a soft deleted model, you may call the ',(0,i.kt)("inlineCode",{parentName:"p"},"restore")," method on a model instance. The ",(0,i.kt)("inlineCode",{parentName:"p"},"restore")," method will set the model's ",(0,i.kt)("inlineCode",{parentName:"p"},"deleted_at")," column to ",(0,i.kt)("inlineCode",{parentName:"p"},"null"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->restore();\n")),(0,i.kt)("p",null,"You may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"restore")," method in a query to restore multiple models:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'Flight::withTrashed()\n ->whereEq("airline_id", 1)\n .restore();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"restore")," method may also be used when building ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," queries:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->restore();\n")),(0,i.kt)("h4",{id:"permanently-deleting-models"},"Permanently Deleting Models"),(0,i.kt)("p",null,"Sometimes you may need to truly remove a model from your database. You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"forceDelete")," method (or it's alias ",(0,i.kt)("inlineCode",{parentName:"p"},"forceRemove"),") to permanently remove a soft deleted model from the database table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->forceDelete();\n")),(0,i.kt)("p",null,"You may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"forceDelete")," method when building TinyORM relationship queries:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->forceDelete();\n")),(0,i.kt)("h3",{id:"querying-soft-deleted-models"},"Querying Soft Deleted Models"),(0,i.kt)("h4",{id:"including-soft-deleted-models"},"Including Soft Deleted Models"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"withTrashed")," method on the query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flights = Flight::withTrashed()\n ->whereEq("account_id", 1)\n .get();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"withTrashed")," method may also be called when building a ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->withTrashed().get();\n")),(0,i.kt)("h4",{id:"retrieving-only-soft-deleted-models"},"Retrieving Only Soft Deleted Models"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"onlyTrashed")," method will retrieve ",(0,i.kt)("strong",{parentName:"p"},"only")," soft deleted models:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flights = Flight::onlyTrashed()\n ->whereEq("airline_id", 1)\n .get();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"onlyTrashed")," method may also be called when building a ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->onlyTrashed().get();\n")),(0,i.kt)("h4",{id:"excluding-soft-deleted-models"},"Excluding Soft Deleted Models"),(0,i.kt)("p",null,"As noted above, soft deleted models will automatically be excluded from query results. However, you may force soft deleted models to be ",(0,i.kt)("strong",{parentName:"p"},"excluded")," in a query's results by calling the ",(0,i.kt)("inlineCode",{parentName:"p"},"withoutTrashed")," method on the query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto flights = Flight::withoutTrashed()\n ->whereEq("account_id", 1)\n .get();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"withoutTrashed")," method may also be called when building a ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationship")," query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"flight->history()->withoutTrashed().get();\n")),(0,i.kt)("h3",{id:"truncate-table"},"Truncate Table"),(0,i.kt)("p",null,"You may call the ",(0,i.kt)("inlineCode",{parentName:"p"},"truncate")," method to delete all of the model's associated database records. The ",(0,i.kt)("inlineCode",{parentName:"p"},"truncate")," operation will also reset any auto-incrementing IDs on the model's associated table:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"Flight::truncate();\n")),(0,i.kt)("h2",{id:"replicating-models"},"Replicating Models"),(0,i.kt)("p",null,"You may create an unsaved copy of an existing model instance using the ",(0,i.kt)("inlineCode",{parentName:"p"},"replicate")," method. This method is particularly useful when you have model instances that share many of the same attributes:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("p",null,"To exclude one or more attributes from being replicated to the new model, you may pass an unordered_set to the ",(0,i.kt)("inlineCode",{parentName:"p"},"replicate")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'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')),(0,i.kt)("h2",{id:"comparing-models"},"Comparing Models"),(0,i.kt)("p",null,'Sometimes you may need to determine if two models are the "same" or not. The ',(0,i.kt)("inlineCode",{parentName:"p"},"is")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"isNot")," methods may be used to quickly verify two models have the same primary key, table, and database connection or not:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"if (post->is(anotherPost)) {\n //\n}\n\nif (post->isNot(anotherPost)) {\n //\n}\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"is")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"isNot")," methods are also available when using the ",(0,i.kt)("inlineCode",{parentName:"p"},"belongsTo")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"hasOne")," ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/relationships"},"relationships"),". This method is particularly helpful when you would like to compare a related model without issuing a query to retrieve that model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"if (post->author()->is(user)) {\n //\n}\n")),(0,i.kt)("h5",{id:"equality-comparison"},"Equality comparison"),(0,i.kt)("p",null,"The base ",(0,i.kt)("inlineCode",{parentName:"p"},"Model")," class also defines the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"model1 == model2")," expression guarantees that these two models are exactly the same."),(0,i.kt)("p",null,"It would be appropriate to mention that this comparison also includes relations, which means it will also compare ",(0,i.kt)("strong",{parentName:"p"},"all")," models (including their data members) these relations contain."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/62a1276f.b50a0dc6.js b/assets/js/62a1276f.732e44fe.js similarity index 79% rename from assets/js/62a1276f.b50a0dc6.js rename to assets/js/62a1276f.732e44fe.js index 68bb87be4..0569911e4 100644 --- a/assets/js/62a1276f.b50a0dc6.js +++ b/assets/js/62a1276f.732e44fe.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[57],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>y});var n=a(7294);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function r(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function o(e){for(var t=1;t=0||(i[a]=e[a]);return i}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(i[a]=e[a])}return i}var l=n.createContext({}),p=function(e){var t=n.useContext(l),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},m=function(e){var t=p(e.components);return n.createElement(l.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},c=n.forwardRef((function(e,t){var a=e.components,i=e.mdxType,r=e.originalType,l=e.parentName,m=s(e,["components","mdxType","originalType","parentName"]),d=p(a),c=i,y=d["".concat(l,".").concat(c)]||d[c]||u[c]||r;return a?n.createElement(y,o(o({ref:t},m),{},{components:a})):n.createElement(y,o({ref:t},m))}));function y(e,t){var a=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var r=a.length,o=new Array(r);o[0]=c;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:i,o[1]=s;for(var p=2;p{a.r(t),a.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>p});var n=a(7462),i=(a(7294),a(3905));const r={sidebar_position:3,sidebar_label:"Casts",description:"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a `datetime` string that is stored in your database to the `QDateTime` instance when it is accessed via your TinyORM model.",keywords:["c++ orm","orm","casts","casting","attributes","tinyorm"]},o="TinyORM: Casting",s={unversionedId:"tinyorm/casts",id:"tinyorm/casts",title:"TinyORM: Casting",description:"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a `datetime` string that is stored in your database to the `QDateTime` instance when it is accessed via your TinyORM model.",source:"@site/docs/tinyorm/casts.mdx",sourceDirName:"tinyorm",slug:"/tinyorm/casts",permalink:"/tinyorm/casts",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinyorm/casts.mdx",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3,sidebar_label:"Casts",description:"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a `datetime` string that is stored in your database to the `QDateTime` instance when it is accessed via your TinyORM model.",keywords:["c++ orm","orm","casts","casting","attributes","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Collections",permalink:"/tinyorm/collections"},next:{title:"Serialization",permalink:"/tinyorm/serialization"}},l={},p=[{value:"Introduction",id:"introduction",level:2},{value:"Accessors",id:"accessors",level:2},{value:"Defining An Accessor",id:"defining-an-accessor",level:3},{value:"Building Value From Multiple Attributes",id:"building-value-from-multiple-attributes",level:4},{value:"Accessor Caching",id:"accessor-caching",level:4},{value:"Attribute Casting",id:"attribute-casting",level:2},{value:"Date Casting",id:"date-casting",level:3},{value:"Date Casting, Serialization & Timezones",id:"date-casting-serialization-and-timezones",level:4},{value:"Query Time Casting",id:"query-time-casting",level:3}],m={toc:p},d="wrapper";function u(e){let{components:t,...a}=e;return(0,i.kt)(d,(0,n.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"tinyorm-casting"},"TinyORM: Casting"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#accessors"},"Accessors"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#defining-an-accessor"},"Defining An Accessor")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#attribute-casting"},"Attribute Casting"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#date-casting"},"Date Casting")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#query-time-casting"},"Query Time Casting"))))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a ",(0,i.kt)("inlineCode",{parentName:"p"},"datetime")," string that is stored in your database to the ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance when it is accessed via your TinyORM model. Or, you may want to convert a ",(0,i.kt)("inlineCode",{parentName:"p"},"tinyint")," number that is stored in the database to the ",(0,i.kt)("inlineCode",{parentName:"p"},"bool")," when you access it on the TinyORM model."),(0,i.kt)("h2",{id:"accessors"},"Accessors"),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"Accessors are currently only used during the serialization by the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization#appending-values-to-json"},"Appending Values")," feature. They are not used during the ",(0,i.kt)("inlineCode",{parentName:"p"},"getAttribute")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"getAttributeValue")," methods calls.")),(0,i.kt)("h3",{id:"defining-an-accessor"},"Defining An Accessor"),(0,i.kt)("p",null,"An accessor transforms a TinyORM attribute value when it is accessed (currently during serialization only by the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization#appending-values-to-json"},"Appending Values"),' feature). To define an accessor, create a protected method on your model to represent the accessible attribute. This method name should correspond to the "camelCase" representation of the true underlying model attribute / database column when applicable.'),(0,i.kt)("p",null,"In this example, we'll define an accessor for the ",(0,i.kt)("inlineCode",{parentName:"p"},"first_name")," attribute. The accessor will automatically be called by TinyORM during serialization if the ",(0,i.kt)("inlineCode",{parentName:"p"},"first_name")," attribute is defined in the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_appends")," data member set. All attribute accessor methods must return the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Casts::Attribute"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\nprotected:\n /*! Get the user\'s first name (accessor). */\n Attribute firstName() const noexcept\n {\n return Attribute::make(/* get */ [this]() -> QVariant\n {\n auto firstName = getAttribute("first_name");\n\n if (!firstName.isEmpty())\n firstName[0] = firstName.at(0).toUpper();\n\n return firstName;\n });\n }\n\nprivate:\n /*! Map of mutator names to methods. */\n inline static const QHash u_mutators {\n {"first_name", &User::firstName},\n };\n};\n')),(0,i.kt)("p",null,"All accessor methods return an ",(0,i.kt)("inlineCode",{parentName:"p"},"Attribute")," instance which defines how the attribute will be accessed. To do so, we supply the ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," argument to the ",(0,i.kt)("inlineCode",{parentName:"p"},"Attribute")," class constructor or ",(0,i.kt)("inlineCode",{parentName:"p"},"Attribute::make")," factory method."),(0,i.kt)("p",null,"As you can see, the current model is captured by-reference using the ",(0,i.kt)("inlineCode",{parentName:"p"},"[this]")," capture, allowing you to obtain a value by the ",(0,i.kt)("inlineCode",{parentName:"p"},"getAttribute")," method inside the lambda expression, manipulate it and return a new value."),(0,i.kt)("p",null,"You can also use the second overload that allows you to pass the ",(0,i.kt)("inlineCode",{parentName:"p"},"ModelAttributes")," unordered map to the lambda expression:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'protected:\n /*! Get the user\'s first name (accessor). */\n Attribute firstName() const noexcept\n {\n return Attribute::make(\n /* get */ [](const ModelAttributes &attributes) -> QVariant\n {\n auto firstName = attributes.at("first_name");\n\n if (!firstName.isEmpty())\n firstName[0] = firstName.at(0).toUpper();\n\n return firstName;\n });\n }\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/include/orm/tiny/types/modelattributes.hpp"},(0,i.kt)("inlineCode",{parentName:"a"},"ModelAttributes"))," container extends the ",(0,i.kt)("inlineCode",{parentName:"p"},"std::unordered_map")," and adds the ",(0,i.kt)("inlineCode",{parentName:"p"},"at")," method that allows you to cast the underlying QVariant value."),(0,i.kt)("p",null,"Special note should be given to the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_mutators")," static data member map, which maps accessors' attribute names to its methods. This data member is ",(0,i.kt)("strong",{parentName:"p"},"required")," because C++ does not currently support reflection."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"If you would like these computed values to be added to the vector, map, or JSON representations of your model, ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization#appending-values-to-json"},"you will need to append them"),".")),(0,i.kt)("admonition",{type:"danger"},(0,i.kt)("p",{parentName:"admonition"},"You must guarantee that the current model will live long enough to avoid the dangling reference and crash if the current model is captured by-reference. Of course, you can capture it by-copy in edge cases or if you can't guarantee this.")),(0,i.kt)("h4",{id:"building-value-from-multiple-attributes"},"Building Value From Multiple Attributes"),(0,i.kt)("p",null,"Sometimes your accessor may need to transform multiple model attributes into a single value. You can use both methods described above to accomplish this:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'using Orm::Constants::SPACE_IN;\n\nprotected:\n /*! Get the user\'s full name (accessor). */\n Attribute fullName() const noexcept\n {\n return Attribute::make(/* get */ [this]() -> QVariant\n {\n return SPACE_IN.arg(getAttribute("first_name"),\n getAttribute("last_name"));\n });\n }\n')),(0,i.kt)("p",null,"Or you can use the ",(0,i.kt)("inlineCode",{parentName:"p"},"ModelAttributes")," overload:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! Get the user\'s full name (accessor). */\nAttribute fullName() const noexcept\n{\n return Attribute::make(\n /* get */ [](const ModelAttributes &attributes) -> QVariant\n {\n return SPACE_IN.arg(attributes.at("first_name"),\n attributes.at("last_name"));\n });\n}\n')),(0,i.kt)("h4",{id:"accessor-caching"},"Accessor Caching"),(0,i.kt)("p",null,"Sometimes computing an attribute value can be intensive, in this case, you can enable caching for this attribute value. To accomplish this, you have to invoke the ",(0,i.kt)("inlineCode",{parentName:"p"},"shouldCache")," method when defining your accessor:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'using Orm::Constants::SPACE_IN;\n\nprotected:\n /*! Get the user\'s full name (accessor). */\n Attribute fullName() const noexcept\n {\n return Attribute::make(/* get */ [this]() -> QVariant\n {\n return SPACE_IN.arg(getAttribute("first_name"),\n getAttribute("last_name"));\n }).shouldCache();\n }\n')),(0,i.kt)("h2",{id:"attribute-casting"},"Attribute Casting"),(0,i.kt)("p",null,"Attribute casting provides functionality that allows converting model attributes to the appropriate ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant")," ",(0,i.kt)("strong",{parentName:"p"},"metatype")," when it is accessed via your TinyORM model. The core of this functionality is a model's ",(0,i.kt)("inlineCode",{parentName:"p"},"u_casts")," static data member that provides a convenient method of converting attributes' ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant")," ",(0,i.kt)("strong",{parentName:"p"},"internal types")," to the defined cast types."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"u_casts")," static data member should be the ",(0,i.kt)("inlineCode",{parentName:"p"},"std::unordered_map")," where the key is the name of the attribute being cast and the value is the type you wish to cast the column to. The supported cast types are:"),(0,i.kt)("div",{id:"casts-types-list"},(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::QString")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Boolean")," / ",(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Bool")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Integer")," / ",(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Int")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::UInteger")," / ",(0,i.kt)("inlineCode",{parentName:"li"},"CastType::UInt")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::LongLong")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::ULongLong")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Short")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::UShort")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::QDate")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::QDateTime")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Timestamp")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Real")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Float")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Double")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("code",null,"CastType::Decimal:")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::QByteArray")))),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The primary key name defined by the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_primaryKey")," model's data member is automatically cast to the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::ULongLong")," for all database drivers if the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_incrementing")," is set to true (its default value).")),(0,i.kt)("p",null,"To demonstrate attribute casting, let's cast the ",(0,i.kt)("inlineCode",{parentName:"p"},"is_admin")," attribute, which is stored in our database as an integer (",(0,i.kt)("inlineCode",{parentName:"p"},"0")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"1"),") to a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant(bool)")," value:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#pragma once\n\n#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! The attributes that should be cast. */\n inline static std::unordered_map u_casts {\n {"is_admin", CastType::Boolean},\n };\n};\n')),(0,i.kt)("p",null,"After defining the cast, the ",(0,i.kt)("inlineCode",{parentName:"p"},"is_admin")," attribute will always be cast to a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant(bool)")," when you access it, even if the underlying value is stored in the database as an integer:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'using Orm::Utils::Helpers;\n\nauto isAdmin = User::find(1)->getAttribute("is_admin");\n\n// Proof of the QVariant type\nQ_ASSERT(Helpers::qVariantTypeId(isAdmin) == QMetaType::Bool);\n\nif (isAdmin.value()) {\n //\n}\n')),(0,i.kt)("p",null,"If you need to add a new, ",(0,i.kt)("strong",{parentName:"p"},"temporary")," cast at runtime, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"mergeCasts")," method. These cast definitions will be added to any of the casts already defined on the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'user->mergeCasts({\n {"is_paid", CastType::Boolean},\n {"income", {CastType::Decimal, 2}},\n});\n')),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"You should never define a cast (or an attribute) that has the same name as a relationship.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Attributes that are ",(0,i.kt)("inlineCode",{parentName:"p"},"null")," ",(0,i.kt)("strong",{parentName:"p"},"will also be")," cast so that the ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant"),"'s internal type will have the correct type.")),(0,i.kt)("h3",{id:"date-casting"},"Date Casting"),(0,i.kt)("p",null,"By default, TinyORM will cast the ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," columns to instances of ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime"),". You may cast additional date attributes by defining additional date casts within your model's ",(0,i.kt)("inlineCode",{parentName:"p"},"u_casts")," static data member unordered map. Typically, dates should be cast using the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDateTime"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDate"),", or ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::Timestamp")," cast types."),(0,i.kt)("p",null,"When a database column is of the date type, you may set the corresponding model attribute value to a UNIX timestamp, date string (",(0,i.kt)("inlineCode",{parentName:"p"},"Y-m-d"),"), date-time string, ",(0,i.kt)("inlineCode",{parentName:"p"},"QDate"),", or ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance. The date's value will be correctly converted and stored in your database.",(0,i.kt)("br",null),"\nThe same is true for the datetime or timestamp database column types, you can set the corresponding model attribute value to a UNIX timestamp, date-time string, or a ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance."),(0,i.kt)("p",null,"When defining the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDate")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDateTime")," cast, you may also specify the date's format. In this case you must use the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDate")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDateTime")," cast types. This format will be used when the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization"},"model is serialized to a vector, map, or JSON"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! The attributes that should be cast. */\ninline static std::unordered_map u_casts {\n {"created_at", {CastType::CustomQDateTime, "yyyy-MM-dd"}},\n};\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDate")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDateTime")," cast types behave exactly like the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDate")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDateTime")," cast types with the additional ",(0,i.kt)("strong",{parentName:"p"},"date's format")," functionality during ",(0,i.kt)("strong",{parentName:"p"},"serialization"),".")),(0,i.kt)("p",null,"You may customize the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization#customizing-the-default-date-format"},"default serialization format")," for all of your model's dates or datetimes by defining a ",(0,i.kt)("inlineCode",{parentName:"p"},"serializeDate")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"serializeDateTime")," methods on your model. These methods do not affect how your dates are formatted for storage in the database:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! Prepare a date for vector, map, or JSON serialization. */\nQString serializeDate(const QDate date)\n{\n return date.toString("yyyy-MM-dd");\n}\n\n/*! Prepare a datetime for vector, map, or JSON serialization. */\nQString serializeDateTime(const QDateTime &datetime)\n{\n return datetime.toUTC().toString("yyyy-MM-ddTHH:mm:ssZ");\n}\n')),(0,i.kt)("p",null,"To specify the format that should be used when actually storing a model's dates within your database, you should define a ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dateFormat")," data member on your model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"/*! The storage format of the model's date columns. */\ninline static QString u_dateFormat {QLatin1Char('U')};\n")),(0,i.kt)("p",null,"This format can be any format that the QDateTime's ",(0,i.kt)("inlineCode",{parentName:"p"},"fromString")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"toString")," methods accept or the special ",(0,i.kt)("inlineCode",{parentName:"p"},"U")," format that represents the UNIX timestamp (this ",(0,i.kt)("inlineCode",{parentName:"p"},"U")," format is TinyORM-specific and isn't supported by ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime"),")."),(0,i.kt)("h4",{id:"date-casting-serialization-and-timezones"},"Date Casting, Serialization & Timezones"),(0,i.kt)("p",null,"By default, the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDate")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDateTime")," casts will serialize dates to a UTC ISO-8601 date string (",(0,i.kt)("inlineCode",{parentName:"p"},"yyyy-MM-ddTHH:mm:ss.zzzZ"),"), regardless of the timezone specified in your database connection's ",(0,i.kt)("inlineCode",{parentName:"p"},"qt_timezone")," configuration option. You are strongly encouraged to always use this serialization format, as well as to store your application's dates in the UTC timezone by not changing your database connection's ",(0,i.kt)("inlineCode",{parentName:"p"},"qt_timezone")," configuration option from its default ",(0,i.kt)("inlineCode",{parentName:"p"},"Qt::UTC")," value. Consistently using the UTC timezone throughout your application will provide the maximum level of interoperability with other date manipulation libraries or services written in any programming language."),(0,i.kt)("p",null,"If a custom format is applied to the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDate")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDateTime")," cast types, such as ",(0,i.kt)("inlineCode",{parentName:"p"},'{CastType::CustomQDateTime, "yyyy-MM-dd HH:mm:ss"}'),", the inner timezone of the QDateTime instance will be used during date serialization. Typically, this will be the timezone specified in your database connection's ",(0,i.kt)("inlineCode",{parentName:"p"},"qt_timezone")," configuration option."),(0,i.kt)("h3",{id:"query-time-casting"},"Query Time Casting"),(0,i.kt)("p",null,"Sometimes you may need to apply casts while executing a query, such as when selecting a raw value from a table. For example, consider the following query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'using Models::Post;\nusing Models::User;\n\nauto users = User::select("users.*")\n ->addSelect(\n Post::selectRaw("MAX(created_at)")\n ->whereColumnEq("user_id", "users.id")\n .toBase(),\n "last_posted_at"\n ).get();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"last_posted_at")," attribute on the results of this query will be a simple string. It would be wonderful if we could apply a ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDateTime")," cast to this attribute when executing the query. Thankfully, we may accomplish this using the ",(0,i.kt)("inlineCode",{parentName:"p"},"withCasts")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"withCast")," methods:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto users = User::select("users.*")\n ->addSelect(Post::selectRaw("MAX(created_at)")\n ->whereColumnEq("user_id", "users.id")\n .toBase(),\n "last_posted_at")\n .withCast({"last_posted_at", CastType::QDateTime})\n .get();\n')))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[57],{3905:(e,t,a)=>{a.d(t,{Zo:()=>m,kt:()=>y});var n=a(7294);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function r(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function o(e){for(var t=1;t=0||(i[a]=e[a]);return i}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(i[a]=e[a])}return i}var l=n.createContext({}),p=function(e){var t=n.useContext(l),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},m=function(e){var t=p(e.components);return n.createElement(l.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},c=n.forwardRef((function(e,t){var a=e.components,i=e.mdxType,r=e.originalType,l=e.parentName,m=s(e,["components","mdxType","originalType","parentName"]),d=p(a),c=i,y=d["".concat(l,".").concat(c)]||d[c]||u[c]||r;return a?n.createElement(y,o(o({ref:t},m),{},{components:a})):n.createElement(y,o({ref:t},m))}));function y(e,t){var a=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var r=a.length,o=new Array(r);o[0]=c;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:i,o[1]=s;for(var p=2;p{a.r(t),a.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>p});var n=a(7462),i=(a(7294),a(3905));const r={sidebar_position:3,sidebar_label:"Casts",description:"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a `datetime` string that is stored in your database to the `QDateTime` instance when it is accessed via your TinyORM model.",keywords:["c++ orm","orm","casts","casting","attributes","tinyorm"]},o="TinyORM: Casting",s={unversionedId:"tinyorm/casts",id:"tinyorm/casts",title:"TinyORM: Casting",description:"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a `datetime` string that is stored in your database to the `QDateTime` instance when it is accessed via your TinyORM model.",source:"@site/docs/tinyorm/casts.mdx",sourceDirName:"tinyorm",slug:"/tinyorm/casts",permalink:"/tinyorm/casts",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinyorm/casts.mdx",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3,sidebar_label:"Casts",description:"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a `datetime` string that is stored in your database to the `QDateTime` instance when it is accessed via your TinyORM model.",keywords:["c++ orm","orm","casts","casting","attributes","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Collections",permalink:"/tinyorm/collections"},next:{title:"Serialization",permalink:"/tinyorm/serialization"}},l={},p=[{value:"Introduction",id:"introduction",level:2},{value:"Accessors",id:"accessors",level:2},{value:"Defining An Accessor",id:"defining-an-accessor",level:3},{value:"Building Value From Multiple Attributes",id:"building-value-from-multiple-attributes",level:4},{value:"Accessor Caching",id:"accessor-caching",level:4},{value:"Attribute Casting",id:"attribute-casting",level:2},{value:"Date Casting",id:"date-casting",level:3},{value:"Date Casting, Serialization & Timezones",id:"date-casting-serialization-and-timezones",level:4},{value:"Query Time Casting",id:"query-time-casting",level:3}],m={toc:p},d="wrapper";function u(e){let{components:t,...a}=e;return(0,i.kt)(d,(0,n.Z)({},m,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"tinyorm-casting"},"TinyORM: Casting"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#accessors"},"Accessors"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#defining-an-accessor"},"Defining An Accessor")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#attribute-casting"},"Attribute Casting"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#date-casting"},"Date Casting")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#query-time-casting"},"Query Time Casting"))))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a ",(0,i.kt)("inlineCode",{parentName:"p"},"datetime")," string that is stored in your database to the ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance when it is accessed via your TinyORM model. Or, you may want to convert a ",(0,i.kt)("inlineCode",{parentName:"p"},"tinyint")," number that is stored in the database to the ",(0,i.kt)("inlineCode",{parentName:"p"},"bool")," when you access it on the TinyORM model."),(0,i.kt)("h2",{id:"accessors"},"Accessors"),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"Accessors are currently only used during the serialization by the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization#appending-values-to-json"},"Appending Values")," feature. They are not used during the ",(0,i.kt)("inlineCode",{parentName:"p"},"getAttribute")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"getAttributeValue")," methods calls.")),(0,i.kt)("h3",{id:"defining-an-accessor"},"Defining An Accessor"),(0,i.kt)("p",null,"An accessor transforms a TinyORM attribute value when it is accessed (currently during serialization only by the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization#appending-values-to-json"},"Appending Values"),' feature). To define an accessor, create a protected method on your model to represent the accessible attribute. This method name should correspond to the "camelCase" representation of the true underlying model attribute / database column when applicable.'),(0,i.kt)("p",null,"In this example, we'll define an accessor for the ",(0,i.kt)("inlineCode",{parentName:"p"},"first_name")," attribute. The accessor will automatically be called by TinyORM during serialization if the ",(0,i.kt)("inlineCode",{parentName:"p"},"first_name")," attribute is defined in the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_appends")," data member set. All attribute accessor methods must return the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Tiny::Casts::Attribute"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\nprotected:\n /*! Get the user\'s first name (accessor). */\n Attribute firstName() const noexcept\n {\n return Attribute::make(/* get */ [this]() -> QVariant\n {\n auto firstName = getAttribute("first_name");\n\n if (!firstName.isEmpty())\n firstName[0] = firstName.at(0).toUpper();\n\n return firstName;\n });\n }\n\nprivate:\n /*! Map of mutator names to methods. */\n inline static const QHash u_mutators {\n {"first_name", &User::firstName},\n };\n};\n')),(0,i.kt)("p",null,"All accessor methods return an ",(0,i.kt)("inlineCode",{parentName:"p"},"Attribute")," instance which defines how the attribute will be accessed. To do so, we supply the ",(0,i.kt)("inlineCode",{parentName:"p"},"get")," argument to the ",(0,i.kt)("inlineCode",{parentName:"p"},"Attribute")," class constructor or ",(0,i.kt)("inlineCode",{parentName:"p"},"Attribute::make")," factory method."),(0,i.kt)("p",null,"As you can see, the current model is captured by-reference using the ",(0,i.kt)("inlineCode",{parentName:"p"},"[this]")," capture, allowing you to obtain a value by the ",(0,i.kt)("inlineCode",{parentName:"p"},"getAttribute")," method inside the lambda expression, manipulate it and return a new value."),(0,i.kt)("p",null,"You can also use the second overload that allows you to pass the ",(0,i.kt)("inlineCode",{parentName:"p"},"ModelAttributes")," unordered map to the lambda expression:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'protected:\n /*! Get the user\'s first name (accessor). */\n Attribute firstName() const noexcept\n {\n return Attribute::make(\n /* get */ [](const ModelAttributes &attributes) -> QVariant\n {\n auto firstName = attributes.at("first_name");\n\n if (!firstName.isEmpty())\n firstName[0] = firstName.at(0).toUpper();\n\n return firstName;\n });\n }\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/include/orm/tiny/types/modelattributes.hpp"},(0,i.kt)("inlineCode",{parentName:"a"},"ModelAttributes"))," container extends the ",(0,i.kt)("inlineCode",{parentName:"p"},"std::unordered_map")," and adds the ",(0,i.kt)("inlineCode",{parentName:"p"},"at")," method that allows you to cast the underlying QVariant value."),(0,i.kt)("p",null,"Special note should be given to the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_mutators")," static data member map, which maps accessors' attribute names to its methods. This data member is ",(0,i.kt)("strong",{parentName:"p"},"required")," because C++ does not currently support reflection."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"If you would like these computed values to be added to the vector, map, or JSON representations of your model, ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization#appending-values-to-json"},"you will need to append them"),".")),(0,i.kt)("admonition",{type:"danger"},(0,i.kt)("p",{parentName:"admonition"},"You must guarantee that the current model will live long enough to avoid the dangling reference and crash if the current model is captured by-reference. Of course, you can capture it by-copy in edge cases or if you can't guarantee this.")),(0,i.kt)("h4",{id:"building-value-from-multiple-attributes"},"Building Value From Multiple Attributes"),(0,i.kt)("p",null,"Sometimes your accessor may need to transform multiple model attributes into a single value. You can use both methods described above to accomplish this:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'using Orm::Constants::SPACE_IN;\n\nprotected:\n /*! Get the user\'s full name (accessor). */\n Attribute fullName() const noexcept\n {\n return Attribute::make(/* get */ [this]() -> QVariant\n {\n return SPACE_IN.arg(getAttribute("first_name"),\n getAttribute("last_name"));\n });\n }\n')),(0,i.kt)("p",null,"Or you can use the ",(0,i.kt)("inlineCode",{parentName:"p"},"ModelAttributes")," overload:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! Get the user\'s full name (accessor). */\nAttribute fullName() const noexcept\n{\n return Attribute::make(\n /* get */ [](const ModelAttributes &attributes) -> QVariant\n {\n return SPACE_IN.arg(attributes.at("first_name"),\n attributes.at("last_name"));\n });\n}\n')),(0,i.kt)("h4",{id:"accessor-caching"},"Accessor Caching"),(0,i.kt)("p",null,"Sometimes computing an attribute value can be intensive, in this case, you can enable caching for this attribute value. To accomplish this, you have to invoke the ",(0,i.kt)("inlineCode",{parentName:"p"},"shouldCache")," method when defining your accessor:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'using Orm::Constants::SPACE_IN;\n\nprotected:\n /*! Get the user\'s full name (accessor). */\n Attribute fullName() const noexcept\n {\n return Attribute::make(/* get */ [this]() -> QVariant\n {\n return SPACE_IN.arg(getAttribute("first_name"),\n getAttribute("last_name"));\n }).shouldCache();\n }\n')),(0,i.kt)("h2",{id:"attribute-casting"},"Attribute Casting"),(0,i.kt)("p",null,"Attribute casting provides functionality that allows converting model attributes to the appropriate ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant")," ",(0,i.kt)("strong",{parentName:"p"},"metatype")," when it is accessed via your TinyORM model. The core of this functionality is a model's ",(0,i.kt)("inlineCode",{parentName:"p"},"u_casts")," static data member that provides a convenient method of converting attributes' ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant")," ",(0,i.kt)("strong",{parentName:"p"},"internal types")," to the defined cast types."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"u_casts")," static data member should be the ",(0,i.kt)("inlineCode",{parentName:"p"},"std::unordered_map")," where the key is the name of the attribute being cast and the value is the type you wish to cast the column to. The supported cast types are:"),(0,i.kt)("div",{id:"casts-types-list"},(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::QString")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Boolean")," / ",(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Bool")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Integer")," / ",(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Int")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::UInteger")," / ",(0,i.kt)("inlineCode",{parentName:"li"},"CastType::UInt")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::LongLong")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::ULongLong")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Short")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::UShort")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::QDate")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::QDateTime")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Timestamp")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Real")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Float")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::Double")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("code",null,"CastType::Decimal:")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"CastType::QByteArray")))),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The primary key name defined by the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_primaryKey")," model's data member is automatically cast to the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::ULongLong")," for all database drivers if the ",(0,i.kt)("inlineCode",{parentName:"p"},"u_incrementing")," is set to true (its default value).")),(0,i.kt)("p",null,"To demonstrate attribute casting, let's cast the ",(0,i.kt)("inlineCode",{parentName:"p"},"is_admin")," attribute, which is stored in our database as an integer (",(0,i.kt)("inlineCode",{parentName:"p"},"0")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"1"),") to a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant(bool)")," value:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#pragma once\n\n#include \n\nusing Orm::Tiny::Model;\n\nclass User final : public Model\n{\n friend Model;\n using Model::Model;\n\n /*! The attributes that should be cast. */\n inline static std::unordered_map u_casts {\n {"is_admin", CastType::Boolean},\n };\n};\n')),(0,i.kt)("p",null,"After defining the cast, the ",(0,i.kt)("inlineCode",{parentName:"p"},"is_admin")," attribute will always be cast to a ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant(bool)")," when you access it, even if the underlying value is stored in the database as an integer:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'using Orm::Utils::Helpers;\n\nauto isAdmin = User::find(1)->getAttribute("is_admin");\n\n// Proof of the QVariant type\nQ_ASSERT(Helpers::qVariantTypeId(isAdmin) == QMetaType::Bool);\n\nif (isAdmin.value()) {\n //\n}\n')),(0,i.kt)("p",null,"If you need to add a new, ",(0,i.kt)("strong",{parentName:"p"},"temporary")," cast at runtime, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"mergeCasts")," method. These cast definitions will be added to any of the casts already defined on the model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'user->mergeCasts({\n {"is_paid", CastType::Boolean},\n {"income", {CastType::Decimal, 2}},\n});\n')),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"You should never define a cast (or an attribute) that has the same name as a relationship.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Attributes that are ",(0,i.kt)("inlineCode",{parentName:"p"},"null")," ",(0,i.kt)("strong",{parentName:"p"},"will also be")," cast so that the ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariant"),"'s internal type will have the correct type.")),(0,i.kt)("h3",{id:"date-casting"},"Date Casting"),(0,i.kt)("p",null,"By default, TinyORM will cast the ",(0,i.kt)("inlineCode",{parentName:"p"},"created_at")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"updated_at")," columns to instances of ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime"),". You may cast additional date attributes by defining additional date casts within your model's ",(0,i.kt)("inlineCode",{parentName:"p"},"u_casts")," static data member unordered map. Typically, dates should be cast using the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDateTime"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDate"),", or ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::Timestamp")," cast types."),(0,i.kt)("p",null,"When a database column is of the date type, you may set the corresponding model attribute value to a UNIX timestamp, date string (",(0,i.kt)("inlineCode",{parentName:"p"},"Y-m-d"),"), date-time string, ",(0,i.kt)("inlineCode",{parentName:"p"},"QDate"),", or ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance. The date's value will be correctly converted and stored in your database.",(0,i.kt)("br",null),"\nThe same is true for the datetime or timestamp database column types, you can set the corresponding model attribute value to a UNIX timestamp, date-time string, or a ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance."),(0,i.kt)("p",null,"When defining the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDate")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDateTime")," cast, you may also specify the date's format. In this case you must use the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDate")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDateTime")," cast types. This format will be used when the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization"},"model is serialized to a vector, map, or JSON"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! The attributes that should be cast. */\ninline static std::unordered_map u_casts {\n {"created_at", {CastType::CustomQDateTime, "yyyy-MM-dd"}},\n};\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDate")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDateTime")," cast types behave exactly like the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDate")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDateTime")," cast types with the additional ",(0,i.kt)("strong",{parentName:"p"},"date's format")," functionality during ",(0,i.kt)("u",null,(0,i.kt)("strong",{parentName:"p"},"serialization")),".")),(0,i.kt)("p",null,"You may customize the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/serialization#customizing-the-default-date-format"},"default serialization format")," for all of your model's dates or datetimes by defining a ",(0,i.kt)("inlineCode",{parentName:"p"},"serializeDate")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"serializeDateTime")," methods on your model. These methods do not affect how your dates are formatted for storage in the database:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! Prepare a date for vector, map, or JSON serialization. */\nQString serializeDate(const QDate date)\n{\n return date.toString("yyyy-MM-dd");\n}\n\n/*! Prepare a datetime for vector, map, or JSON serialization. */\nQString serializeDateTime(const QDateTime &datetime)\n{\n return datetime.toUTC().toString("yyyy-MM-ddTHH:mm:ssZ");\n}\n')),(0,i.kt)("p",null,"To specify the format that should be used when actually storing a model's dates within your database, you should define a ",(0,i.kt)("inlineCode",{parentName:"p"},"u_dateFormat")," data member on your model:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"/*! The storage format of the model's date columns. */\ninline static QString u_dateFormat {QLatin1Char('U')};\n")),(0,i.kt)("p",null,"This format can be any format that the QDateTime's ",(0,i.kt)("inlineCode",{parentName:"p"},"fromString")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"toString")," methods accept or the special ",(0,i.kt)("inlineCode",{parentName:"p"},"U")," format that represents the UNIX timestamp (this ",(0,i.kt)("inlineCode",{parentName:"p"},"U")," format is TinyORM-specific and isn't supported by ",(0,i.kt)("inlineCode",{parentName:"p"},"QDateTime"),")."),(0,i.kt)("p",null,"Define a ",(0,i.kt)("inlineCode",{parentName:"p"},"u_timeFormat")," data member on your model to specify the format that should be used when storing a model's times within your database:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'/*! The storage format of the model\'s time columns. */\ninline static QString u_timeFormat {"HH:mm:ss.zzz"};\n')),(0,i.kt)("h4",{id:"date-casting-serialization-and-timezones"},"Date Casting, Serialization & Timezones"),(0,i.kt)("p",null,"By default, the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDate")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDateTime")," casts will serialize dates to a UTC ISO-8601 date string (",(0,i.kt)("inlineCode",{parentName:"p"},"yyyy-MM-ddTHH:mm:ss.zzzZ"),"), regardless of the timezone specified in your database connection's ",(0,i.kt)("inlineCode",{parentName:"p"},"qt_timezone")," configuration option. You are strongly encouraged to always use this serialization format, as well as to store your application's dates in the UTC timezone by not changing your database connection's ",(0,i.kt)("inlineCode",{parentName:"p"},"qt_timezone")," configuration option from its default ",(0,i.kt)("inlineCode",{parentName:"p"},"Qt::UTC")," value. Consistently using the UTC timezone throughout your application will provide the maximum level of interoperability with other date manipulation libraries or services written in any programming language."),(0,i.kt)("p",null,"If a custom format is applied to the ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDate")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::CustomQDateTime")," cast types, such as ",(0,i.kt)("inlineCode",{parentName:"p"},'{CastType::CustomQDateTime, "yyyy-MM-dd HH:mm:ss"}'),", the inner timezone of the QDateTime instance will be used during date serialization. Typically, this will be the timezone specified in your database connection's ",(0,i.kt)("inlineCode",{parentName:"p"},"qt_timezone")," configuration option."),(0,i.kt)("h3",{id:"query-time-casting"},"Query Time Casting"),(0,i.kt)("p",null,"Sometimes you may need to apply casts while executing a query, such as when selecting a raw value from a table. For example, consider the following query:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'using Models::Post;\nusing Models::User;\n\nauto users = User::select("users.*")\n ->addSelect(\n Post::selectRaw("MAX(created_at)")\n ->whereColumnEq("user_id", "users.id")\n .toBase(),\n "last_posted_at"\n ).get();\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"last_posted_at")," attribute on the results of this query will be a simple string. It would be wonderful if we could apply a ",(0,i.kt)("inlineCode",{parentName:"p"},"CastType::QDateTime")," cast to this attribute when executing the query. Thankfully, we may accomplish this using the ",(0,i.kt)("inlineCode",{parentName:"p"},"withCasts")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"withCast")," methods:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto users = User::select("users.*")\n ->addSelect(Post::selectRaw("MAX(created_at)")\n ->whereColumnEq("user_id", "users.id")\n .toBase(),\n "last_posted_at")\n .withCast({"last_posted_at", CastType::QDateTime})\n .get();\n')))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/8a8faf8d.c6447040.js b/assets/js/8a8faf8d.3f5122a9.js similarity index 99% rename from assets/js/8a8faf8d.c6447040.js rename to assets/js/8a8faf8d.3f5122a9.js index 21cc481ae..62b0fe493 100644 --- a/assets/js/8a8faf8d.c6447040.js +++ b/assets/js/8a8faf8d.3f5122a9.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[225],{5162:(e,t,n)=>{n.d(t,{Z:()=>r});var a=n(7294),i=n(6010);const o={tabItem:"tabItem_Ymn6"};function r(e){let{children:t,hidden:n,className:r}=e;return a.createElement("div",{role:"tabpanel",className:(0,i.Z)(o.tabItem,r),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>y});var a=n(7462),i=n(7294),o=n(6010),r=n(2466),l=n(6550),s=n(1980),p=n(7392),m=n(12);function d(e){return function(e){return i.Children.map(e,(e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:i}}=e;return{value:t,label:n,attributes:a,default:i}}))}function u(e){const{values:t,children:n}=e;return(0,i.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function c(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function k(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,s._X)(o),(0,i.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(a.location.search);t.set(o,e),a.replace({...a.location,search:t.toString()})}),[o,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,o=u(e),[r,l]=(0,i.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!c({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:o}))),[s,p]=k({queryString:n,groupId:a}),[d,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,m.Nk)(n);return[a,(0,i.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:a}),g=(()=>{const e=s??d;return c({value:e,tabValues:o})?e:null})();(0,i.useLayoutEffect)((()=>{g&&l(g)}),[g]);return{selectedValue:r,selectValue:(0,i.useCallback)((e=>{if(!c({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),p(e),h(e)}),[p,h,o]),tabValues:o}}var g=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function N(e){let{className:t,block:n,selectedValue:l,selectValue:s,tabValues:p}=e;const m=[],{blockElementScrollPositionUntilNextRender:d}=(0,r.o5)(),u=e=>{const t=e.currentTarget,n=m.indexOf(t),a=p[n].value;a!==l&&(d(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=m.indexOf(e.currentTarget)+1;t=m[n]??m[0];break}case"ArrowLeft":{const n=m.indexOf(e.currentTarget)-1;t=m[n]??m[m.length-1];break}}t?.focus()};return i.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":n},t)},p.map((e=>{let{value:t,label:n,attributes:r}=e;return i.createElement("li",(0,a.Z)({role:"tab",tabIndex:l===t?0:-1,"aria-selected":l===t,key:t,ref:e=>m.push(e),onKeyDown:c,onClick:u},r,{className:(0,o.Z)("tabs__item",b.tabItem,r?.className,{"tabs__item--active":l===t})}),n??t)})))}function f(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,i.cloneElement)(e,{className:"margin-top--md"}):null}return i.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,i.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function T(e){const t=h(e);return i.createElement("div",{className:(0,o.Z)("tabs-container",b.tabList)},i.createElement(N,(0,a.Z)({},e,t)),i.createElement(f,(0,a.Z)({},e,t)))}function y(e){const t=(0,g.Z)();return i.createElement(T,(0,a.Z)({key:String(t)},e))}},2044:(e,t,n)=>{n.d(t,{$t:()=>d,Ae:()=>g,C:()=>k,DK:()=>b,Fo:()=>l,Fs:()=>i,IM:()=>h,IZ:()=>a,RS:()=>C,VE:()=>N,Wg:()=>T,_A:()=>p,al:()=>_,jk:()=>c,js:()=>s,of:()=>m,q5:()=>r,qb:()=>y,vk:()=>u,wU:()=>o,zg:()=>f});const a="shell",i="database",o="application",r="bash",l="pwsh",s="zsh",p="maria",m="mysql",d="postgres",u="sqlite",c="application",k="bash",h="pwsh",g="zsh",b="MariaDB",N="MySQL",f="PostgreSQL",T="SQLite",y="tinyorm.org",_="$HOME/Code/c/",C="$env:USERPROFILE\\Code\\c\\"},4355:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(7294),i=n(9482);function o(){const e=(0,a.useContext)(i.Z);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6005:(e,t,n)=>{n.d(t,{AE:()=>l,EA:()=>r,em:()=>p,go:()=>s,mT:()=>m,we:()=>d});var a=n(4355),i=n(2389),o=n(2044);const r=function(e,t){return void 0===t&&(t=!0),u((0,a.Z)().rootFolder[e]??p(e),e,t)},l=()=>(0,a.Z)().rootFolder[o.wU]??p(o.wU),s=function(e,t){if(void 0===t&&(t=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const n=t||e!==o.Fo?"/":"\\";return u(r(e)+n+l(),e,t)};function p(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,i.Z)())return"";switch(e){case o.Fo:return o.RS;case o.q5:return o.al;case o.wU:return o.qb;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function m(e){return e===o.wU}function d(e,t){if(null==t||""===t)return t;const n="$ENV{$1}$2";switch(e){case o.Fo:return k(t).replace(/\$env:(.+?)(\/.*)/,n);case o.q5:return t.replace(/\$(.+?)(\/.*)/,n);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function u(e,t,n){if(void 0===n&&(n=!0),null==e||""===e)return e;if(t!==o.Fo)return c(e);const a=c(e);return n?k(a):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(a)}function c(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function k(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},3974:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>d,default:()=>b,frontMatter:()=>m,metadata:()=>u,toc:()=>k});var a=n(7462),i=(n(7294),n(3905)),o=n(7693),r=n(5162),l=n(4866),s=n(2044),p=n(6005);const m={sidebar_position:3,sidebar_label:"Migrations",description:"How to compile the TinyORM migrations (tom) C++ console application on Windows and Linux.",keywords:["c++ orm","building","migrations","tinyorm"]},d="Building: Migrations",u={unversionedId:"building/migrations",id:"building/migrations",title:"Building: Migrations",description:"How to compile the TinyORM migrations (tom) C++ console application on Windows and Linux.",source:"@site/docs/building/migrations.mdx",sourceDirName:"building",slug:"/building/migrations",permalink:"/building/migrations",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/building/migrations.mdx",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3,sidebar_label:"Migrations",description:"How to compile the TinyORM migrations (tom) C++ console application on Windows and Linux.",keywords:["c++ orm","building","migrations","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Hello world",permalink:"/building/hello-world"},next:{title:"\ud83d\udcc4 Features Summary",permalink:"/features-summary"}},c={},k=[{value:"Introduction",id:"introduction",level:2},{value:"Install dependencies",id:"install-dependencies",level:2},{value:"Using vcpkg.json (manifest mode)",id:"using-vcpkg-json-manifest-mode",level:4},{value:"Using vcpkg install (manually)",id:"using-vcpkg-install-manually",level:4},{value:"Source code",id:"source-code",level:2},{value:"Main file",id:"main-file",level:3},{value:"Migrations",id:"migrations",level:3},{value:"Seeders",id:"seeders",level:3},{value:"Migrations with CMake",id:"migrations-with-cmake",level:2},{value:"CMake project",id:"cmake-project",level:3},{value:"Build migrations",id:"build-migrations-cmake",level:3},{value:"Execute migrations",id:"execute-migrations-cmake",level:3},{value:"Migrations with qmake",id:"migrations-with-qmake",level:2},{value:"qmake project",id:"qmake-project",level:3},{value:"Auto-configure using .qmake.conf and .env",id:"auto-configure-using-qmakeconf-and-env",level:4},{value:"Migrations source files",id:"migrations-source-files",level:4},{value:"Seeders source files",id:"seeders-source-files",level:4},{value:"Build migrations",id:"build-migrations-qmake",level:3},{value:"Execute migrations",id:"execute-migrations-qmake",level:3},{value:"Finish",id:"finish",level:2}],h={toc:k},g="wrapper";function b(e){let{components:t,...m}=e;return(0,i.kt)(g,(0,a.Z)({},h,m,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"building-migrations"},"Building: Migrations"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#install-dependencies"},"Install dependencies"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#using-vcpkg-json-manifest-mode"},"Using vcpkg.json")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#using-vcpkg-install-manually"},"Using vcpkg install")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#source-code"},"Source code"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#main-file"},"Main file")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#migrations"},"Migrations")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#seeders"},"Seeders")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#migrations-with-cmake"},"Migrations with CMake"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#cmake-project"},"CMake project")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#build-migrations-cmake"},"Build migrations")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#execute-migrations-cmake"},"Execute migrations")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#migrations-with-qmake"},"Migrations with qmake"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#qmake-project"},"qmake project")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#build-migrations-qmake"},"Build migrations")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#execute-migrations-qmake"},"Execute migrations")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#finish"},"Finish"))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,"We will try to create a working migrations console application called as ",(0,i.kt)("abbr",{title:"TinyORM migrations"},(0,i.kt)("inlineCode",{parentName:"p"},"tom"))," in the terminal with the ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," and in the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator IDE")," with the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," build systems."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," console application also expects the following ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure"),", let's create them."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.Fo)}\nmkdir tom/tom\ncd tom`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.q5)}\nmkdir -p tom/tom\ncd tom`))),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source tree contains the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," example application, you can inspire or look at the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/examples/tom"},"source code"),". Also, ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," unit tests use a ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations internally to create the database structure, internally called as the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/tests/testdata_tom"},(0,i.kt)("inlineCode",{parentName:"a"},"tom")," migrations for unit tests"),"."),(0,i.kt)("p",null,"All these three console applications the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," example, ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations for unit tests, and the application described in this tutorial have practically identical source code (the main.cpp file)."),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," is able to generate ",(0,i.kt)("a",{href:"https://en.wikipedia.org/wiki/Data_definition_language",title:"Data Definition Language"},"DDL")," queries for all the ",(0,i.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"supported databases")," databases.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"You can see the ",(0,i.kt)("a",{parentName:"p",href:"/features-summary#tom-console-application"},"Tom showcase image")," of how the resulting ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," console application will look like.")),(0,i.kt)("h2",{id:"install-dependencies"},"Install dependencies"),(0,i.kt)("p",null,"First, install the ",(0,i.kt)("inlineCode",{parentName:"p"},"vcpkg")," package manager as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#vcpkg"},"here"),"."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"tabulate")," libraries are required dependencies because ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," uses them in header files, you have to install them before you can use ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM"),". The ",(0,i.kt)("inlineCode",{parentName:"p"},"tabulate")," library is only needed in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations it's used by the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:status")," command."),(0,i.kt)("p",null,"There are two ways how to install the ",(0,i.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"tabulate")," libraries using ",(0,i.kt)("inlineCode",{parentName:"p"},"vcpkg"),"."),(0,i.kt)("p",null,"Also, don't forget to build the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," library with the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," source code enabled (it's enabled by default) as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm"},"here"),"."),(0,i.kt)("h4",{id:"using-vcpkg-json-manifest-mode"},"Using vcpkg.json ",(0,i.kt)("small",null,"(manifest mode)")),(0,i.kt)("p",null,"Create a ",(0,i.kt)("inlineCode",{parentName:"p"},"vcpkg.json")," file with the following content. ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," example below uses this method."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cd tom\nvim vcpkg.json\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-json",metastring:"title='vcpkg.json'",title:"'vcpkg.json'"},'{\n "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",\n "name": "tom",\n "version-semver": "0.1.0",\n "description": "Tom console application for TinyORM C++ library",\n "homepage": "https://github.com/silverqx/TinyORM",\n "documentation": "https://www.tinyorm.org/building/migrations",\n "maintainers": "Silver Zachara ",\n "supports": "!(uwp | arm | android | emscripten | osx | ios | xbox | freebsd | openbsd | wasm32)",\n "dependencies": [\n "range-v3",\n "tabulate"\n ]\n}\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"Only ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," via the ",(0,i.kt)("inlineCode",{parentName:"p"},"toolchain file")," supports this method.")),(0,i.kt)("h4",{id:"using-vcpkg-install-manually"},"Using vcpkg install ",(0,i.kt)("small",null,"(manually)")),(0,i.kt)("p",null,"This method can be used with both ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../../vcpkg\n\nvcpkg search range-v3\nvcpkg search tabulate\nvcpkg install range-v3 tabulate\nvcpkg list\n")),(0,i.kt)("h2",{id:"source-code"},"Source code"),(0,i.kt)("p",null,"Let's start in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," project folder."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.Fo)}/tom/tom`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.q5)}/tom/tom`))),(0,i.kt)("h3",{id:"main-file"},"Main file"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"main.cpp")," source file."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"vim main.cpp\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"To paste a source code correctly in ",(0,i.kt)("inlineCode",{parentName:"p"},"vim"),", press ",(0,i.kt)("kbd",null,"Shift")," + ",(0,i.kt)("kbd",null,"p"),".")),(0,i.kt)("p",null,"And paste the following code."),(0,i.kt)("a",{id:"string-constants-example"}),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp",metastring:"title='main.cpp'",title:"'main.cpp'"},'#include \n\n#include \n\n#include "migrations/2014_10_12_000000_create_posts_table.hpp"\n\n#include "seeders/databaseseeder.hpp"\n\nusing Orm::DatabaseManager;\nusing Orm::DB;\n\nusing TomApplication = Tom::Application;\n\nusing namespace Migrations; // NOLINT(google-build-using-namespace)\nusing namespace Seeders; // NOLINT(google-build-using-namespace)\n\n/*! Create the database manager instance and add a database connection. */\nstd::shared_ptr setupDatabaseManager();\n\n/*! C++ main function. */\nint main(int argc, char *argv[])\n{\n try {\n // Ownership of the shared_ptr()\n auto db = setupDatabaseManager();\n\n return TomApplication(argc, argv, std::move(db), "TOM_EXAMPLE_ENV")\n .migrations()\n .seeders()\n // Fire it up \ud83d\udd25\ud83d\ude80\u2728\n .run();\n\n } catch (const std::exception &e) {\n\n TomApplication::logException(e);\n }\n\n return EXIT_FAILURE;\n}\n\nstd::shared_ptr setupDatabaseManager()\n{\n using namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n // Ownership of the shared_ptr()\n return DB::create({\n {driver_, QMYSQL},\n {host_, qEnvironmentVariable("DB_MYSQL_HOST", H127001)},\n {port_, qEnvironmentVariable("DB_MYSQL_PORT", P3306)},\n {database_, qEnvironmentVariable("DB_MYSQL_DATABASE", EMPTY)},\n {username_, qEnvironmentVariable("DB_MYSQL_USERNAME", EMPTY)},\n {password_, qEnvironmentVariable("DB_MYSQL_PASSWORD", EMPTY)},\n {charset_, qEnvironmentVariable("DB_MYSQL_CHARSET", UTF8MB4)},\n {collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},\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 {strict_, true},\n },\n QStringLiteral("tinyorm_tom_mysql")); // shell:connection\n}\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"If you have defined more database connections then you can tag the lines with the database connection names with the ",(0,i.kt)("inlineCode",{parentName:"p"},"// shell:connection")," comment and this connection names will be provided to the bash, zsh, pwsh completions for the ",(0,i.kt)("inlineCode",{parentName:"p"},"--database=")," option \ud83d\ude0e, ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/examples/tom/main.cpp#L74"},"example"),".")),(0,i.kt)("h3",{id:"migrations"},"Migrations"),(0,i.kt)("p",null,"If you have already built the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application then you can generate a migrations using the ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#generating-migrations"},(0,i.kt)("inlineCode",{parentName:"a"},"make:migration"))," command \ud83d\ude0e."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:migration create_posts_table\n")),(0,i.kt)("p",null,"Below is the expected folders structure for the migrations. The ",(0,i.kt)("a",{parentName:"p",href:"#migrations-source-files"},(0,i.kt)("inlineCode",{parentName:"a"},"migrations.pri"))," file is used only by the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," build system and is not needed with ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," builds."),(0,i.kt)("a",{id:"folders-structure"}),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-text"},"tom/\n\u2514\u2500\u2500 database/\n \u251c\u2500\u2500 migrations/\n \u251c\u2500\u2500 seeders/\n \u251c\u2500\u2500 migrations.pri\n \u2514\u2500\u2500 seeders.pri\n")),(0,i.kt)("p",null,"Let's create the first migration manually."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},"mkdir database/migrations\n\nvim database/migrations/2014_10_12_000000_create_posts_table.hpp")),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},"mkdir -p database/migrations\n\nvim database/migrations/2014_10_12_000000_create_posts_table.hpp"))),(0,i.kt)("p",null,"And paste the following code."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp",metastring:"title='database/migrations/2014_10_12_000000_create_posts_table.hpp'",title:"'database/migrations/2014_10_12_000000_create_posts_table.hpp'"},'#pragma once\n\n#include \n\nnamespace Migrations\n{\n\n struct CreatePostsTable : Migration\n {\n /*! Filename of the migration file. */\n T_MIGRATION\n\n /*! Run the migrations. */\n void up() const override\n {\n Schema::create("posts", [](Blueprint &table)\n {\n table.id();\n\n table.string(NAME);\n table.timestamps();\n });\n }\n\n /*! Reverse the migrations. */\n void down() const override\n {\n Schema::dropIfExists("posts");\n }\n };\n\n} // namespace Migrations\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source tree contains the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tests/database/migrations/2014_10_12_000000_create_posts_table.hpp#L5"},(0,i.kt)("inlineCode",{parentName:"a"},"CreatePostsTable"))," example migration that also acts as the full-fledged example migration. It has defined and also nicely commented all possible features that migration classes can use or define.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"If you want, you can also build the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application without the migrations, simply comment out the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrations")," method and the corresponding ",(0,i.kt)("inlineCode",{parentName:"p"},'#include "migrations/xyz.hpp"')," files.")),(0,i.kt)("h3",{id:"seeders"},"Seeders"),(0,i.kt)("p",null,"If you have already built the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application then you can generate a seeder using the ",(0,i.kt)("a",{parentName:"p",href:"/database/seeding#writing-seeders"},(0,i.kt)("inlineCode",{parentName:"a"},"make:seeder"))," command \ud83d\ude0e."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:seeder PostSeeder\n")),(0,i.kt)("p",null,"The expected folders structure is described a few paragraphs ",(0,i.kt)("a",{parentName:"p",href:"#folders-structure"},"above"),". The ",(0,i.kt)("a",{parentName:"p",href:"#seeders-source-files"},(0,i.kt)("inlineCode",{parentName:"a"},"seeders.pri"))," file is used only by the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," build system and is not needed with ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," builds."),(0,i.kt)("p",null,"Let's create the root seeder class manually."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},"mkdir database/seeders\n\nvim database/seeders/databaseseeder.hpp")),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},"mkdir -p database/seeders\n\nvim database/seeders/databaseseeder.hpp"))),(0,i.kt)("p",null,"And paste the following code."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp",metastring:"title='database/seeders/databaseseeder.hpp'",title:"'database/seeders/databaseseeder.hpp'"},'#pragma once\n\n#include \n\nnamespace Seeders\n{\n\n /*! Main database seeder. */\n struct DatabaseSeeder : Seeder\n {\n /*! Run the database seeders. */\n void run() override\n {\n DB::table("posts")->insert({\n {{"name", "1. post"}},\n {{"name", "2. post"}},\n });\n }\n };\n\n} // namespace Seeders\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source tree contains the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tests/database/seeders/databaseseeder.hpp#L8"},(0,i.kt)("inlineCode",{parentName:"a"},"DatabaseSeeder"))," root seeder example class that also acts as the full-fledged example seeder. It has defined and also nicely commented all possible features that seeder classes can use or define.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can create more seeder classes like this and use the ",(0,i.kt)("inlineCode",{parentName:"p"},"call<>()")," method to invoke them as is described in the ",(0,i.kt)("a",{parentName:"p",href:"/database/seeding#calling-additional-seeders"},"Calling Additional Seeders")," section.")),(0,i.kt)("h2",{id:"migrations-with-cmake"},"Migrations with CMake"),(0,i.kt)("p",null,"Create a folder for the ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," build."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},"cd ..\nmkdir tom-builds-cmake/build-debug\n\ncd tom")),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},"cd ..\nmkdir -p tom-builds-cmake/build-debug\n\ncd tom"))),(0,i.kt)("h3",{id:"cmake-project"},"CMake project"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"CMakeLists.txt")," file with the following content. I leave the comments in the ",(0,i.kt)("inlineCode",{parentName:"p"},"CMakeLists.txt")," file because it's not as simple as the ",(0,i.kt)("inlineCode",{parentName:"p"},"Hello world")," example; to make it clear what's going on."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cmake",metastring:"title='CMakeLists.txt'",title:"'CMakeLists.txt'"},'cmake_minimum_required(VERSION VERSION 3.22...3.28 FATAL_ERROR)\n\n# Specify the C++ standard\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\n# Initialize variables\n# ---\n\nset(Tom_ns tom)\nset(Tom_target tom)\n\nfile(REAL_PATH "../../TinyORM" TinyMainDir)\n\nset(TinyOrmSourceDir "${TinyMainDir}/TinyORM")\nset(TinyOrmBuildDir "${TinyMainDir}/TinyORM-builds-cmake/build-debug")\n\n# TinyORM CMake modules (needed to set the executable version and RC file on Windows)\nlist(APPEND CMAKE_MODULE_PATH "${TinyOrmSourceDir}/cmake/CommonModules")\n\n# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${TinyOrmBuildDir}")\n\n# Initialize Project Version\n# ---\n\ninclude(TinyHelpers)\ntiny_read_version(TINY_VERSION\n TINY_VERSION_MAJOR TINY_VERSION_MINOR TINY_VERSION_PATCH TINY_VERSION_TWEAK\n VERSION_HEADER "${TinyOrmSourceDir}/tom/include/tom/version.hpp"\n PREFIX TINYTOM\n HEADER_FOR "${Tom_ns}"\n)\n\n# Basic project\n# ---\n\nproject(${Tom_ns}\n DESCRIPTION "Tom console application for TinyORM C++ library"\n HOMEPAGE_URL "https://www.tinyorm.org"\n LANGUAGES CXX\n VERSION ${TINY_VERSION}\n)\n\n# Tom command-line application\n# ---\n\nadd_executable(${Tom_target}\n main.cpp\n)\nadd_executable(${Tom_ns}::${Tom_target} ALIAS ${Tom_target})\n\n# Tom command-line application specific configuration\n# ---\n\nset_target_properties(${Tom_target}\n PROPERTIES\n C_VISIBILITY_PRESET "hidden"\n CXX_VISIBILITY_PRESET "hidden"\n VISIBILITY_INLINES_HIDDEN YES\n VERSION ${PROJECT_VERSION}\n)\n\ntarget_include_directories(${Tom_target}\n PRIVATE "$"\n)\n\n# Tom command-line application defines\n# ---\n\ntarget_compile_definitions(${Tom_target}\n PRIVATE\n PROJECT_TOM\n)\n\n# Windows resource and manifest files\n# ---\n\n# Find icons, tom/version.hpp, and Windows manifest file for MinGW\nif(CMAKE_SYSTEM_NAME STREQUAL "Windows")\n tiny_set_rc_flags("-I \\"${TinyOrmSourceDir}/tom/resources\\"")\nendif()\n\ninclude(TinyResourceAndManifest)\ntiny_resource_and_manifest(${Tom_target}\n OUTPUT_DIR "${TINY_BUILD_GENDIR}/tmp/"\n RESOURCES_DIR "${TinyOrmSourceDir}/tom/resources"\n)\n\n# Resolve and link dependencies\n# ---\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.36.5 CONFIG REQUIRED)\n\n# Unconditional dependencies\ntarget_link_libraries(${Tom_target}\n PRIVATE\n Qt${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)\n')),(0,i.kt)("h3",{id:"build-migrations-cmake"},"Build migrations"),(0,i.kt)("p",null,"Now you are ready to configure ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," application. Don't forget to prepare the build environment with the ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#windows-prerequisites"},(0,i.kt)("inlineCode",{parentName:"a"},"qtenv6.ps1"))," command if you are building with the ",(0,i.kt)("inlineCode",{parentName:"p"},"msvc"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../tom-builds-cmake/build-debug\n")),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cmake.exe \`\n-S "${(0,p.go)(s.Fo)}/tom/tom" \`\n-B "${(0,p.go)(s.Fo)}/tom/tom-builds-cmake/build-debug" \`\n-G 'Ninja' \`\n-D CMAKE_BUILD_TYPE:STRING='Debug' \`\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,p.EA)(s.Fo)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \`\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,p.EA)(s.Fo)}/tmp/tom"`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cmake \\\n-S "${(0,p.go)(s.q5)}/tom/tom" \\\n-B "${(0,p.go)(s.q5)}/tom/tom-builds-cmake/build-debug" \\\n-G 'Ninja' \\\n-D CMAKE_BUILD_TYPE:STRING='Debug' \\\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,p.EA)(s.q5)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \\\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,p.EA)(s.q5)}/tmp/tom"`))),(0,i.kt)("p",null,"And build."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cmake --build . --target all\n")),(0,i.kt)("h3",{id:"execute-migrations-cmake"},"Execute migrations"),(0,i.kt)("p",null,"Do not forget to add ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyOrm0d.dll")," on the path on Windows and on the ",(0,i.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux, so ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application can find it during execution, as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#tinyorm-on-path-cmake"},"here"),"."),(0,i.kt)(l.Z,{groupId:s.IZ,name:"tinyorm-on-path",mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,p.go)(s.Fo,!1)}\\TinyORM\\TinyORM-builds-cmake\\build-debug;" + $env:Path`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export LD_LIBRARY_PATH=${(0,p.go)(s.q5)}/TinyORM/TinyORM-builds-cmake/build-debug\${PATH:+:}$PATH`))),(0,i.kt)("p",null,"Execute ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-powershell"},".\\tom.exe migrate:status\n"))),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"./tom migrate:status\n")))),(0,i.kt)("p",null,"The output will look something like this."),(0,i.kt)("img",{src:n(3086).Z,alt:"Tom migrations - migrate:status command output",width:"660"}),(0,i.kt)("p",null,"See also the ",(0,i.kt)("a",{parentName:"p",href:"#finish"},"final thoughts")," on how to verify the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," executable file properties."),(0,i.kt)("p",null,"Happy migrating \ud83c\udf89\ud83d\udc4c"),(0,i.kt)("h2",{id:"migrations-with-qmake"},"Migrations with qmake"),(0,i.kt)("p",null,"Create a folder for the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," build."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.Fo)}/tom\n\nmkdir tom-builds-qmake`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.q5)}/tom\n\nmkdir tom-builds-qmake`))),(0,i.kt)("p",null,"The ",(0,i.kt)("a",{parentName:"p",href:"#source-code"},(0,i.kt)("inlineCode",{parentName:"a"},"source code"))," is the same as for the ",(0,i.kt)("inlineCode",{parentName:"p"},"Migrations with CMake")," console application."),(0,i.kt)("h3",{id:"qmake-project"},"qmake project"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"tom.pro")," qmake file with the following content."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cd tom\nvim tom.pro\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"To paste a source code correctly in ",(0,i.kt)("inlineCode",{parentName:"p"},"vim"),", press ",(0,i.kt)("kbd",null,"Shift")," + ",(0,i.kt)("kbd",null,"p"),".")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='tom.pro'",title:"'tom.pro'"},"QT -= gui\n\nTEMPLATE = app\nTARGET = tom\n\nCONFIG *= cmdline\n\nDEFINES += PROJECT_TOM\n\nSOURCES += $$PWD/main.cpp\n\n# Database migrations\ninclude($$PWD/database/migrations.pri)\n# Database seeders\ninclude($$PWD/database/seeders.pri)\n\n# Auto-configure TinyORM library for the migrations purposes \ud83d\udd25\ninclude($$TINY_MAIN_DIR/TinyORM/qmake/tom.pri)\n")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"The exact ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure")," is crucial in this example because the paths to the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source and build folders are relative.")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!")),(0,i.kt)("h4",{id:"auto-configure-using-qmakeconf-and-env"},(0,i.kt)("inlineCode",{parentName:"h4"},"Auto-configure")," using ",(0,i.kt)("inlineCode",{parentName:"h4"},".qmake.conf")," and ",(0,i.kt)("inlineCode",{parentName:"h4"},".env")),(0,i.kt)("p",null,"If you want to have properly configured ",(0,i.kt)("inlineCode",{parentName:"p"},"DEFINES")," (C preprocessor macros), have Qt headers marked as system headers, or eg. have properly set properties of an executable file such as version and description, then you need to specify a path to the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," qmake features (",(0,i.kt)("inlineCode",{parentName:"p"},".prf")," files) which handle this correctly; this path is provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"QMAKEFEATURES")," variable and can only be set in the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"Read the ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#consume-tinyorm-library-qmake"},"Consume TinyOrm library (qmake)")," section, as everything that is described in that section applies here as well.")),(0,i.kt)("p",null,"Create the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application root folder with the following content."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# Path to the PARENT folder of the TinyORM source folder\nTINY_MAIN_DIR = $$clean_path($$PWD/../../TinyORM/)\n# To find .env and .env.$$QMAKE_PLATFORM files\nTINY_DOTENV_ROOT = $$PWD\n# Path to the current build tree (used to guess the TinyORM build tree)\n#TINY_BUILD_TREE = $$shadowed($$PWD)\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")),(0,i.kt)("p",null,"Then, create a ",(0,i.kt)("code",null,".env.(win32","|","unix","|","mingw)")," file in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application root folder with the following content."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:".env.win32",mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in the tom.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_5_3_MSVC2022_64bit-Debug/)\n\n# Path to the vcpkg - range-v3 and tabulate\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-windows\n\n# Enable ccache wrapper\n#CONFIG *= tiny_ccache_win32\n"))),(0,i.kt)(r.Z,{value:s.q5,label:".env.unix",mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in the tom.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_5_3_clang16_64bit_ccache-Debug/)\n\n# Path to the vcpkg - range-v3 and tabulate\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-linux\n\n# Use faster linker\nclang: CONFIG *= use_lld_linker\nelse: CONFIG *= use_gold_linker\n\n# Or use the mold linker\n#QMAKE_LFLAGS *= -fuse-ld=mold\n"))),(0,i.kt)(r.Z,{value:"mingw",label:".env.mingw",mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in the tom.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_5_3_MSYS2_UCRT64_clang_64bit-Debug/)\n\n# Path to the vcpkg - range-v3 and tabulate\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-mingw-dynamic\n\n# Enable ccache wrapper\n#CONFIG *= tiny_ccache_win32\n\n# Use faster linker (for both GCC and Clang)\n# CONFIG *= use_lld_linker does not work on MinGW\nQMAKE_LFLAGS *= -fuse-ld=lld\n")))),(0,i.kt)("p",null,"Don't forget to update the ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"TINY_VCPKG_ROOT")," folder paths to your needs if you are not using the recommended ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},(0,i.kt)("inlineCode",{parentName:"a"},"Folders structure")),"."),(0,i.kt)("p",null,"You can use the ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,i.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," if you don't like to specify it manually. Just comment out the ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," and uncomment the ",(0,i.kt)("inlineCode",{parentName:"p"},"TINY_BUILD_TREE = $$shadowed($$PWD)")," in the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can entirely avoid the ",(0,i.kt)("inlineCode",{parentName:"p"},".env")," files, just move the ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," to the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," or remove it by help of ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,i.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," and set the ",(0,i.kt)("inlineCode",{parentName:"p"},"VCPKG_ROOT")," environment variable at system level as is described in ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#set-up-vcpkg-environment"},(0,i.kt)("inlineCode",{parentName:"a"},"Set up vcpkg environment")),".")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Configuring by the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," and ",(0,i.kt)("inlineCode",{parentName:"p"},".env")," files has one big advantage, which is that you don't have to modify the project files.")),(0,i.kt)("h4",{id:"migrations-source-files"},"Migrations source files"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"database/migrations.pri")," file and paste the following code."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='database/migrations.pri'",title:"'database/migrations.pri'"},"INCLUDEPATH *= $$PWD\n\nHEADERS += \\\n $$PWD/migrations/2014_10_12_000000_create_posts_table.hpp \\\n")),(0,i.kt)("h4",{id:"seeders-source-files"},"Seeders source files"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"database/seeders.pri")," file and paste the following code."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='database/seeders.pri'",title:"'database/seeders.pri'"},"INCLUDEPATH *= $$PWD\n\nHEADERS += \\\n $$PWD/seeders/databaseseeder.hpp \\\n")),(0,i.kt)("h3",{id:"build-migrations-qmake"},"Build migrations"),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"I recommend creating a new ",(0,i.kt)("inlineCode",{parentName:"p"},"Session")," in the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator IDE")," as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#open-qtcreator-ide"},"here"),".")),(0,i.kt)("p",null,"Now you can open the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom.pro")," project in the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),"."),(0,i.kt)("p",null,"This will open the ",(0,i.kt)("inlineCode",{parentName:"p"},"Configure Project")," tab, select some kit and update build folder paths to meet our ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure")," or like you want."),(0,i.kt)("img",{src:n(6191).Z,alt:"tom - QtCreator - Configure Project",width:"760"}),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can force the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator")," to generate a build folders structure as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#qtcreator-default-build-directory"},"here"),".")),(0,i.kt)("p",null,"You are ready to configure build options, hit ",(0,i.kt)("kbd",null,"Ctrl"),"+",(0,i.kt)("kbd",null,"5")," to open ",(0,i.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,i.kt)("inlineCode",{parentName:"p"},"Build")," in the left sidebar to open the ",(0,i.kt)("inlineCode",{parentName:"p"},"Build Settings"),", it should look similar to the following picture."),(0,i.kt)("img",{src:n(5539).Z,className:"no-blurry",alt:"tom - QtCreator - Build Settings",width:"760"}),(0,i.kt)("p",null,"Disable ",(0,i.kt)("inlineCode",{parentName:"p"},"QML debugging and profiling")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"Qt Quick Compiler"),", they are not used."),(0,i.kt)("p",null,"In the left sidebar open ",(0,i.kt)("inlineCode",{parentName:"p"},"Dependencies")," and check ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," project and ",(0,i.kt)("inlineCode",{parentName:"p"},"Synchronize configuration"),", this setting ensures that the current project will be rebuilt correctly when the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," library source code changes."),(0,i.kt)("p",null,"Everything is ready to build, you can press ",(0,i.kt)("kbd",null,"Ctrl"),"+",(0,i.kt)("kbd",null,"b")," to build the project."),(0,i.kt)("h3",{id:"execute-migrations-qmake"},"Execute migrations"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator")," takes care of all the necessary configurations, sets up the build environment correctly, and also prepends dependency libraries on the system path on Windows and on the ",(0,i.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux."),(0,i.kt)("p",null,"The only thing you might want to change is to run the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application in the new terminal window. To do so, hit ",(0,i.kt)("kbd",null,"Ctrl"),"+",(0,i.kt)("kbd",null,"5")," to open the ",(0,i.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,i.kt)("inlineCode",{parentName:"p"},"Run")," in the left sidebar to open the ",(0,i.kt)("inlineCode",{parentName:"p"},"Run Settings"),", then in the ",(0,i.kt)("inlineCode",{parentName:"p"},"Run")," section select the ",(0,i.kt)("inlineCode",{parentName:"p"},"Run in terminal")," checkbox."),(0,i.kt)("p",null,"You can also set the ",(0,i.kt)("inlineCode",{parentName:"p"},"Command line arguments")," in this ",(0,i.kt)("inlineCode",{parentName:"p"},"Run")," section, eg. the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:status"),"."),(0,i.kt)("p",null,"To execute the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application press ",(0,i.kt)("kbd",null,"Ctrl")," + ",(0,i.kt)("kbd",null,"r"),"."),(0,i.kt)("p",null,"The output will look ",(0,i.kt)("strong",{parentName:"p"},"very similar")," to this if you add more migrations."),(0,i.kt)("img",{src:n(3086).Z,alt:"Tom migrations - migrate:status command output",width:"660"}),(0,i.kt)("p",null,"Happy migrating \ud83c\udf89\ud83d\udc4c"),(0,i.kt)("h2",{id:"finish"},"Finish"),(0,i.kt)("p",null,"As the last thing, you can check that all the file properties were correctly set by the ",(0,i.kt)("a",{parentName:"p",href:"https://docs.microsoft.com/en-us/windows/win32/menurc/resource-compiler"},(0,i.kt)("inlineCode",{parentName:"a"},"rc"))," compiler."),(0,i.kt)("p",null,"Find the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom.exe")," file and press ",(0,i.kt)("kbd",null,"Alt")," + ",(0,i.kt)("kbd",null,"Enter")," to open the file properties. To check the executable manifest you can use eg. the ",(0,i.kt)("a",{parentName:"p",href:"http://www.angusj.com/resourcehacker/"},"Resource Hacker"),"."),(0,i.kt)("img",{src:n(643).Z,alt:"tom.exe file properties detail",width:"440"}))}b.isMDXComponent=!0},5539:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-build_settings-e10927d1c4ed852620f9eb7564198940.png"},6191:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-configure_project-4721257090370204b0272d166512adef.png"},643:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/tom_file_properties-0df513c47ceadd5c09165e41c6b53086.png"},3086:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/tom_migrate_status-63c129a10bfe6bffe8d2d5ea280860e5.png"}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[225],{5162:(e,t,n)=>{n.d(t,{Z:()=>r});var a=n(7294),i=n(6010);const o={tabItem:"tabItem_Ymn6"};function r(e){let{children:t,hidden:n,className:r}=e;return a.createElement("div",{role:"tabpanel",className:(0,i.Z)(o.tabItem,r),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>y});var a=n(7462),i=n(7294),o=n(6010),r=n(2466),l=n(6550),s=n(1980),p=n(7392),m=n(12);function d(e){return function(e){return i.Children.map(e,(e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:i}}=e;return{value:t,label:n,attributes:a,default:i}}))}function u(e){const{values:t,children:n}=e;return(0,i.useMemo)((()=>{const e=t??d(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function c(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function k(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,s._X)(o),(0,i.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(a.location.search);t.set(o,e),a.replace({...a.location,search:t.toString()})}),[o,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,o=u(e),[r,l]=(0,i.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!c({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:o}))),[s,p]=k({queryString:n,groupId:a}),[d,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,m.Nk)(n);return[a,(0,i.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:a}),g=(()=>{const e=s??d;return c({value:e,tabValues:o})?e:null})();(0,i.useLayoutEffect)((()=>{g&&l(g)}),[g]);return{selectedValue:r,selectValue:(0,i.useCallback)((e=>{if(!c({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),p(e),h(e)}),[p,h,o]),tabValues:o}}var g=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function N(e){let{className:t,block:n,selectedValue:l,selectValue:s,tabValues:p}=e;const m=[],{blockElementScrollPositionUntilNextRender:d}=(0,r.o5)(),u=e=>{const t=e.currentTarget,n=m.indexOf(t),a=p[n].value;a!==l&&(d(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=m.indexOf(e.currentTarget)+1;t=m[n]??m[0];break}case"ArrowLeft":{const n=m.indexOf(e.currentTarget)-1;t=m[n]??m[m.length-1];break}}t?.focus()};return i.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":n},t)},p.map((e=>{let{value:t,label:n,attributes:r}=e;return i.createElement("li",(0,a.Z)({role:"tab",tabIndex:l===t?0:-1,"aria-selected":l===t,key:t,ref:e=>m.push(e),onKeyDown:c,onClick:u},r,{className:(0,o.Z)("tabs__item",b.tabItem,r?.className,{"tabs__item--active":l===t})}),n??t)})))}function f(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,i.cloneElement)(e,{className:"margin-top--md"}):null}return i.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,i.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function T(e){const t=h(e);return i.createElement("div",{className:(0,o.Z)("tabs-container",b.tabList)},i.createElement(N,(0,a.Z)({},e,t)),i.createElement(f,(0,a.Z)({},e,t)))}function y(e){const t=(0,g.Z)();return i.createElement(T,(0,a.Z)({key:String(t)},e))}},2044:(e,t,n)=>{n.d(t,{$t:()=>d,Ae:()=>g,C:()=>k,DK:()=>b,Fo:()=>l,Fs:()=>i,IM:()=>h,IZ:()=>a,RS:()=>C,VE:()=>N,Wg:()=>T,_A:()=>p,al:()=>_,jk:()=>c,js:()=>s,of:()=>m,q5:()=>r,qb:()=>y,vk:()=>u,wU:()=>o,zg:()=>f});const a="shell",i="database",o="application",r="bash",l="pwsh",s="zsh",p="maria",m="mysql",d="postgres",u="sqlite",c="application",k="bash",h="pwsh",g="zsh",b="MariaDB",N="MySQL",f="PostgreSQL",T="SQLite",y="tinyorm.org",_="$HOME/Code/c/",C="$env:USERPROFILE\\Code\\c\\"},4355:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(7294),i=n(9482);function o(){const e=(0,a.useContext)(i.Z);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6005:(e,t,n)=>{n.d(t,{AE:()=>l,EA:()=>r,em:()=>p,go:()=>s,mT:()=>m,we:()=>d});var a=n(4355),i=n(2389),o=n(2044);const r=function(e,t){return void 0===t&&(t=!0),u((0,a.Z)().rootFolder[e]??p(e),e,t)},l=()=>(0,a.Z)().rootFolder[o.wU]??p(o.wU),s=function(e,t){if(void 0===t&&(t=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const n=t||e!==o.Fo?"/":"\\";return u(r(e)+n+l(),e,t)};function p(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,i.Z)())return"";switch(e){case o.Fo:return o.RS;case o.q5:return o.al;case o.wU:return o.qb;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function m(e){return e===o.wU}function d(e,t){if(null==t||""===t)return t;const n="$ENV{$1}$2";switch(e){case o.Fo:return k(t).replace(/\$env:(.+?)(\/.*)/,n);case o.q5:return t.replace(/\$(.+?)(\/.*)/,n);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function u(e,t,n){if(void 0===n&&(n=!0),null==e||""===e)return e;if(t!==o.Fo)return c(e);const a=c(e);return n?k(a):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(a)}function c(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function k(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},3974:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>d,default:()=>b,frontMatter:()=>m,metadata:()=>u,toc:()=>k});var a=n(7462),i=(n(7294),n(3905)),o=n(7693),r=n(5162),l=n(4866),s=n(2044),p=n(6005);const m={sidebar_position:3,sidebar_label:"Migrations",description:"How to compile the TinyORM migrations (tom) C++ console application on Windows and Linux.",keywords:["c++ orm","building","migrations","tinyorm"]},d="Building: Migrations",u={unversionedId:"building/migrations",id:"building/migrations",title:"Building: Migrations",description:"How to compile the TinyORM migrations (tom) C++ console application on Windows and Linux.",source:"@site/docs/building/migrations.mdx",sourceDirName:"building",slug:"/building/migrations",permalink:"/building/migrations",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/building/migrations.mdx",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3,sidebar_label:"Migrations",description:"How to compile the TinyORM migrations (tom) C++ console application on Windows and Linux.",keywords:["c++ orm","building","migrations","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"Hello world",permalink:"/building/hello-world"},next:{title:"\ud83d\udcc4 Features Summary",permalink:"/features-summary"}},c={},k=[{value:"Introduction",id:"introduction",level:2},{value:"Install dependencies",id:"install-dependencies",level:2},{value:"Using vcpkg.json (manifest mode)",id:"using-vcpkg-json-manifest-mode",level:4},{value:"Using vcpkg install (manually)",id:"using-vcpkg-install-manually",level:4},{value:"Source code",id:"source-code",level:2},{value:"Main file",id:"main-file",level:3},{value:"Migrations",id:"migrations",level:3},{value:"Seeders",id:"seeders",level:3},{value:"Migrations with CMake",id:"migrations-with-cmake",level:2},{value:"CMake project",id:"cmake-project",level:3},{value:"Build migrations",id:"build-migrations-cmake",level:3},{value:"Execute migrations",id:"execute-migrations-cmake",level:3},{value:"Migrations with qmake",id:"migrations-with-qmake",level:2},{value:"qmake project",id:"qmake-project",level:3},{value:"Auto-configure using .qmake.conf and .env",id:"auto-configure-using-qmakeconf-and-env",level:4},{value:"Migrations source files",id:"migrations-source-files",level:4},{value:"Seeders source files",id:"seeders-source-files",level:4},{value:"Build migrations",id:"build-migrations-qmake",level:3},{value:"Execute migrations",id:"execute-migrations-qmake",level:3},{value:"Finish",id:"finish",level:2}],h={toc:k},g="wrapper";function b(e){let{components:t,...m}=e;return(0,i.kt)(g,(0,a.Z)({},h,m,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"building-migrations"},"Building: Migrations"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#install-dependencies"},"Install dependencies"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#using-vcpkg-json-manifest-mode"},"Using vcpkg.json")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#using-vcpkg-install-manually"},"Using vcpkg install")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#source-code"},"Source code"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#main-file"},"Main file")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#migrations"},"Migrations")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#seeders"},"Seeders")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#migrations-with-cmake"},"Migrations with CMake"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#cmake-project"},"CMake project")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#build-migrations-cmake"},"Build migrations")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#execute-migrations-cmake"},"Execute migrations")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#migrations-with-qmake"},"Migrations with qmake"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#qmake-project"},"qmake project")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#build-migrations-qmake"},"Build migrations")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#execute-migrations-qmake"},"Execute migrations")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#finish"},"Finish"))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,"We will try to create a working migrations console application called as ",(0,i.kt)("abbr",{title:"TinyORM migrations"},(0,i.kt)("inlineCode",{parentName:"p"},"tom"))," in the terminal with the ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," and in the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator IDE")," with the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," build systems."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," console application also expects the following ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure"),", let's create them."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.Fo)}\nmkdir tom/tom\ncd tom`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.q5)}\nmkdir -p tom/tom\ncd tom`))),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source tree contains the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," example application, you can inspire or look at the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/examples/tom"},"source code"),". Also, ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," unit tests use a ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations internally to create the database structure, internally called as the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/tests/testdata_tom"},(0,i.kt)("inlineCode",{parentName:"a"},"tom")," migrations for unit tests"),"."),(0,i.kt)("p",null,"All these three console applications the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," example, ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations for unit tests, and the application described in this tutorial have practically identical source code (the main.cpp file)."),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," is able to generate ",(0,i.kt)("a",{href:"https://en.wikipedia.org/wiki/Data_definition_language",title:"Data Definition Language"},"DDL")," queries for all the ",(0,i.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"supported databases")," databases.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"You can see the ",(0,i.kt)("a",{parentName:"p",href:"/features-summary#tom-console-application"},"Tom showcase image")," of how the resulting ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," console application will look like.")),(0,i.kt)("h2",{id:"install-dependencies"},"Install dependencies"),(0,i.kt)("p",null,"First, install the ",(0,i.kt)("inlineCode",{parentName:"p"},"vcpkg")," package manager as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#vcpkg"},"here"),"."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"tabulate")," libraries are required dependencies because ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," uses them in header files, you have to install them before you can use ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM"),". The ",(0,i.kt)("inlineCode",{parentName:"p"},"tabulate")," library is only needed in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations it's used by the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:status")," command."),(0,i.kt)("p",null,"There are two ways how to install the ",(0,i.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"tabulate")," libraries using ",(0,i.kt)("inlineCode",{parentName:"p"},"vcpkg"),"."),(0,i.kt)("p",null,"Also, don't forget to build the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," library with the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," source code enabled (it's enabled by default) as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm"},"here"),"."),(0,i.kt)("h4",{id:"using-vcpkg-json-manifest-mode"},"Using vcpkg.json ",(0,i.kt)("small",null,"(manifest mode)")),(0,i.kt)("p",null,"Create a ",(0,i.kt)("inlineCode",{parentName:"p"},"vcpkg.json")," file with the following content. ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," example below uses this method."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cd tom\nvim vcpkg.json\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-json",metastring:"title='vcpkg.json'",title:"'vcpkg.json'"},'{\n "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",\n "name": "tom",\n "version-semver": "0.1.0",\n "description": "Tom console application for TinyORM C++ library",\n "homepage": "https://github.com/silverqx/TinyORM",\n "documentation": "https://www.tinyorm.org/building/migrations",\n "maintainers": "Silver Zachara ",\n "supports": "!(uwp | arm | android | emscripten | osx | ios | xbox | freebsd | openbsd | wasm32)",\n "dependencies": [\n "range-v3",\n "tabulate"\n ]\n}\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"Only ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," via the ",(0,i.kt)("inlineCode",{parentName:"p"},"toolchain file")," supports this method.")),(0,i.kt)("h4",{id:"using-vcpkg-install-manually"},"Using vcpkg install ",(0,i.kt)("small",null,"(manually)")),(0,i.kt)("p",null,"This method can be used with both ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../../vcpkg\n\nvcpkg search range-v3\nvcpkg search tabulate\nvcpkg install range-v3 tabulate\nvcpkg list\n")),(0,i.kt)("h2",{id:"source-code"},"Source code"),(0,i.kt)("p",null,"Let's start in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," project folder."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.Fo)}/tom/tom`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.q5)}/tom/tom`))),(0,i.kt)("h3",{id:"main-file"},"Main file"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"main.cpp")," source file."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"vim main.cpp\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"To paste a source code correctly in ",(0,i.kt)("inlineCode",{parentName:"p"},"vim"),", press ",(0,i.kt)("kbd",null,"Shift")," + ",(0,i.kt)("kbd",null,"p"),".")),(0,i.kt)("p",null,"And paste the following code."),(0,i.kt)("a",{id:"string-constants-example"}),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp",metastring:"title='main.cpp'",title:"'main.cpp'"},'#include \n\n#include \n\n#include "migrations/2014_10_12_000000_create_posts_table.hpp"\n\n#include "seeders/databaseseeder.hpp"\n\nusing Orm::DatabaseManager;\nusing Orm::DB;\n\nusing TomApplication = Tom::Application;\n\nusing namespace Migrations; // NOLINT(google-build-using-namespace)\nusing namespace Seeders; // NOLINT(google-build-using-namespace)\n\n/*! Create the database manager instance and add a database connection. */\nstd::shared_ptr setupDatabaseManager();\n\n/*! C++ main function. */\nint main(int argc, char *argv[])\n{\n try {\n // Ownership of the shared_ptr()\n auto db = setupDatabaseManager();\n\n return TomApplication(argc, argv, std::move(db), "TOM_EXAMPLE_ENV")\n .migrations()\n .seeders()\n // Fire it up \ud83d\udd25\ud83d\ude80\u2728\n .run();\n\n } catch (const std::exception &e) {\n\n TomApplication::logException(e);\n }\n\n return EXIT_FAILURE;\n}\n\nstd::shared_ptr setupDatabaseManager()\n{\n using namespace Orm::Constants; // NOLINT(google-build-using-namespace)\n\n // Ownership of the shared_ptr()\n return DB::create({\n {driver_, QMYSQL},\n {host_, qEnvironmentVariable("DB_MYSQL_HOST", H127001)},\n {port_, qEnvironmentVariable("DB_MYSQL_PORT", P3306)},\n {database_, qEnvironmentVariable("DB_MYSQL_DATABASE", EMPTY)},\n {username_, qEnvironmentVariable("DB_MYSQL_USERNAME", EMPTY)},\n {password_, qEnvironmentVariable("DB_MYSQL_PASSWORD", EMPTY)},\n {charset_, qEnvironmentVariable("DB_MYSQL_CHARSET", UTF8MB4)},\n {collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},\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 {strict_, true},\n },\n QStringLiteral("tinyorm_tom_mysql")); // shell:connection\n}\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"If you have defined more database connections then you can tag the lines with the database connection names with the ",(0,i.kt)("inlineCode",{parentName:"p"},"// shell:connection")," comment and this connection names will be provided to the bash, zsh, pwsh completions for the ",(0,i.kt)("inlineCode",{parentName:"p"},"--database=")," option \ud83d\ude0e, ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/examples/tom/main.cpp#L74"},"example"),".")),(0,i.kt)("h3",{id:"migrations"},"Migrations"),(0,i.kt)("p",null,"If you have already built the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application then you can generate a migrations using the ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#generating-migrations"},(0,i.kt)("inlineCode",{parentName:"a"},"make:migration"))," command \ud83d\ude0e."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:migration create_posts_table\n")),(0,i.kt)("p",null,"Below is the expected folders structure for the migrations. The ",(0,i.kt)("a",{parentName:"p",href:"#migrations-source-files"},(0,i.kt)("inlineCode",{parentName:"a"},"migrations.pri"))," file is used only by the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," build system and is not needed with ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," builds."),(0,i.kt)("a",{id:"folders-structure"}),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-text"},"tom/\n\u2514\u2500\u2500 database/\n \u251c\u2500\u2500 migrations/\n \u251c\u2500\u2500 seeders/\n \u251c\u2500\u2500 migrations.pri\n \u2514\u2500\u2500 seeders.pri\n")),(0,i.kt)("p",null,"Let's create the first migration manually."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},"mkdir database/migrations\n\nvim database/migrations/2014_10_12_000000_create_posts_table.hpp")),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},"mkdir -p database/migrations\n\nvim database/migrations/2014_10_12_000000_create_posts_table.hpp"))),(0,i.kt)("p",null,"And paste the following code."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp",metastring:"title='database/migrations/2014_10_12_000000_create_posts_table.hpp'",title:"'database/migrations/2014_10_12_000000_create_posts_table.hpp'"},'#pragma once\n\n#include \n\nnamespace Migrations\n{\n\n struct CreatePostsTable : Migration\n {\n /*! Filename of the migration file. */\n T_MIGRATION\n\n /*! Run the migrations. */\n void up() const override\n {\n Schema::create("posts", [](Blueprint &table)\n {\n table.id();\n\n table.string(NAME);\n table.timestamps();\n });\n }\n\n /*! Reverse the migrations. */\n void down() const override\n {\n Schema::dropIfExists("posts");\n }\n };\n\n} // namespace Migrations\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source tree contains the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tests/database/migrations/2014_10_12_000000_create_posts_table.hpp#L5"},(0,i.kt)("inlineCode",{parentName:"a"},"CreatePostsTable"))," example migration that also acts as the full-fledged example migration. It has defined and also nicely commented all possible features that migration classes can use or define.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"If you want, you can also build the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application without the migrations, simply comment out the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrations")," method and the corresponding ",(0,i.kt)("inlineCode",{parentName:"p"},'#include "migrations/xyz.hpp"')," files.")),(0,i.kt)("h3",{id:"seeders"},"Seeders"),(0,i.kt)("p",null,"If you have already built the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application then you can generate a seeder using the ",(0,i.kt)("a",{parentName:"p",href:"/database/seeding#writing-seeders"},(0,i.kt)("inlineCode",{parentName:"a"},"make:seeder"))," command \ud83d\ude0e."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"tom make:seeder PostSeeder\n")),(0,i.kt)("p",null,"The expected folders structure is described a few paragraphs ",(0,i.kt)("a",{parentName:"p",href:"#folders-structure"},"above"),". The ",(0,i.kt)("a",{parentName:"p",href:"#seeders-source-files"},(0,i.kt)("inlineCode",{parentName:"a"},"seeders.pri"))," file is used only by the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," build system and is not needed with ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," builds."),(0,i.kt)("p",null,"Let's create the root seeder class manually."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},"mkdir database/seeders\n\nvim database/seeders/databaseseeder.hpp")),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},"mkdir -p database/seeders\n\nvim database/seeders/databaseseeder.hpp"))),(0,i.kt)("p",null,"And paste the following code."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp",metastring:"title='database/seeders/databaseseeder.hpp'",title:"'database/seeders/databaseseeder.hpp'"},'#pragma once\n\n#include \n\nnamespace Seeders\n{\n\n /*! Main database seeder. */\n struct DatabaseSeeder : Seeder\n {\n /*! Run the database seeders. */\n void run() override\n {\n DB::table("posts")->insert({\n {{"name", "1. post"}},\n {{"name", "2. post"}},\n });\n }\n };\n\n} // namespace Seeders\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source tree contains the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/tests/database/seeders/databaseseeder.hpp#L8"},(0,i.kt)("inlineCode",{parentName:"a"},"DatabaseSeeder"))," root seeder example class that also acts as the full-fledged example seeder. It has defined and also nicely commented all possible features that seeder classes can use or define.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can create more seeder classes like this and use the ",(0,i.kt)("inlineCode",{parentName:"p"},"call<>()")," method to invoke them as is described in the ",(0,i.kt)("a",{parentName:"p",href:"/database/seeding#calling-additional-seeders"},"Calling Additional Seeders")," section.")),(0,i.kt)("h2",{id:"migrations-with-cmake"},"Migrations with CMake"),(0,i.kt)("p",null,"Create a folder for the ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," build."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},"cd ..\nmkdir tom-builds-cmake/build-debug\n\ncd tom")),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},"cd ..\nmkdir -p tom-builds-cmake/build-debug\n\ncd tom"))),(0,i.kt)("h3",{id:"cmake-project"},"CMake project"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"CMakeLists.txt")," file with the following content. I leave the comments in the ",(0,i.kt)("inlineCode",{parentName:"p"},"CMakeLists.txt")," file because it's not as simple as the ",(0,i.kt)("inlineCode",{parentName:"p"},"Hello world")," example; to make it clear what's going on."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cmake",metastring:"title='CMakeLists.txt'",title:"'CMakeLists.txt'"},'cmake_minimum_required(VERSION VERSION 3.22...3.29 FATAL_ERROR)\n\n# Specify the C++ standard\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\n# Initialize variables\n# ---\n\nset(Tom_ns tom)\nset(Tom_target tom)\n\nfile(REAL_PATH "../../TinyORM" TinyMainDir)\n\nset(TinyOrmSourceDir "${TinyMainDir}/TinyORM")\nset(TinyOrmBuildDir "${TinyMainDir}/TinyORM-builds-cmake/build-debug")\n\n# TinyORM CMake modules (needed to set the executable version and RC file on Windows)\nlist(APPEND CMAKE_MODULE_PATH "${TinyOrmSourceDir}/cmake/CommonModules")\n\n# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${TinyOrmBuildDir}")\n\n# Initialize Project Version\n# ---\n\ninclude(TinyHelpers)\ntiny_read_version(TINY_VERSION\n TINY_VERSION_MAJOR TINY_VERSION_MINOR TINY_VERSION_PATCH TINY_VERSION_TWEAK\n VERSION_HEADER "${TinyOrmSourceDir}/tom/include/tom/version.hpp"\n PREFIX TINYTOM\n HEADER_FOR "${Tom_ns}"\n)\n\n# Basic project\n# ---\n\nproject(${Tom_ns}\n DESCRIPTION "Tom console application for TinyORM C++ library"\n HOMEPAGE_URL "https://www.tinyorm.org"\n LANGUAGES CXX\n VERSION ${TINY_VERSION}\n)\n\n# Tom command-line application\n# ---\n\nadd_executable(${Tom_target}\n main.cpp\n)\nadd_executable(${Tom_ns}::${Tom_target} ALIAS ${Tom_target})\n\n# Tom command-line application specific configuration\n# ---\n\nset_target_properties(${Tom_target}\n PROPERTIES\n C_VISIBILITY_PRESET "hidden"\n CXX_VISIBILITY_PRESET "hidden"\n VISIBILITY_INLINES_HIDDEN YES\n VERSION ${PROJECT_VERSION}\n)\n\ntarget_include_directories(${Tom_target}\n PRIVATE "$"\n)\n\n# Tom command-line application defines\n# ---\n\ntarget_compile_definitions(${Tom_target}\n PRIVATE\n PROJECT_TOM\n)\n\n# Windows resource and manifest files\n# ---\n\n# Find icons, tom/version.hpp, and Windows manifest file for MinGW\nif(CMAKE_SYSTEM_NAME STREQUAL "Windows")\n tiny_set_rc_flags("-I \\"${TinyOrmSourceDir}/tom/resources\\"")\nendif()\n\ninclude(TinyResourceAndManifest)\ntiny_resource_and_manifest(${Tom_target}\n OUTPUT_DIR "${TINY_BUILD_GENDIR}/tmp/"\n RESOURCES_DIR "${TinyOrmSourceDir}/tom/resources"\n)\n\n# Resolve and link dependencies\n# ---\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.37.0 CONFIG REQUIRED)\n\n# Unconditional dependencies\ntarget_link_libraries(${Tom_target}\n PRIVATE\n Qt${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)\n')),(0,i.kt)("h3",{id:"build-migrations-cmake"},"Build migrations"),(0,i.kt)("p",null,"Now you are ready to configure ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," application. Don't forget to prepare the build environment with the ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#windows-prerequisites"},(0,i.kt)("inlineCode",{parentName:"a"},"qtenv6.ps1"))," command if you are building with the ",(0,i.kt)("inlineCode",{parentName:"p"},"msvc"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../tom-builds-cmake/build-debug\n")),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cmake.exe \`\n-S "${(0,p.go)(s.Fo)}/tom/tom" \`\n-B "${(0,p.go)(s.Fo)}/tom/tom-builds-cmake/build-debug" \`\n-G 'Ninja' \`\n-D CMAKE_BUILD_TYPE:STRING='Debug' \`\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,p.EA)(s.Fo)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \`\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,p.EA)(s.Fo)}/tmp/tom"`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cmake \\\n-S "${(0,p.go)(s.q5)}/tom/tom" \\\n-B "${(0,p.go)(s.q5)}/tom/tom-builds-cmake/build-debug" \\\n-G 'Ninja' \\\n-D CMAKE_BUILD_TYPE:STRING='Debug' \\\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,p.EA)(s.q5)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \\\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,p.EA)(s.q5)}/tmp/tom"`))),(0,i.kt)("p",null,"And build."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cmake --build . --target all\n")),(0,i.kt)("h3",{id:"execute-migrations-cmake"},"Execute migrations"),(0,i.kt)("p",null,"Do not forget to add ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyOrm0d.dll")," on the path on Windows and on the ",(0,i.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux, so ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application can find it during execution, as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#tinyorm-on-path-cmake"},"here"),"."),(0,i.kt)(l.Z,{groupId:s.IZ,name:"tinyorm-on-path",mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,p.go)(s.Fo,!1)}\\TinyORM\\TinyORM-builds-cmake\\build-debug;" + $env:Path`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export LD_LIBRARY_PATH=${(0,p.go)(s.q5)}/TinyORM/TinyORM-builds-cmake/build-debug\${PATH:+:}$PATH`))),(0,i.kt)("p",null,"Execute ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-powershell"},".\\tom.exe migrate:status\n"))),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"./tom migrate:status\n")))),(0,i.kt)("p",null,"The output will look something like this."),(0,i.kt)("img",{src:n(3086).Z,alt:"Tom migrations - migrate:status command output",width:"660"}),(0,i.kt)("p",null,"See also the ",(0,i.kt)("a",{parentName:"p",href:"#finish"},"final thoughts")," on how to verify the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," executable file properties."),(0,i.kt)("p",null,"Happy migrating \ud83c\udf89\ud83d\udc4c"),(0,i.kt)("h2",{id:"migrations-with-qmake"},"Migrations with qmake"),(0,i.kt)("p",null,"Create a folder for the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," build."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:s.IM,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.Fo)}/tom\n\nmkdir tom-builds-qmake`)),(0,i.kt)(r.Z,{value:s.q5,label:s.C,mdxType:"TabItem"},(0,i.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(s.q5)}/tom\n\nmkdir tom-builds-qmake`))),(0,i.kt)("p",null,"The ",(0,i.kt)("a",{parentName:"p",href:"#source-code"},(0,i.kt)("inlineCode",{parentName:"a"},"source code"))," is the same as for the ",(0,i.kt)("inlineCode",{parentName:"p"},"Migrations with CMake")," console application."),(0,i.kt)("h3",{id:"qmake-project"},"qmake project"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"tom.pro")," qmake file with the following content."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"cd tom\nvim tom.pro\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"To paste a source code correctly in ",(0,i.kt)("inlineCode",{parentName:"p"},"vim"),", press ",(0,i.kt)("kbd",null,"Shift")," + ",(0,i.kt)("kbd",null,"p"),".")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='tom.pro'",title:"'tom.pro'"},"QT -= gui\n\nTEMPLATE = app\nTARGET = tom\n\nCONFIG *= cmdline\n\nDEFINES *= PROJECT_TOM\n\nSOURCES += $$PWD/main.cpp\n\n# Database migrations\ninclude($$PWD/database/migrations.pri)\n# Database seeders\ninclude($$PWD/database/seeders.pri)\n\n# Auto-configure TinyORM library for the migrations purposes \ud83d\udd25\ninclude($$TINY_MAIN_DIR/TinyORM/qmake/tom.pri)\n")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"The exact ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure")," is crucial in this example because the paths to the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," source and build folders are relative.")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!")),(0,i.kt)("h4",{id:"auto-configure-using-qmakeconf-and-env"},(0,i.kt)("inlineCode",{parentName:"h4"},"Auto-configure")," using ",(0,i.kt)("inlineCode",{parentName:"h4"},".qmake.conf")," and ",(0,i.kt)("inlineCode",{parentName:"h4"},".env")),(0,i.kt)("p",null,"If you want to have properly configured ",(0,i.kt)("inlineCode",{parentName:"p"},"DEFINES")," (C preprocessor macros), have Qt headers marked as system headers, or eg. have properly set properties of an executable file such as version and description, then you need to specify a path to the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," qmake features (",(0,i.kt)("inlineCode",{parentName:"p"},".prf")," files) which handle this correctly; this path is provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"QMAKEFEATURES")," variable and can only be set in the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"Read the ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#consume-tinyorm-library-qmake"},"Consume TinyOrm library (qmake)")," section, as everything that is described in that section applies here as well.")),(0,i.kt)("p",null,"Create the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application root folder with the following content."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# Path to the PARENT folder of the TinyORM source folder\nTINY_MAIN_DIR = $$clean_path($$PWD/../../TinyORM/)\n# To find .env and .env.$$QMAKE_PLATFORM files\nTINY_DOTENV_ROOT = $$PWD\n# Path to the current build tree (used to guess the TinyORM build tree)\n#TINY_BUILD_TREE = $$shadowed($$PWD)\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")),(0,i.kt)("p",null,"Then, create a ",(0,i.kt)("code",null,".env.(win32","|","unix","|","mingw)")," file in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application root folder with the following content."),(0,i.kt)(l.Z,{groupId:s.IZ,mdxType:"Tabs"},(0,i.kt)(r.Z,{value:s.Fo,label:".env.win32",mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in the tom.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSVC2022_64bit-Debug/)\n\n# Path to the vcpkg - range-v3 and tabulate\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-windows\n\n# Enable ccache wrapper\n#CONFIG *= tiny_ccache_win32\n"))),(0,i.kt)(r.Z,{value:s.q5,label:".env.unix",mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in the tom.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_clang16_64bit_ccache-Debug/)\n\n# Path to the vcpkg - range-v3 and tabulate\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-linux\n\n# Use faster linker\nclang: CONFIG *= use_lld_linker\nelse: CONFIG *= use_gold_linker\n\n# Or use the mold linker\n#QMAKE_LFLAGS *= -fuse-ld=mold\n"))),(0,i.kt)(r.Z,{value:"mingw",label:".env.mingw",mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in the tom.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSYS2_UCRT64_clang_64bit-Debug/)\n\n# Path to the vcpkg - range-v3 and tabulate\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-mingw-dynamic\n\n# Enable ccache wrapper\n#CONFIG *= tiny_ccache_win32\n\n# Use faster linker (for both GCC and Clang)\n# CONFIG *= use_lld_linker does not work on MinGW\nQMAKE_LFLAGS *= -fuse-ld=lld\n")))),(0,i.kt)("p",null,"Don't forget to update the ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"TINY_VCPKG_ROOT")," folder paths to your needs if you are not using the recommended ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},(0,i.kt)("inlineCode",{parentName:"a"},"Folders structure")),"."),(0,i.kt)("p",null,"You can use the ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,i.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," if you don't like to specify it manually. Just comment out the ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," and uncomment the ",(0,i.kt)("inlineCode",{parentName:"p"},"TINY_BUILD_TREE = $$shadowed($$PWD)")," in the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can entirely avoid the ",(0,i.kt)("inlineCode",{parentName:"p"},".env")," files, just move the ",(0,i.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," to the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," or remove it by help of ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,i.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," and set the ",(0,i.kt)("inlineCode",{parentName:"p"},"VCPKG_ROOT")," environment variable at system level as is described in ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#set-up-vcpkg-environment"},(0,i.kt)("inlineCode",{parentName:"a"},"Set up vcpkg environment")),".")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Configuring by the ",(0,i.kt)("inlineCode",{parentName:"p"},".qmake.conf")," and ",(0,i.kt)("inlineCode",{parentName:"p"},".env")," files has one big advantage, which is that you don't have to modify the project files.")),(0,i.kt)("h4",{id:"migrations-source-files"},"Migrations source files"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"database/migrations.pri")," file and paste the following code."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='database/migrations.pri'",title:"'database/migrations.pri'"},"INCLUDEPATH *= $$PWD\n\nHEADERS += \\\n $$PWD/migrations/2014_10_12_000000_create_posts_table.hpp \\\n")),(0,i.kt)("h4",{id:"seeders-source-files"},"Seeders source files"),(0,i.kt)("p",null,"Create ",(0,i.kt)("inlineCode",{parentName:"p"},"database/seeders.pri")," file and paste the following code."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='database/seeders.pri'",title:"'database/seeders.pri'"},"INCLUDEPATH *= $$PWD\n\nHEADERS += \\\n $$PWD/seeders/databaseseeder.hpp \\\n")),(0,i.kt)("h3",{id:"build-migrations-qmake"},"Build migrations"),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"I recommend creating a new ",(0,i.kt)("inlineCode",{parentName:"p"},"Session")," in the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator IDE")," as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#open-qtcreator-ide"},"here"),".")),(0,i.kt)("p",null,"Now you can open the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom.pro")," project in the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),"."),(0,i.kt)("p",null,"This will open the ",(0,i.kt)("inlineCode",{parentName:"p"},"Configure Project")," tab, select some kit and update build folder paths to meet our ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure")," or like you want."),(0,i.kt)("img",{src:n(6191).Z,alt:"tom - QtCreator - Configure Project",width:"760"}),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can force the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator")," to generate a build folders structure as is described ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#qtcreator-default-build-directory"},"here"),".")),(0,i.kt)("p",null,"You are ready to configure build options, hit ",(0,i.kt)("kbd",null,"Ctrl"),"+",(0,i.kt)("kbd",null,"5")," to open ",(0,i.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,i.kt)("inlineCode",{parentName:"p"},"Build")," in the left sidebar to open the ",(0,i.kt)("inlineCode",{parentName:"p"},"Build Settings"),", it should look similar to the following picture."),(0,i.kt)("img",{src:n(5539).Z,className:"no-blurry",alt:"tom - QtCreator - Build Settings",width:"760"}),(0,i.kt)("p",null,"Disable ",(0,i.kt)("inlineCode",{parentName:"p"},"QML debugging and profiling")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"Qt Quick Compiler"),", they are not used."),(0,i.kt)("p",null,"In the left sidebar open ",(0,i.kt)("inlineCode",{parentName:"p"},"Dependencies")," and check ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," project and ",(0,i.kt)("inlineCode",{parentName:"p"},"Synchronize configuration"),", this setting ensures that the current project will be rebuilt correctly when the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," library source code changes."),(0,i.kt)("p",null,"Everything is ready to build, you can press ",(0,i.kt)("kbd",null,"Ctrl"),"+",(0,i.kt)("kbd",null,"b")," to build the project."),(0,i.kt)("h3",{id:"execute-migrations-qmake"},"Execute migrations"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"QtCreator")," takes care of all the necessary configurations, sets up the build environment correctly, and also prepends dependency libraries on the system path on Windows and on the ",(0,i.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux."),(0,i.kt)("p",null,"The only thing you might want to change is to run the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application in the new terminal window. To do so, hit ",(0,i.kt)("kbd",null,"Ctrl"),"+",(0,i.kt)("kbd",null,"5")," to open the ",(0,i.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,i.kt)("inlineCode",{parentName:"p"},"Run")," in the left sidebar to open the ",(0,i.kt)("inlineCode",{parentName:"p"},"Run Settings"),", then in the ",(0,i.kt)("inlineCode",{parentName:"p"},"Run")," section select the ",(0,i.kt)("inlineCode",{parentName:"p"},"Run in terminal")," checkbox."),(0,i.kt)("p",null,"You can also set the ",(0,i.kt)("inlineCode",{parentName:"p"},"Command line arguments")," in this ",(0,i.kt)("inlineCode",{parentName:"p"},"Run")," section, eg. the ",(0,i.kt)("inlineCode",{parentName:"p"},"migrate:status"),"."),(0,i.kt)("p",null,"To execute the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," application press ",(0,i.kt)("kbd",null,"Ctrl")," + ",(0,i.kt)("kbd",null,"r"),"."),(0,i.kt)("p",null,"The output will look ",(0,i.kt)("strong",{parentName:"p"},"very similar")," to this if you add more migrations."),(0,i.kt)("img",{src:n(3086).Z,alt:"Tom migrations - migrate:status command output",width:"660"}),(0,i.kt)("p",null,"Happy migrating \ud83c\udf89\ud83d\udc4c"),(0,i.kt)("h2",{id:"finish"},"Finish"),(0,i.kt)("p",null,"As the last thing, you can check that all the file properties were correctly set by the ",(0,i.kt)("a",{parentName:"p",href:"https://docs.microsoft.com/en-us/windows/win32/menurc/resource-compiler"},(0,i.kt)("inlineCode",{parentName:"a"},"rc"))," compiler."),(0,i.kt)("p",null,"Find the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom.exe")," file and press ",(0,i.kt)("kbd",null,"Alt")," + ",(0,i.kt)("kbd",null,"Enter")," to open the file properties. To check the executable manifest you can use eg. the ",(0,i.kt)("a",{parentName:"p",href:"http://www.angusj.com/resourcehacker/"},"Resource Hacker"),"."),(0,i.kt)("img",{src:n(643).Z,alt:"tom.exe file properties detail",width:"440"}))}b.isMDXComponent=!0},5539:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-build_settings-e10927d1c4ed852620f9eb7564198940.png"},6191:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-configure_project-4721257090370204b0272d166512adef.png"},643:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/tom_file_properties-0df513c47ceadd5c09165e41c6b53086.png"},3086:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/tom_migrate_status-63c129a10bfe6bffe8d2d5ea280860e5.png"}}]); \ No newline at end of file diff --git a/assets/js/935f2afb.1589d25f.js b/assets/js/935f2afb.1589d25f.js new file mode 100644 index 000000000..d6035dbd1 --- /dev/null +++ b/assets/js/935f2afb.1589d25f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[53],{1109:e=>{e.exports=JSON.parse('{"pluginId":"default","version":"current","label":"Next","banner":null,"badge":false,"noIndex":false,"className":"docs-version-current","isLast":true,"docsSidebars":{"tinyormSidebar":[{"type":"link","label":"\ud83d\udd25 Prologue","href":"/","docId":"README"},{"type":"link","label":"\ud83d\udd27 Dependencies","href":"/dependencies","docId":"dependencies"},{"type":"link","label":"\ud83d\ude80 Supported Compilers","href":"/supported-compilers","docId":"supported-compilers"},{"type":"category","label":"\u2728 Database","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Getting Started","href":"/database/getting-started","docId":"database/getting-started"},{"type":"link","label":"Query Builder","href":"/database/query-builder","docId":"database/query-builder"},{"type":"link","label":"Migrations","href":"/database/migrations","docId":"database/migrations"},{"type":"link","label":"Seeding","href":"/database/seeding","docId":"database/seeding"}]},{"type":"category","label":"\ud83c\udf89 TinyORM","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Getting Started","href":"/tinyorm/getting-started","docId":"tinyorm/getting-started"},{"type":"link","label":"Relationships","href":"/tinyorm/relationships","docId":"tinyorm/relationships"},{"type":"link","label":"Collections","href":"/tinyorm/collections","docId":"tinyorm/collections"},{"type":"link","label":"Casts","href":"/tinyorm/casts","docId":"tinyorm/casts"},{"type":"link","label":"Serialization","href":"/tinyorm/serialization","docId":"tinyorm/serialization"}]},{"type":"category","label":"\ud83e\uddec TinyDrivers","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Getting Started","href":"/tinydrivers/getting-started","docId":"tinydrivers/getting-started"}]},{"type":"category","label":"\ud83d\udea7 Building","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"TinyORM","href":"/building/tinyorm","docId":"building/tinyorm"},{"type":"link","label":"Hello world","href":"/building/hello-world","docId":"building/hello-world"},{"type":"link","label":"Migrations","href":"/building/migrations","docId":"building/migrations"}]},{"type":"link","label":"\ud83d\udcc4 Features Summary","href":"/features-summary","docId":"features-summary"},{"type":"link","label":"\u2764\ufe0f Sponsors","href":"/sponsors","docId":"sponsors"}]},"docs":{"building/hello-world":{"id":"building/hello-world","title":"Building: Hello world","description":"Hello world example created in the terminal and QtCreator IDE.","sidebar":"tinyormSidebar"},"building/migrations":{"id":"building/migrations","title":"Building: Migrations","description":"How to compile the TinyORM migrations (tom) C++ console application on Windows and Linux.","sidebar":"tinyormSidebar"},"building/tinyorm":{"id":"building/tinyorm","title":"Building: TinyORM","description":"How to compile the TinyORM C++ library on Windows and Linux.","sidebar":"tinyormSidebar"},"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.","sidebar":"tinyormSidebar"},"database/migrations":{"id":"database/migrations","title":"Database: Migrations","description":"Migrations are like version control for your database, allowing your team to define and share the application\'s database schema definition. Migrations use the Schema facade that provides database agnostic support for creating and manipulating tables across all of TinyORM\'s supported database systems.","sidebar":"tinyormSidebar"},"database/query-builder":{"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.","sidebar":"tinyormSidebar"},"database/seeding":{"id":"database/seeding","title":"Database: Seeding","description":"TinyORM includes the ability to seed your database with data using seed classes. The DatabaseSeeder class is considered as the root seeder. From this class, you may use the `call` method to run other seed classes, allowing you to control the seeding order.","sidebar":"tinyormSidebar"},"dependencies":{"id":"dependencies","title":"Dependencies","description":"Library dependencies are MySQL Connector/C 8, range-v3 >=0.11.0, tabulate and the Qt framework version used during development was 5.15.2 and >=6.2. The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16.","sidebar":"tinyormSidebar"},"features-summary":{"id":"features-summary","title":"Features Summary","description":"List that fastly summarizes all TinyORM features.","sidebar":"tinyormSidebar"},"README":{"id":"README","title":"Prologue","description":"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the QtCore and QtSql libraries. The code is written in the modern C++20 way and is heavily tested with 3366 unit and functional tests.","sidebar":"tinyormSidebar"},"sponsors":{"id":"sponsors","title":"Sponsors","description":"How to sponsor and support the TinyORM project.","sidebar":"tinyormSidebar"},"supported-compilers":{"id":"supported-compilers","title":"Supported Compilers","description":"Platform requirements, supported compilers and build systems for TinyORM C++ library.","sidebar":"tinyormSidebar"},"tinydrivers/getting-started":{"id":"tinydrivers/getting-started","title":"TinyDrivers: 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.","sidebar":"tinyormSidebar"},"tinyorm/casts":{"id":"tinyorm/casts","title":"TinyORM: Casting","description":"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a `datetime` string that is stored in your database to the `QDateTime` instance when it is accessed via your TinyORM model.","sidebar":"tinyormSidebar"},"tinyorm/collections":{"id":"tinyorm/collections","title":"TinyORM: Collections","description":"The ModelsCollection is specialized container which provides a fluent, convenient wrapper for working with vector of models. Is much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. All TinyORM methods that return more than one model result will return instances of the ModelsCollection class.","sidebar":"tinyormSidebar"},"tinyorm/getting-started":{"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.","sidebar":"tinyormSidebar"},"tinyorm/relationships":{"id":"tinyorm/relationships","title":"TinyORM: Relationships","description":"TinyORM relationships are defined as methods on your TinyORM model classes. Since relationships also serve as powerful query builders, defining relationships as methods provides powerful method chaining and querying capabilities.","sidebar":"tinyormSidebar"},"tinyorm/serialization":{"id":"tinyorm/serialization","title":"TinyORM: Serialization","description":"TinyORM models serialization allows you to serialize models and collection of models including all nested relations to JSON. It also supports converting to vectors or maps and allows controlling a custom date format during serialization.","sidebar":"tinyormSidebar"}}}')}}]); \ No newline at end of file diff --git a/assets/js/935f2afb.15ecbd85.js b/assets/js/935f2afb.15ecbd85.js deleted file mode 100644 index 88c6a16a6..000000000 --- a/assets/js/935f2afb.15ecbd85.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[53],{1109:e=>{e.exports=JSON.parse('{"pluginId":"default","version":"current","label":"Next","banner":null,"badge":false,"noIndex":false,"className":"docs-version-current","isLast":true,"docsSidebars":{"tinyormSidebar":[{"type":"link","label":"\ud83d\udd25 Prologue","href":"/","docId":"README"},{"type":"link","label":"\ud83d\udd27 Dependencies","href":"/dependencies","docId":"dependencies"},{"type":"link","label":"\ud83d\ude80 Supported Compilers","href":"/supported-compilers","docId":"supported-compilers"},{"type":"category","label":"\u2728 Database","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Getting Started","href":"/database/getting-started","docId":"database/getting-started"},{"type":"link","label":"Query Builder","href":"/database/query-builder","docId":"database/query-builder"},{"type":"link","label":"Migrations","href":"/database/migrations","docId":"database/migrations"},{"type":"link","label":"Seeding","href":"/database/seeding","docId":"database/seeding"}]},{"type":"category","label":"\ud83c\udf89 TinyORM","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Getting Started","href":"/tinyorm/getting-started","docId":"tinyorm/getting-started"},{"type":"link","label":"Relationships","href":"/tinyorm/relationships","docId":"tinyorm/relationships"},{"type":"link","label":"Collections","href":"/tinyorm/collections","docId":"tinyorm/collections"},{"type":"link","label":"Casts","href":"/tinyorm/casts","docId":"tinyorm/casts"},{"type":"link","label":"Serialization","href":"/tinyorm/serialization","docId":"tinyorm/serialization"}]},{"type":"category","label":"\ud83d\udea7 Building","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"TinyORM","href":"/building/tinyorm","docId":"building/tinyorm"},{"type":"link","label":"Hello world","href":"/building/hello-world","docId":"building/hello-world"},{"type":"link","label":"Migrations","href":"/building/migrations","docId":"building/migrations"}]},{"type":"link","label":"\ud83d\udcc4 Features Summary","href":"/features-summary","docId":"features-summary"},{"type":"link","label":"\u2764\ufe0f Sponsors","href":"/sponsors","docId":"sponsors"}]},"docs":{"building/hello-world":{"id":"building/hello-world","title":"Building: Hello world","description":"Hello world example created in the terminal and QtCreator IDE.","sidebar":"tinyormSidebar"},"building/migrations":{"id":"building/migrations","title":"Building: Migrations","description":"How to compile the TinyORM migrations (tom) C++ console application on Windows and Linux.","sidebar":"tinyormSidebar"},"building/tinyorm":{"id":"building/tinyorm","title":"Building: TinyORM","description":"How to compile the TinyORM C++ library on Windows and Linux.","sidebar":"tinyormSidebar"},"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.","sidebar":"tinyormSidebar"},"database/migrations":{"id":"database/migrations","title":"Database: Migrations","description":"Migrations are like version control for your database, allowing your team to define and share the application\'s database schema definition. Migrations use the Schema facade that provides database agnostic support for creating and manipulating tables across all of TinyORM\'s supported database systems.","sidebar":"tinyormSidebar"},"database/query-builder":{"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.","sidebar":"tinyormSidebar"},"database/seeding":{"id":"database/seeding","title":"Database: Seeding","description":"TinyORM includes the ability to seed your database with data using seed classes. The DatabaseSeeder class is considered as the root seeder. From this class, you may use the `call` method to run other seed classes, allowing you to control the seeding order.","sidebar":"tinyormSidebar"},"dependencies":{"id":"dependencies","title":"Dependencies","description":"Library dependencies are MySQL Connector/C 8, range-v3 >=0.11.0, tabulate and the Qt framework version used during development was 5.15.2 and >=6.2. The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16.","sidebar":"tinyormSidebar"},"features-summary":{"id":"features-summary","title":"Features Summary","description":"List that fastly summarizes all TinyORM features.","sidebar":"tinyormSidebar"},"README":{"id":"README","title":"Prologue","description":"TinyORM is a modern C++ ORM library that makes interacting with a database extremely simple. It depends on the QtCore and QtSql libraries. The code is written in the modern C++20 way and is heavily tested with 3269 unit and functional tests.","sidebar":"tinyormSidebar"},"sponsors":{"id":"sponsors","title":"Sponsors","description":"How to sponsor and support the TinyORM project.","sidebar":"tinyormSidebar"},"supported-compilers":{"id":"supported-compilers","title":"Supported Compilers","description":"Platform requirements, supported compilers and build systems for TinyORM C++ library.","sidebar":"tinyormSidebar"},"tinyorm/casts":{"id":"tinyorm/casts","title":"TinyORM: Casting","description":"Attribute casting allows you to transform TinyORM attribute values when you retrieve them on model instances. For example, you may want to convert a `datetime` string that is stored in your database to the `QDateTime` instance when it is accessed via your TinyORM model.","sidebar":"tinyormSidebar"},"tinyorm/collections":{"id":"tinyorm/collections","title":"TinyORM: Collections","description":"The ModelsCollection is specialized container which provides a fluent, convenient wrapper for working with vector of models. Is much more powerful than vectors and expose a variety of map / reduce operations that may be chained using an intuitive interface. All TinyORM methods that return more than one model result will return instances of the ModelsCollection class.","sidebar":"tinyormSidebar"},"tinyorm/getting-started":{"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.","sidebar":"tinyormSidebar"},"tinyorm/relationships":{"id":"tinyorm/relationships","title":"TinyORM: Relationships","description":"TinyORM relationships are defined as methods on your TinyORM model classes. Since relationships also serve as powerful query builders, defining relationships as methods provides powerful method chaining and querying capabilities.","sidebar":"tinyormSidebar"},"tinyorm/serialization":{"id":"tinyorm/serialization","title":"TinyORM: Serialization","description":"TinyORM models serialization allows you to serialize models and collection of models including all nested relations to JSON. It also supports converting to vectors or maps and allows controlling a custom date format during serialization.","sidebar":"tinyormSidebar"}}}')}}]); \ No newline at end of file diff --git a/assets/js/ba3d4959.86bd32f7.js b/assets/js/ba3d4959.86bd32f7.js new file mode 100644 index 000000000..78bba1537 --- /dev/null +++ b/assets/js/ba3d4959.86bd32f7.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[784],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>h});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),p=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},m=function(e){var t=p(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},c=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,s=e.parentName,m=l(e,["components","mdxType","originalType","parentName"]),u=p(n),c=r,h=u["".concat(s,".").concat(c)]||u[c]||d[c]||i;return n?a.createElement(h,o(o({ref:t},m),{},{components:n})):a.createElement(h,o({ref:t},m))}));function h(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,o=new Array(i);o[0]=c;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[u]="string"==typeof e?e:r,o[1]=l;for(var p=2;p{n.d(t,{Z:()=>o});var a=n(7294),r=n(6010);const i={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(i.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>v});var a=n(7462),r=n(7294),i=n(6010),o=n(2466),l=n(6550),s=n(1980),p=n(7392),m=n(12);function u(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function d(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??u(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function c(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,s._X)(i),(0,r.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(a.location.search);t.set(i,e),a.replace({...a.location,search:t.toString()})}),[i,a])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,i=d(e),[o,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!c({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:i}))),[s,p]=h({queryString:n,groupId:a}),[u,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,i]=(0,m.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:a}),f=(()=>{const e=s??u;return c({value:e,tabValues:i})?e:null})();(0,r.useLayoutEffect)((()=>{f&&l(f)}),[f]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!c({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);l(e),p(e),g(e)}),[p,g,i]),tabValues:i}}var f=n(2389);const k={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function b(e){let{className:t,block:n,selectedValue:l,selectValue:s,tabValues:p}=e;const m=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.o5)(),d=e=>{const t=e.currentTarget,n=m.indexOf(t),a=p[n].value;a!==l&&(u(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=m.indexOf(e.currentTarget)+1;t=m[n]??m[0];break}case"ArrowLeft":{const n=m.indexOf(e.currentTarget)-1;t=m[n]??m[m.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.Z)("tabs",{"tabs--block":n},t)},p.map((e=>{let{value:t,label:n,attributes:o}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:l===t?0:-1,"aria-selected":l===t,key:t,ref:e=>m.push(e),onKeyDown:c,onClick:d},o,{className:(0,i.Z)("tabs__item",k.tabItem,o?.className,{"tabs__item--active":l===t})}),n??t)})))}function y(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},i.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function S(e){const t=g(e);return r.createElement("div",{className:(0,i.Z)("tabs-container",k.tabList)},r.createElement(b,(0,a.Z)({},e,t)),r.createElement(y,(0,a.Z)({},e,t)))}function v(e){const t=(0,f.Z)();return r.createElement(S,(0,a.Z)({key:String(t)},e))}},2044:(e,t,n)=>{n.d(t,{$t:()=>u,Ae:()=>f,C:()=>h,DK:()=>k,Fo:()=>l,Fs:()=>r,IM:()=>g,IZ:()=>a,RS:()=>T,VE:()=>b,Wg:()=>S,_A:()=>p,al:()=>_,jk:()=>c,js:()=>s,of:()=>m,q5:()=>o,qb:()=>v,vk:()=>d,wU:()=>i,zg:()=>y});const a="shell",r="database",i="application",o="bash",l="pwsh",s="zsh",p="maria",m="mysql",u="postgres",d="sqlite",c="application",h="bash",g="pwsh",f="zsh",k="MariaDB",b="MySQL",y="PostgreSQL",S="SQLite",v="tinyorm.org",_="$HOME/Code/c/",T="$env:USERPROFILE\\Code\\c\\"},288:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>C,contentTitle:()=>_,default:()=>E,frontMatter:()=>v,metadata:()=>T,toc:()=>N});var a=n(7462),r=n(7294),i=n(3905),o=n(5162),l=n(4866);let s=null,p=null;function m(){const[e,t]=(0,r.useState)(!1),[n,a]=(0,r.useState)(!1);return(0,r.useEffect)((()=>(u(),()=>{u()})),[]),r.createElement("form",null,r.createElement("div",{className:"tinyorm-configuration-row"},r.createElement("label",{htmlFor:"tinyorm-toggle-full"},"Full configuration"),r.createElement("input",{id:"tinyorm-toggle-full",type:"checkbox",checked:e,onChange:()=>t(d),title:"Show full configuration example"})),r.createElement("div",{className:"tinyorm-configuration-row"},r.createElement("label",{htmlFor:"tinyorm-toggle-prefix"},"Prefix environment"),r.createElement("input",{id:"tinyorm-toggle-prefix",type:"checkbox",checked:n,onChange:()=>a(y),title:"Prefix all environment variables by the database type"})))}function u(){s=null,p=null}function d(e){const t=s||(s=document.getElementById("tinyorm-configuration")?.querySelectorAll(".tabs-container")),n=!e;if(!t)return e;if(2!==t.length)throw new Error(`Wrong number of .tabs-container (!== 2) found in the toggle configuration feature, found ${t.length}.`);return n?(t[0].style.display="none",t[1].style.display="block"):(t[0].style.display="block",t[1].style.display="none"),!e}const c='"DB_',h="MARIA",g="MYSQL",f="PGSQL",k="SQLITE",b=[g,f,k,h,g,f,k,h];function y(e){const t=function(){if(p)return p;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 p=new Array(e.length),e.forEach(((e,t)=>{p[t]=Array.from(e.querySelectorAll(".token.string")).filter((e=>e?.textContent.startsWith(c)))})),p}(),n=!e;return t?(t.forEach(((e,t)=>{e.forEach((e=>{const a=e.textContent,r=`${c}${b[t]}_`;if(n)e.textContent=`${r}${a.substring(4)}`;else{if(!a.startsWith(r))throw new Error(`Token doesn't start with the '${r}' prefix.`);e.textContent=`${c}${a.substring(r.length)}`}}))})),!e):e}var S=n(2044);const v={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"]},_="Database: Getting Started",T={unversionedId:"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,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/database/getting-started.mdx",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"}},C={},N=[{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}],Q={toc:N},D="wrapper";function E(e){let{components:t,...n}=e;return(0,i.kt)(D,(0,a.Z)({},Q,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"database-getting-started"},"Database: Getting Started"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#configuration"},"Configuration")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#ssl-connections"},"SSL Connections")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#running-sql-queries"},"Running SQL Queries"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#using-multiple-database-connections"},"Using Multiple Database Connections")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#database-transactions"},"Database Transactions")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#multi-threading-support"},"Multi-threading support"))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,"Almost every modern application interacts with a database. TinyORM makes interacting with a database extremely simple using raw SQL, a ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"fluent query builder"),", and the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/getting-started"},"TinyORM"),". Currently, TinyORM provides first-party support for four databases:"),(0,i.kt)("div",{id:"databases-supported-versions"},(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"MySQL ",(0,i.kt)("inlineCode",{parentName:"li"},">=5.7")," (",(0,i.kt)("a",{parentName:"li",href:"https://en.wikipedia.org/wiki/MySQL#Release_history"},"Version Policy"),")"),(0,i.kt)("li",{parentName:"ul"},"MariaDB ",(0,i.kt)("inlineCode",{parentName:"li"},">=10.3")," (",(0,i.kt)("a",{parentName:"li",href:"https://mariadb.org/about/#maintenance-policy"},"Version Policy"),")"),(0,i.kt)("li",{parentName:"ul"},"PostgreSQL ",(0,i.kt)("inlineCode",{parentName:"li"},">=11")," (",(0,i.kt)("a",{parentName:"li",href:"https://www.postgresql.org/support/versioning/"},"Version Policy"),")"),(0,i.kt)("li",{parentName:"ul"},"SQLite ",(0,i.kt)("inlineCode",{parentName:"li"},">=3.8.8"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},"native rename column ",(0,i.kt)("inlineCode",{parentName:"li"},">=3.25.0")," (",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/lang_altertable.html#alter_table_rename_column"},"docs")," , ",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/releaselog/3_25_0.html"},"release notes"),")"),(0,i.kt)("li",{parentName:"ul"},"native drop column ",(0,i.kt)("inlineCode",{parentName:"li"},">=3.35.0")," (",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/lang_altertable.html#alter_table_drop_column"},"docs"),", ",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/releaselog/3_35_0.html"},"release notes"),")"),(0,i.kt)("li",{parentName:"ul"},"generated columns ",(0,i.kt)("inlineCode",{parentName:"li"},">=3.31.0")," (",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/gencol.html"},"docs"),", ",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/releaselog/3_31_0.html"},"release notes"),")"))))),(0,i.kt)("p",null,"TinyORM internally uses ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql")," module, you can look for ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/sql-driver.html#supported-databases"},"supported databases"),"."),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"TinyORM's code is ready and designed to simply add support for the SQL Server.")),(0,i.kt)("h3",{id:"configuration"},"Configuration"),(0,i.kt)("p",null,"You can create and configure a new database connection using the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("div",{id:"tinyorm-configuration"},(0,i.kt)(m,{mdxType:"ConfigurationSettings"}),(0,i.kt)(l.Z,{className:"tinyorm-configuration-basic",groupId:S.Fs,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.of,label:S.VE,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.$t,label:S.zg,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.vk,label:S.Wg,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S._A,label:S.DK,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(l.Z,{className:"tinyorm-configuration-full",groupId:S.Fs,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.of,label:S.VE,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.$t,label:S.zg,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.vk,label:S.Wg,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S._A,label:S.DK,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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'))))),(0,i.kt)("p",null,"The first argument is configuration hash which is of type ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariantHash")," and the second argument specifies the name of the ",(0,i.kt)("em",{parentName:"p"},"connection"),", this connection will also be a ",(0,i.kt)("em",{parentName:"p"},"default connection"),". You can configure multiple database connections at once and choose the needed one before executing SQL query, section ",(0,i.kt)("a",{parentName:"p",href:"#using-multiple-database-connections"},"Using Multiple Database Connections")," describes how to create and use multiple database connections."),(0,i.kt)("p",null,"You may also configure connection options by ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," key as ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariantHash")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"QString"),", you can pass any ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qsqldatabase.html#setConnectOptions"},"connection options")," supported by ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlDatabase"),"."),(0,i.kt)("p",null,"You can also configure ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.3/en/innodb-transaction-isolation-levels.html"},"Transaction Isolation Levels")," for MySQL connection with the ",(0,i.kt)("inlineCode",{parentName:"p"},"isolation_level")," configuration option."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/src/orm/connectors/mysqlconnector.cpp#L154"},"session variables")," will be set if strict mode is enabled and whether to use an ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/src/orm/query/grammars/mysqlgrammar.cpp#L36"},"alias")," during the ",(0,i.kt)("inlineCode",{parentName:"p"},"upsert")," method call."),(0,i.kt)("p",null,"Breaking values are as follows; use an upsert alias on the MySQL >=8.0.19 and remove the ",(0,i.kt)("inlineCode",{parentName:"p"},"NO_AUTO_CREATE_USER")," sql mode on the MySQL >=8.0.11 if the strict mode is enabled."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"A database connection is resolved lazily, which means that the connection configuration is only saved after the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB::create")," method call. The connection will be resolved after you run some query or you can create it using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB::connection")," method.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can also use predefined string constants to avoid unnecessary ",(0,i.kt)("inlineCode",{parentName:"p"},"QString")," instantiations, as used in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations ",(0,i.kt)("a",{parentName:"p",href:"/building/migrations#string-constants-example"},"example"),".")),(0,i.kt)("h4",{id:"sqlite-configuration"},"SQLite Configuration"),(0,i.kt)("p",null,"SQLite databases are contained within a single file on your filesystem. You can create a new SQLite database using the ",(0,i.kt)("inlineCode",{parentName:"p"},"touch")," command in your terminal: ",(0,i.kt)("inlineCode",{parentName:"p"},"touch database.sqlite3"),". After the database has been created, you may configure SQLite database connection:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"database")," configuration value is the absolute path to the database. To enable foreign key constraints for SQLite connections, you should set the ",(0,i.kt)("inlineCode",{parentName:"p"},"foreign_key_constraints")," configuration value to ",(0,i.kt)("inlineCode",{parentName:"p"},"true"),", if this configuration value is not set, then the default of the SQLite driver will be used (currently the default is ",(0,i.kt)("strong",{parentName:"p"},"disabled"),")."),(0,i.kt)("p",null,"If the ",(0,i.kt)("inlineCode",{parentName:"p"},"check_database_exists")," configuration value is set to the ",(0,i.kt)("inlineCode",{parentName:"p"},"true")," value, then the database connection throws an ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::InvalidArgumentError")," exception, when the SQLite database file doesn't exist. If it is set to the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"true"),"."),(0,i.kt)("h3",{id:"ssl-connections"},"SSL Connections"),(0,i.kt)("p",null,"SSL connections are supported for the ",(0,i.kt)("inlineCode",{parentName:"p"},"MySQL")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"PostgreSQL")," databases. They can be set using the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," configuration option."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"This feature is heavily dependent on the underlying ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlDatabase")," module. What means that you can pass the same ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qsqldatabase.html#setConnectOptions"},"connection options")," to the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," that the ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlDatabase")," accepts.")),(0,i.kt)("h5",{id:"mysql"},"MySQL"),(0,i.kt)("p",null,"You have to pass the ",(0,i.kt)("inlineCode",{parentName:"p"},"SSL_CA"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"SSL_CERT"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"SSL_KEY"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"MYSQL_OPT_SSL_MODE")," options."),(0,i.kt)(l.Z,{groupId:S.IZ,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.Fo,label:S.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.q5,label:S.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')))),(0,i.kt)("p",null,"You may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"ConfigUtils::mysqlSslOptions()")," or the ",(0,i.kt)("inlineCode",{parentName:"p"},"ConfigUtils::insertMySqlSslOptions()")," methods to insert these options for you and define them using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_MYSQL_SSL_CA"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_MYSQL_SSL_CERT"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_MYSQL_SSL_KEY"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_MYSQL_SSL_MODE")," environment variables."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"You can define these SSL-related options in the top-level configuration, they will be copied to the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," option hash during configuration parsing. The top-level configuration takes precedence and overwrites the options in the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," hash."),(0,i.kt)(l.Z,{groupId:S.IZ,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.Fo,label:S.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.q5,label:S.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')))),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can take a look at the GitHub actions how the ",(0,i.kt)("inlineCode",{parentName:"p"},"MySQL")," certificates are generated in the CI pipeline for ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/msvc2022-qt6.yml"},"Windows")," and ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/linux-qt6.yml"},"Linux"),".")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can also pass the ",(0,i.kt)("inlineCode",{parentName:"p"},"QString")," to the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," configuration separated by the ",(0,i.kt)("inlineCode",{parentName:"p"},";")," semicolon character and use the ",(0,i.kt)("inlineCode",{parentName:"p"},"=")," to assign values.")),(0,i.kt)("h5",{id:"postgresql"},"PostgreSQL"),(0,i.kt)("p",null,"You have to pass the ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS"},(0,i.kt)("inlineCode",{parentName:"a"},"sslmode"))," or the deprecated ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-REQUIRESSL"},(0,i.kt)("inlineCode",{parentName:"a"},"requiressl"))," options."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"And place your ",(0,i.kt)("strong",{parentName:"p"},"client")," certificates to the ",(0,i.kt)("inlineCode",{parentName:"p"},"~/.postgres/")," on ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-FILE-USAGE"},"Linux")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"$env:APPDATA/postgres/")," on Windows. Everything is described in the PostgreSQL's ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-ssl.html"},"libpq client")," and ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/15/ssl-tcp.html#SSL-FILE-USAGE"},"server")," documentation."),(0,i.kt)("p",null,"If you want to keep your ",(0,i.kt)("strong",{parentName:"p"},"client")," certificates in your own location, you can set the ",(0,i.kt)("inlineCode",{parentName:"p"},"sslcert"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"sslkey"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"sslrootcert")," options."),(0,i.kt)(l.Z,{groupId:S.IZ,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.Fo,label:S.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.q5,label:S.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')))),(0,i.kt)("p",null,"You can define these SSL-related options in the top-level configuration, they will be copied to the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," option hash during a configuration parsing. The top-level configuration takes precedence and overwrites the options in the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," hash."),(0,i.kt)(l.Z,{groupId:S.IZ,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.Fo,label:S.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.q5,label:S.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')))),(0,i.kt)("p",null,"You may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"ConfigUtils::postgresSslOptions()")," or the ",(0,i.kt)("inlineCode",{parentName:"p"},"ConfigUtils::insertPostgresSslOptions()")," methods to insert the ",(0,i.kt)("inlineCode",{parentName:"p"},"sslmode"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"sslcert"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"sslkey"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"sslrootcert")," options for you and define them using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_PGSQL_SSLMODE"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_PGSQL_SSLCERT"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_PGSQL_SSLKEY"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_PGSQL_SSLROOTCERT")," environment variable."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The PostgreSQL's libpq client library provides the ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.13.1.1"},(0,i.kt)("inlineCode",{parentName:"a"},"PGSSLMODE")),", ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.16.1.1"},(0,i.kt)("inlineCode",{parentName:"a"},"PGSSLCERT")),", ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.17.1.1"},(0,i.kt)("inlineCode",{parentName:"a"},"PGSSLKEY")),", and ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.18.1.1"},(0,i.kt)("inlineCode",{parentName:"a"},"PGSSLROOTCERT"))," environment variables, so you don't have to use TinyORM's ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," configuration and may use these environment variables instead.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can take a look at the GitHub actions how the ",(0,i.kt)("inlineCode",{parentName:"p"},"PostgreSQL")," certificates are generated in the CI pipeline for ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/msvc2022-qt6.yml"},"Windows")," and ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/linux-qt6.yml"},"Linux"),".")),(0,i.kt)("h2",{id:"running-sql-queries"},"Running SQL Queries"),(0,i.kt)("p",null,"Once you have configured your database connection, you may run queries using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade. The ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade provides methods for each type of query: ",(0,i.kt)("inlineCode",{parentName:"p"},"select"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"update"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"insert"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"delete"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"statement"),"."),(0,i.kt)("h4",{id:"running-a-select-query"},"Running A Select Query"),(0,i.kt)("p",null,"To run a basic SELECT query, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"select")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto users = DB::select("select * from users where active = ?", {1});\n')),(0,i.kt)("p",null,"The first argument passed to the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"where")," clause constraints. Parameter binding provides protection against SQL injection."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"select")," method returns a ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," containing the results of the query, where each result can be accessed by ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery::next")," method. Look into the ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery"),' documentation on how to obtain results from the "query". You may access each column\'s value by ',(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery::value")," method. The first ",(0,i.kt)("inlineCode",{parentName:"p"},"bool")," return value is the value returned from ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery::exec")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\n#include \n\nauto users = DB::select("select * from users");\n\nwhile(users.next())\n qDebug() << users.value("name").toString();\n')),(0,i.kt)("h4",{id:"selecting-scalar-values"},"Selecting Scalar Values"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"scalar")," shortcut method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"running-an-insert-statement"},"Running An Insert Statement"),(0,i.kt)("p",null,"To execute an ",(0,i.kt)("inlineCode",{parentName:"p"},"insert")," statement, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"insert")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade. Like ",(0,i.kt)("inlineCode",{parentName:"p"},"select"),", this method accepts the SQL query as its first argument and bindings as its second argument and returns ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nDB::insert("insert into users (id, name) values (?, ?)", {1, "Marc"});\n')),(0,i.kt)("h4",{id:"running-an-update-statement"},"Running An Update Statement"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"update")," method should be used to update existing records in the database. The number of rows affected by the statement and ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," is returned by the method as ",(0,i.kt)("inlineCode",{parentName:"p"},"std::tuple"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"running-a-delete-statement"},"Running A Delete Statement"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"remove")," method should be used to delete records from the database. Like ",(0,i.kt)("inlineCode",{parentName:"p"},"update"),", the number of affected rows and ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," will be returned by the method as ",(0,i.kt)("inlineCode",{parentName:"p"},"std::tuple"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nauto [affected, query] = DB::remove("delete from users");\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("inlineCode",{parentName:"p"},"delete")," can not be used as the method name because it is the reserved word.")),(0,i.kt)("h4",{id:"running-a-general-statement"},"Running A General Statement"),(0,i.kt)("p",null,"Some database statements do not return any value. For these types of operations, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"statement")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'DB::statement("drop table users");\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("inlineCode",{parentName:"p"},"DB::statement")," method should be used for ",(0,i.kt)("a",{parentName:"p",href:"https://en.wikipedia.org/wiki/Data_definition_language"},"DDL"),' queries, don\'t use it for "select" queries because it internally calls ',(0,i.kt)("inlineCode",{parentName:"p"},"recordsHaveBeenModified")," method.")),(0,i.kt)("h4",{id:"running-an-unprepared-statement"},"Running An Unprepared Statement"),(0,i.kt)("p",null,"Sometimes you may want to execute an SQL statement without binding any values. You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade's ",(0,i.kt)("inlineCode",{parentName:"p"},"unprepared")," method to accomplish this:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"DB::unprepared(\"update users set votes = 100 where name = 'Dries'\");\n")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"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.")),(0,i.kt)("h4",{id:"implicit-commits"},"Implicit Commits"),(0,i.kt)("p",null,"When using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade's ",(0,i.kt)("inlineCode",{parentName:"p"},"statement")," methods within transactions, you must be careful to avoid statements that cause ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.3/en/implicit-commit.html"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'DB::statement("create table users (name varchar(255) null)");\n')),(0,i.kt)("p",null,"Please refer to the MySQL manual for ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.3/en/implicit-commit.html"},"a list of all statements")," that trigger implicit commits."),(0,i.kt)("h3",{id:"using-multiple-database-connections"},"Using Multiple Database Connections"),(0,i.kt)("p",null,"You can configure multiple database connections at once during ",(0,i.kt)("inlineCode",{parentName:"p"},"DatabaseManager")," instantiation using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB::create")," overload, where the first argument is a hash of multiple connections and is of type ",(0,i.kt)("inlineCode",{parentName:"p"},"QHash")," and the second argument is the name of the default connection:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"If your application needs to use multiple connections, you may access each connection via the ",(0,i.kt)("inlineCode",{parentName:"p"},"connection")," method provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade. The connection name passed to the ",(0,i.kt)("inlineCode",{parentName:"p"},"connection")," method should correspond to one of the connections key listed in your configuration:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nauto query = DB::connection("mysql_test").select(...);\n')),(0,i.kt)("p",null,"You may access the raw underlying ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," instance of a connection using the ",(0,i.kt)("inlineCode",{parentName:"p"},"getQtQuery")," method on a connection instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"auto query = DB::connection().getQtQuery();\n")),(0,i.kt)("p",null,"Or you can use the shortcut method ",(0,i.kt)("inlineCode",{parentName:"p"},"qtQuery")," provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"auto query = DB::qtQuery();\n")),(0,i.kt)("h2",{id:"database-transactions"},"Database Transactions"),(0,i.kt)("h4",{id:"manually-using-transactions"},"Manually Using Transactions"),(0,i.kt)("p",null,"If you would like to begin a transaction manually and have complete control over rollbacks and commits, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"beginTransaction")," method provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#include \n\nDB::beginTransaction();\n")),(0,i.kt)("p",null,"You can rollback the transaction via the ",(0,i.kt)("inlineCode",{parentName:"p"},"rollBack")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"DB::rollBack();\n")),(0,i.kt)("p",null,"Lastly, you can commit a transaction via the ",(0,i.kt)("inlineCode",{parentName:"p"},"commit")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"DB::commit();\n")),(0,i.kt)("p",null,"All transaction methods accept a connection name as the optional argument:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'DB::beginTransaction("mysql_test");\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade's transaction methods control the transactions for both the ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder")," and ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/getting-started"},"TinyORM"),".")),(0,i.kt)("h2",{id:"multi-threading-support"},"Multi-threading support"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," supports multi-threading for the ",(0,i.kt)("inlineCode",{parentName:"p"},"MSVC")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"GCC")," on Linux compilers. Multi-threading is disabled for the ",(0,i.kt)("inlineCode",{parentName:"p"},"Clang <14.0.3")," compiler on MSYS2, ",(0,i.kt)("inlineCode",{parentName:"p"},"Clang <14.0.4")," on Linux and for the ",(0,i.kt)("inlineCode",{parentName:"p"},"GCC")," compiler on MSYS2. The reason are bugs in the ",(0,i.kt)("inlineCode",{parentName:"p"},"TLS")," wrapper that is generated by the ",(0,i.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/keyword/thread_local"},(0,i.kt)("inlineCode",{parentName:"a"},"thread_local"))," keyword."),(0,i.kt)("p",null,"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."),(0,i.kt)("p",null,"In addition, the third party libraries used by the ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlDrivers")," can impose further restrictions on using the SQL Module in a multithreaded program."),(0,i.kt)("p",null,"In short, if you create a ",(0,i.kt)("inlineCode",{parentName:"p"},"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."),(0,i.kt)("p",null,"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."),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#tables"},(0,i.kt)("inlineCode",{parentName:"a"},"schema builder"))," and ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},(0,i.kt)("inlineCode",{parentName:"a"},"migrations"))," don't support multi-threading.")))}E.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/ba3d4959.a82789dd.js b/assets/js/ba3d4959.a82789dd.js deleted file mode 100644 index ef120e262..000000000 --- a/assets/js/ba3d4959.a82789dd.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[784],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>h});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),p=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},u=function(e){var t=p(e.components);return a.createElement(s.Provider,{value:t},e.children)},m="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},c=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,s=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),m=p(n),c=r,h=m["".concat(s,".").concat(c)]||m[c]||d[c]||i;return n?a.createElement(h,o(o({ref:t},u),{},{components:n})):a.createElement(h,o({ref:t},u))}));function h(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,o=new Array(i);o[0]=c;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[m]="string"==typeof e?e:r,o[1]=l;for(var p=2;p{n.d(t,{Z:()=>o});var a=n(7294),r=n(6010);const i={tabItem:"tabItem_Ymn6"};function o(e){let{children:t,hidden:n,className:o}=e;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(i.tabItem,o),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>v});var a=n(7462),r=n(7294),i=n(6010),o=n(2466),l=n(6550),s=n(1980),p=n(7392),u=n(12);function m(e){return function(e){return r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}function d(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??m(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function c(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),i=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,s._X)(i),(0,r.useCallback)((e=>{if(!i)return;const t=new URLSearchParams(a.location.search);t.set(i,e),a.replace({...a.location,search:t.toString()})}),[i,a])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,i=d(e),[o,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!c({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:i}))),[s,p]=h({queryString:n,groupId:a}),[m,g]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,i]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:a}),f=(()=>{const e=s??m;return c({value:e,tabValues:i})?e:null})();(0,r.useLayoutEffect)((()=>{f&&l(f)}),[f]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!c({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);l(e),p(e),g(e)}),[p,g,i]),tabValues:i}}var f=n(2389);const k={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function b(e){let{className:t,block:n,selectedValue:l,selectValue:s,tabValues:p}=e;const u=[],{blockElementScrollPositionUntilNextRender:m}=(0,o.o5)(),d=e=>{const t=e.currentTarget,n=u.indexOf(t),a=p[n].value;a!==l&&(m(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.Z)("tabs",{"tabs--block":n},t)},p.map((e=>{let{value:t,label:n,attributes:o}=e;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:l===t?0:-1,"aria-selected":l===t,key:t,ref:e=>u.push(e),onKeyDown:c,onClick:d},o,{className:(0,i.Z)("tabs__item",k.tabItem,o?.className,{"tabs__item--active":l===t})}),n??t)})))}function y(e){let{lazy:t,children:n,selectedValue:a}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=i.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},i.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function S(e){const t=g(e);return r.createElement("div",{className:(0,i.Z)("tabs-container",k.tabList)},r.createElement(b,(0,a.Z)({},e,t)),r.createElement(y,(0,a.Z)({},e,t)))}function v(e){const t=(0,f.Z)();return r.createElement(S,(0,a.Z)({key:String(t)},e))}},2044:(e,t,n)=>{n.d(t,{$t:()=>m,Ae:()=>f,C:()=>h,DK:()=>k,Fo:()=>l,Fs:()=>r,IM:()=>g,IZ:()=>a,RS:()=>_,VE:()=>b,Wg:()=>S,_A:()=>p,al:()=>T,jk:()=>c,js:()=>s,of:()=>u,q5:()=>o,qb:()=>v,vk:()=>d,wU:()=>i,zg:()=>y});const a="shell",r="database",i="application",o="bash",l="pwsh",s="zsh",p="maria",u="mysql",m="postgres",d="sqlite",c="application",h="bash",g="pwsh",f="zsh",k="MariaDB",b="MySQL",y="PostgreSQL",S="SQLite",v="tinyorm.org",T="$HOME/Code/c/",_="$env:USERPROFILE\\Code\\c\\"},288:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>C,contentTitle:()=>T,default:()=>E,frontMatter:()=>v,metadata:()=>_,toc:()=>N});var a=n(7462),r=n(7294),i=n(3905),o=n(5162),l=n(4866);let s=null,p=null;function u(){const[e,t]=(0,r.useState)(!1),[n,a]=(0,r.useState)(!1);return(0,r.useEffect)((()=>(m(),()=>{m()})),[]),r.createElement("form",null,r.createElement("div",{className:"tinyorm-configuration-row"},r.createElement("label",{htmlFor:"tinyorm-toggle-full"},"Full configuration"),r.createElement("input",{id:"tinyorm-toggle-full",type:"checkbox",checked:e,onChange:()=>t(d),title:"Show full configuration example"})),r.createElement("div",{className:"tinyorm-configuration-row"},r.createElement("label",{htmlFor:"tinyorm-toggle-prefix"},"Prefix environment"),r.createElement("input",{id:"tinyorm-toggle-prefix",type:"checkbox",checked:n,onChange:()=>a(y),title:"Prefix all environment variables by the database type"})))}function m(){s=null,p=null}function d(e){const t=s||(s=document.getElementById("tinyorm-configuration")?.querySelectorAll(".tabs-container")),n=!e;if(!t)return e;if(2!==t.length)throw new Error(`Wrong number of .tabs-container (!== 2) found in the toggle configuration feature, found ${t.length}.`);return n?(t[0].style.display="none",t[1].style.display="block"):(t[0].style.display="block",t[1].style.display="none"),!e}const c='"DB_',h="MARIA",g="MYSQL",f="PGSQL",k="SQLITE",b=[g,f,k,h,g,f,k,h];function y(e){const t=function(){if(p)return p;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 p=new Array(e.length),e.forEach(((e,t)=>{p[t]=Array.from(e.querySelectorAll(".token.string")).filter((e=>e?.textContent.startsWith(c)))})),p}(),n=!e;return t?(t.forEach(((e,t)=>{e.forEach((e=>{const a=e.textContent,r=`${c}${b[t]}_`;if(n)e.textContent=`${r}${a.substring(4)}`;else{if(!a.startsWith(r))throw new Error(`Token doesn't start with the '${r}' prefix.`);e.textContent=`${c}${a.substring(r.length)}`}}))})),!e):e}var S=n(2044);const v={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"]},T="Database: Getting Started",_={unversionedId:"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,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/database/getting-started.mdx",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"}},C={},N=[{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}],Q={toc:N},D="wrapper";function E(e){let{components:t,...n}=e;return(0,i.kt)(D,(0,a.Z)({},Q,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"database-getting-started"},"Database: Getting Started"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#configuration"},"Configuration")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#ssl-connections"},"SSL Connections")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#running-sql-queries"},"Running SQL Queries"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#using-multiple-database-connections"},"Using Multiple Database Connections")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#database-transactions"},"Database Transactions")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#multi-threading-support"},"Multi-threading support"))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,"Almost every modern application interacts with a database. TinyORM makes interacting with a database extremely simple using raw SQL, a ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"fluent query builder"),", and the ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/getting-started"},"TinyORM"),". Currently, TinyORM provides first-party support for four databases:"),(0,i.kt)("div",{id:"databases-supported-versions"},(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"MySQL ",(0,i.kt)("inlineCode",{parentName:"li"},">=5.7")," (",(0,i.kt)("a",{parentName:"li",href:"https://en.wikipedia.org/wiki/MySQL#Release_history"},"Version Policy"),")"),(0,i.kt)("li",{parentName:"ul"},"MariaDB ",(0,i.kt)("inlineCode",{parentName:"li"},">=10.3")," (",(0,i.kt)("a",{parentName:"li",href:"https://mariadb.org/about/#maintenance-policy"},"Version Policy"),")"),(0,i.kt)("li",{parentName:"ul"},"PostgreSQL ",(0,i.kt)("inlineCode",{parentName:"li"},">=11")," (",(0,i.kt)("a",{parentName:"li",href:"https://www.postgresql.org/support/versioning/"},"Version Policy"),")"),(0,i.kt)("li",{parentName:"ul"},"SQLite ",(0,i.kt)("inlineCode",{parentName:"li"},">=3.8.8"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},"native rename column ",(0,i.kt)("inlineCode",{parentName:"li"},">=3.25.0")," (",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/lang_altertable.html#alter_table_rename_column"},"docs")," , ",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/releaselog/3_25_0.html"},"release notes"),")"),(0,i.kt)("li",{parentName:"ul"},"native drop column ",(0,i.kt)("inlineCode",{parentName:"li"},">=3.35.0")," (",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/lang_altertable.html#alter_table_drop_column"},"docs"),", ",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/releaselog/3_35_0.html"},"release notes"),")"),(0,i.kt)("li",{parentName:"ul"},"generated columns ",(0,i.kt)("inlineCode",{parentName:"li"},">=3.31.0")," (",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/gencol.html"},"docs"),", ",(0,i.kt)("a",{parentName:"li",href:"https://www.sqlite.org/releaselog/3_31_0.html"},"release notes"),")"))))),(0,i.kt)("p",null,"TinyORM internally uses ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql")," module, you can look for ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/sql-driver.html#supported-databases"},"supported databases"),"."),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},"TinyORM's code is ready and designed to simply add support for the SQL Server.")),(0,i.kt)("h3",{id:"configuration"},"Configuration"),(0,i.kt)("p",null,"You can create and configure a new database connection using the ",(0,i.kt)("inlineCode",{parentName:"p"},"create")," method provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("div",{id:"tinyorm-configuration"},(0,i.kt)(u,{mdxType:"ConfigurationSettings"}),(0,i.kt)(l.Z,{className:"tinyorm-configuration-basic",groupId:S.Fs,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.of,label:S.VE,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.$t,label:S.zg,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.vk,label:S.Wg,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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 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.kt)(o.Z,{value:S._A,label:S.DK,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(l.Z,{className:"tinyorm-configuration-full",groupId:S.Fs,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.of,label:S.VE,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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 // 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.kt)(o.Z,{value:S.$t,label:S.zg,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.vk,label:S.Wg,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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 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.kt)(o.Z,{value:S._A,label:S.DK,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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'))))),(0,i.kt)("p",null,"The first argument is configuration hash which is of type ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariantHash")," and the second argument specifies the name of the ",(0,i.kt)("em",{parentName:"p"},"connection"),", this connection will also be a ",(0,i.kt)("em",{parentName:"p"},"default connection"),". You can configure multiple database connections at once and choose the needed one before executing SQL query, section ",(0,i.kt)("a",{parentName:"p",href:"#using-multiple-database-connections"},"Using Multiple Database Connections")," describes how to create and use multiple database connections."),(0,i.kt)("p",null,"You may also configure connection options by ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," key as ",(0,i.kt)("inlineCode",{parentName:"p"},"QVariantHash")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"QString"),", you can pass any ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qsqldatabase.html#setConnectOptions"},"connection options")," supported by ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlDatabase"),"."),(0,i.kt)("p",null,"You can also configure ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.1/en/innodb-transaction-isolation-levels.html"},"Transaction Isolation Levels")," for MySQL connection with the ",(0,i.kt)("inlineCode",{parentName:"p"},"isolation_level")," configuration option."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/src/orm/connectors/mysqlconnector.cpp#L154"},"session variables")," will be set if strict mode is enabled and whether to use an ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/src/orm/query/grammars/mysqlgrammar.cpp#L36"},"alias")," during the ",(0,i.kt)("inlineCode",{parentName:"p"},"upsert")," method call."),(0,i.kt)("p",null,"Breaking values are as follows; use an upsert alias on the MySQL >=8.0.19 and remove the ",(0,i.kt)("inlineCode",{parentName:"p"},"NO_AUTO_CREATE_USER")," sql mode on the MySQL >=8.0.11 if the strict mode is enabled."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"A database connection is resolved lazily, which means that the connection configuration is only saved after the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB::create")," method call. The connection will be resolved after you run some query or you can create it using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB::connection")," method.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can also use predefined string constants to avoid unnecessary ",(0,i.kt)("inlineCode",{parentName:"p"},"QString")," instantiations, as used in the ",(0,i.kt)("inlineCode",{parentName:"p"},"tom")," migrations ",(0,i.kt)("a",{parentName:"p",href:"/building/migrations#string-constants-example"},"example"),".")),(0,i.kt)("h4",{id:"sqlite-configuration"},"SQLite Configuration"),(0,i.kt)("p",null,"SQLite databases are contained within a single file on your filesystem. You can create a new SQLite database using the ",(0,i.kt)("inlineCode",{parentName:"p"},"touch")," command in your terminal: ",(0,i.kt)("inlineCode",{parentName:"p"},"touch database.sqlite3"),". After the database has been created, you may configure SQLite database connection:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"database")," configuration value is the absolute path to the database. To enable foreign key constraints for SQLite connections, you should set the ",(0,i.kt)("inlineCode",{parentName:"p"},"foreign_key_constraints")," configuration value to ",(0,i.kt)("inlineCode",{parentName:"p"},"true"),", if this configuration value is not set, then the default of the SQLite driver will be used (currently the default is ",(0,i.kt)("strong",{parentName:"p"},"disabled"),")."),(0,i.kt)("p",null,"If the ",(0,i.kt)("inlineCode",{parentName:"p"},"check_database_exists")," configuration value is set to the ",(0,i.kt)("inlineCode",{parentName:"p"},"true")," value, then the database connection throws an ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::InvalidArgumentError")," exception, when the SQLite database file doesn't exist. If it is set to the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"true"),"."),(0,i.kt)("h3",{id:"ssl-connections"},"SSL Connections"),(0,i.kt)("p",null,"SSL connections are supported for the ",(0,i.kt)("inlineCode",{parentName:"p"},"MySQL")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"PostgreSQL")," databases. They can be set using the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," configuration option."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"This feature is heavily dependent on the underlying ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlDatabase")," module. What means that you can pass the same ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qsqldatabase.html#setConnectOptions"},"connection options")," to the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," that the ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlDatabase")," accepts.")),(0,i.kt)("h5",{id:"mysql"},"MySQL"),(0,i.kt)("p",null,"You have to pass the ",(0,i.kt)("inlineCode",{parentName:"p"},"SSL_CA"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"SSL_CERT"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"SSL_KEY")," options."),(0,i.kt)(l.Z,{groupId:S.IZ,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.Fo,label:S.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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 // highlight-end\n});\n'))),(0,i.kt)(o.Z,{value:S.q5,label:S.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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 // highlight-end\n});\n')))),(0,i.kt)("p",null,"You may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"ConfigUtils::mysqlSslOptions()")," or the ",(0,i.kt)("inlineCode",{parentName:"p"},"ConfigUtils::insertMySqlSslOptions()")," methods to insert these options for you and define them using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_MYSQL_SSL_CA"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_MYSQL_SSL_CERT"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_MYSQL_SSL_KEY")," environment variables."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"You can define these SSL-related options in the top-level configuration, they will be copied to the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," option hash during a configuration parsing. The top-level configuration takes precedence and overwrites the options in the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," hash."),(0,i.kt)(l.Z,{groupId:S.IZ,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.Fo,label:S.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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 // highlight-end\n});\n'))),(0,i.kt)(o.Z,{value:S.q5,label:S.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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 // highlight-end\n});\n')))),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can take a look at the GitHub actions how the ",(0,i.kt)("inlineCode",{parentName:"p"},"MySQL")," certificates are generated in the CI pipeline for ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/msvc2022-qt6.yml"},"Windows")," and ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/linux-qt6.yml"},"Linux"),".")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can also pass the ",(0,i.kt)("inlineCode",{parentName:"p"},"QString")," to the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," configuration separated by the ",(0,i.kt)("inlineCode",{parentName:"p"},";")," semicolon character and using the ",(0,i.kt)("inlineCode",{parentName:"p"},"=")," to assign values.")),(0,i.kt)("h5",{id:"postgresql"},"PostgreSQL"),(0,i.kt)("p",null,"You have to pass the ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS"},(0,i.kt)("inlineCode",{parentName:"a"},"sslmode"))," or the deprecated ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-REQUIRESSL"},(0,i.kt)("inlineCode",{parentName:"a"},"requiressl"))," options."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"And place your ",(0,i.kt)("strong",{parentName:"p"},"client")," certificates to the ",(0,i.kt)("inlineCode",{parentName:"p"},"~/.postgres/")," on ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-FILE-USAGE"},"Linux")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"$env:APPDATA/postgres/")," on Windows. Everything is described in the PostgreSQL's ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-ssl.html"},"libpq client")," and ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/15/ssl-tcp.html#SSL-FILE-USAGE"},"server")," documentation."),(0,i.kt)("p",null,"If you want to keep your ",(0,i.kt)("strong",{parentName:"p"},"client")," certificates in your own location, you can set the ",(0,i.kt)("inlineCode",{parentName:"p"},"sslcert"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"sslkey"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"sslrootcert")," options."),(0,i.kt)(l.Z,{groupId:S.IZ,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.Fo,label:S.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.q5,label:S.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')))),(0,i.kt)("p",null,"You can define these SSL-related options in the top-level configuration, they will be copied to the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," option hash during a configuration parsing. The top-level configuration takes precedence and overwrites the options in the ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," hash."),(0,i.kt)(l.Z,{groupId:S.IZ,mdxType:"Tabs"},(0,i.kt)(o.Z,{value:S.Fo,label:S.IM,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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.kt)(o.Z,{value:S.q5,label:S.C,mdxType:"TabItem"},(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')))),(0,i.kt)("p",null,"You may also use the ",(0,i.kt)("inlineCode",{parentName:"p"},"ConfigUtils::postgresSslOptions()")," or the ",(0,i.kt)("inlineCode",{parentName:"p"},"ConfigUtils::insertPostgresSslOptions()")," methods to insert the ",(0,i.kt)("inlineCode",{parentName:"p"},"sslmode"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"sslcert"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"sslkey"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"sslrootcert")," options for you and define them using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_PGSQL_SSLMODE"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_PGSQL_SSLCERT"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_PGSQL_SSLKEY"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"DB_PGSQL_SSLROOTCERT")," environment variable."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The PostgreSQL's libpq client library provides the ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.13.1.1"},(0,i.kt)("inlineCode",{parentName:"a"},"PGSSLMODE")),", ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.16.1.1"},(0,i.kt)("inlineCode",{parentName:"a"},"PGSSLCERT")),", ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.17.1.1"},(0,i.kt)("inlineCode",{parentName:"a"},"PGSSLKEY")),", and ",(0,i.kt)("a",{parentName:"p",href:"https://www.postgresql.org/docs/current/libpq-envars.html#id-1.7.3.22.3.4.18.1.1"},(0,i.kt)("inlineCode",{parentName:"a"},"PGSSLROOTCERT"))," environment variables, so you don't have to use TinyORM's ",(0,i.kt)("inlineCode",{parentName:"p"},"options")," configuration and may use these environment variables instead.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can take a look at the GitHub actions how the ",(0,i.kt)("inlineCode",{parentName:"p"},"PostgreSQL")," certificates are generated in the CI pipeline for ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/msvc2022-qt6.yml"},"Windows")," and ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/blob/main/.github/workflows/linux-qt6.yml"},"Linux"),".")),(0,i.kt)("h2",{id:"running-sql-queries"},"Running SQL Queries"),(0,i.kt)("p",null,"Once you have configured your database connection, you may run queries using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade. The ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade provides methods for each type of query: ",(0,i.kt)("inlineCode",{parentName:"p"},"select"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"update"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"insert"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"delete"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"statement"),"."),(0,i.kt)("h4",{id:"running-a-select-query"},"Running A Select Query"),(0,i.kt)("p",null,"To run a basic SELECT query, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"select")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'auto users = DB::select("select * from users where active = ?", {1});\n')),(0,i.kt)("p",null,"The first argument passed to the ",(0,i.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"where")," clause constraints. Parameter binding provides protection against SQL injection."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"select")," method returns a ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," containing the results of the query, where each result can be accessed by ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery::next")," method. Look into the ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery"),' documentation on how to obtain results from the "query". You may access each column\'s value by ',(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery::value")," method. The first ",(0,i.kt)("inlineCode",{parentName:"p"},"bool")," return value is the value returned from ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery::exec")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\n#include \n\nauto users = DB::select("select * from users");\n\nwhile(users.next())\n qDebug() << users.value("name").toString();\n')),(0,i.kt)("h4",{id:"selecting-scalar-values"},"Selecting Scalar Values"),(0,i.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"scalar")," shortcut method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"running-an-insert-statement"},"Running An Insert Statement"),(0,i.kt)("p",null,"To execute an ",(0,i.kt)("inlineCode",{parentName:"p"},"insert")," statement, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"insert")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade. Like ",(0,i.kt)("inlineCode",{parentName:"p"},"select"),", this method accepts the SQL query as its first argument and bindings as its second argument and returns ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nDB::insert("insert into users (id, name) values (?, ?)", {1, "Marc"});\n')),(0,i.kt)("h4",{id:"running-an-update-statement"},"Running An Update Statement"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"update")," method should be used to update existing records in the database. The number of rows affected by the statement and ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," is returned by the method as ",(0,i.kt)("inlineCode",{parentName:"p"},"std::tuple"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("h4",{id:"running-a-delete-statement"},"Running A Delete Statement"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"remove")," method should be used to delete records from the database. Like ",(0,i.kt)("inlineCode",{parentName:"p"},"update"),", the number of affected rows and ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," will be returned by the method as ",(0,i.kt)("inlineCode",{parentName:"p"},"std::tuple"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nauto [affected, query] = DB::remove("delete from users");\n')),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("inlineCode",{parentName:"p"},"delete")," can not be used as the method name because it is the reserved word.")),(0,i.kt)("h4",{id:"running-a-general-statement"},"Running A General Statement"),(0,i.kt)("p",null,"Some database statements do not return any value. For these types of operations, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"statement")," method on the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'DB::statement("drop table users");\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("inlineCode",{parentName:"p"},"DB::statement")," method should be used for ",(0,i.kt)("a",{parentName:"p",href:"https://en.wikipedia.org/wiki/Data_definition_language"},"DDL"),' queries, don\'t use it for "select" queries because it internally calls ',(0,i.kt)("inlineCode",{parentName:"p"},"recordsHaveBeenModified")," method.")),(0,i.kt)("h4",{id:"running-an-unprepared-statement"},"Running An Unprepared Statement"),(0,i.kt)("p",null,"Sometimes you may want to execute an SQL statement without binding any values. You may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade's ",(0,i.kt)("inlineCode",{parentName:"p"},"unprepared")," method to accomplish this:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"DB::unprepared(\"update users set votes = 100 where name = 'Dries'\");\n")),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"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.")),(0,i.kt)("h4",{id:"implicit-commits"},"Implicit Commits"),(0,i.kt)("p",null,"When using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade's ",(0,i.kt)("inlineCode",{parentName:"p"},"statement")," methods within transactions, you must be careful to avoid statements that cause ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.1/en/implicit-commit.html"},"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:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'DB::statement("create table users (name varchar(255) null)");\n')),(0,i.kt)("p",null,"Please refer to the MySQL manual for ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.1/en/implicit-commit.html"},"a list of all statements")," that trigger implicit commits."),(0,i.kt)("h3",{id:"using-multiple-database-connections"},"Using Multiple Database Connections"),(0,i.kt)("p",null,"You can configure multiple database connections at once during ",(0,i.kt)("inlineCode",{parentName:"p"},"DatabaseManager")," instantiation using the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB::create")," overload, where the first argument is a hash of multiple connections and is of type ",(0,i.kt)("inlineCode",{parentName:"p"},"QHash")," and the second argument is the name of the default connection:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#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')),(0,i.kt)("p",null,"If your application needs to use multiple connections, you may access each connection via the ",(0,i.kt)("inlineCode",{parentName:"p"},"connection")," method provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade. The connection name passed to the ",(0,i.kt)("inlineCode",{parentName:"p"},"connection")," method should correspond to one of the connections key listed in your configuration:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'#include \n\nauto query = DB::connection("mysql_test").select(...);\n')),(0,i.kt)("p",null,"You may access the raw underlying ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," instance of a connection using the ",(0,i.kt)("inlineCode",{parentName:"p"},"getQtQuery")," method on a connection instance:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"auto query = DB::connection().getQtQuery();\n")),(0,i.kt)("p",null,"Or you can use the shortcut method ",(0,i.kt)("inlineCode",{parentName:"p"},"qtQuery")," provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"auto query = DB::qtQuery();\n")),(0,i.kt)("h2",{id:"database-transactions"},"Database Transactions"),(0,i.kt)("h4",{id:"manually-using-transactions"},"Manually Using Transactions"),(0,i.kt)("p",null,"If you would like to begin a transaction manually and have complete control over rollbacks and commits, you may use the ",(0,i.kt)("inlineCode",{parentName:"p"},"beginTransaction")," method provided by the ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"#include \n\nDB::beginTransaction();\n")),(0,i.kt)("p",null,"You can rollback the transaction via the ",(0,i.kt)("inlineCode",{parentName:"p"},"rollBack")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"DB::rollBack();\n")),(0,i.kt)("p",null,"Lastly, you can commit a transaction via the ",(0,i.kt)("inlineCode",{parentName:"p"},"commit")," method:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"DB::commit();\n")),(0,i.kt)("p",null,"All transaction methods accept a connection name as the optional argument:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'DB::beginTransaction("mysql_test");\n')),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"DB")," facade's transaction methods control the transactions for both the ",(0,i.kt)("a",{parentName:"p",href:"/database/query-builder"},"query builder")," and ",(0,i.kt)("a",{parentName:"p",href:"/tinyorm/getting-started"},"TinyORM"),".")),(0,i.kt)("h2",{id:"multi-threading-support"},"Multi-threading support"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM")," supports multi-threading for the ",(0,i.kt)("inlineCode",{parentName:"p"},"MSVC")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"GCC")," on Linux compilers. Multi-threading is disabled for the ",(0,i.kt)("inlineCode",{parentName:"p"},"Clang <14.0.3")," compiler on MSYS2, ",(0,i.kt)("inlineCode",{parentName:"p"},"Clang <14.0.4")," on Linux and for the ",(0,i.kt)("inlineCode",{parentName:"p"},"GCC")," compiler on MSYS2. The reason are bugs in the ",(0,i.kt)("inlineCode",{parentName:"p"},"TLS")," wrapper that is generated by the ",(0,i.kt)("a",{parentName:"p",href:"https://en.cppreference.com/w/cpp/keyword/thread_local"},(0,i.kt)("inlineCode",{parentName:"a"},"thread_local"))," keyword."),(0,i.kt)("p",null,"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."),(0,i.kt)("p",null,"In addition, the third party libraries used by the ",(0,i.kt)("inlineCode",{parentName:"p"},"QSqlDrivers")," can impose further restrictions on using the SQL Module in a multithreaded program."),(0,i.kt)("p",null,"In short, if you create a ",(0,i.kt)("inlineCode",{parentName:"p"},"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."),(0,i.kt)("p",null,"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."),(0,i.kt)("admonition",{type:"caution"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations#tables"},(0,i.kt)("inlineCode",{parentName:"a"},"schema builder"))," and ",(0,i.kt)("a",{parentName:"p",href:"/database/migrations"},(0,i.kt)("inlineCode",{parentName:"a"},"migrations"))," don't support multi-threading.")))}E.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/cb1e72f9.fa14ee96.js b/assets/js/cb1e72f9.fa14ee96.js new file mode 100644 index 000000000..7948bcc26 --- /dev/null +++ b/assets/js/cb1e72f9.fa14ee96.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[684],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>k});var a=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function l(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var s=a.createContext({}),d=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=d(e.components);return a.createElement(s.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},c=a.forwardRef((function(e,t){var n=e.components,i=e.mdxType,r=e.originalType,s=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),m=d(n),c=i,k=m["".concat(s,".").concat(c)]||m[c]||u[c]||r;return n?a.createElement(k,l(l({ref:t},p),{},{components:n})):a.createElement(k,l({ref:t},p))}));function k(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var r=n.length,l=new Array(r);l[0]=c;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[m]="string"==typeof e?e:i,l[1]=o;for(var d=2;d{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>o,toc:()=>d});var a=n(7462),i=(n(7294),n(3905));const r={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","tinydrivers","sql drivers"]},l="TinyDrivers: Getting Started",o={unversionedId:"tinydrivers/getting-started",id:"tinydrivers/getting-started",title:"TinyDrivers: 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/tinydrivers/getting-started.mdx",sourceDirName:"tinydrivers",slug:"/tinydrivers/getting-started",permalink:"/tinydrivers/getting-started",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/tinydrivers/getting-started.mdx",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","tinydrivers","sql drivers"]},sidebar:"tinyormSidebar",previous:{title:"Serialization",permalink:"/tinyorm/serialization"},next:{title:"TinyORM",permalink:"/building/tinyorm"}},s={},d=[{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:"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}],p={toc:d},m="wrapper";function u(e){let{components:t,...n}=e;return(0,i.kt)(m,(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"tinydrivers-getting-started"},"TinyDrivers: Getting Started"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#differences-from-qtsql"},"Differences from QtSql"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#build-system"},"Build system")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#performance"},"Performance")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#internals"},"Internals"))),(0,i.kt)("h2",{id:"introduction"},"Introduction"),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," library is an underlying SQL database layer for ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyORM"),". It can be used instead of the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql")," module, can be ",(0,i.kt)("u",null,(0,i.kt)("strong",{parentName:"p"},"swapped"))," at compile, and has ",(0,i.kt)("strong",{parentName:"p"},"1:1")," API as the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql")," module. \ud83d\ude2e Swapping is controlled by the ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," build system options."),(0,i.kt)("p",null,"It was designed to drop the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql")," dependency while maintaining backward compatibility and without the need for any code changes after the swap."),(0,i.kt)("h5",{id:"features-summary"},"Features summary"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"both, normal and prepared statements are supported"),(0,i.kt)("li",{parentName:"ul"},"TLS/SSL connections using ",(0,i.kt)("a",{parentName:"li",href:"https://dev.mysql.com/doc/c-api/en/mysql-options.html"},(0,i.kt)("inlineCode",{parentName:"a"},"MYSQL_OPT_SSL_MODE"))," (verify_ca, verify_identity) \ud83d\udd25"),(0,i.kt)("li",{parentName:"ul"},"setting many other connection options (see ",(0,i.kt)("a",{parentName:"li",href:"https://github.com/silverqx/TinyORM/blob/main/drivers/mysql/src/orm/drivers/mysql/mysqldriver_p.cpp"},(0,i.kt)("inlineCode",{parentName:"a"},"mysqldriver_p.cpp")),")"),(0,i.kt)("li",{parentName:"ul"},"building and linking against the ",(0,i.kt)("a",{parentName:"li",href:"https://mariadb.com/kb/en/mariadb-connector-c/"},(0,i.kt)("inlineCode",{parentName:"a"},"MariaDB Connector/C"))),(0,i.kt)("li",{parentName:"ul"},"transactions"),(0,i.kt)("li",{parentName:"ul"},"re-using the current ",(0,i.kt)("inlineCode",{parentName:"li"},"SqlQuery")," instance to re-execute the same or another query"),(0,i.kt)("li",{parentName:"ul"},"detaching from the result set (associated to release memory)"),(0,i.kt)("li",{parentName:"ul"},"query size, number of affected rows, last inserted ID, testing ",(0,i.kt)("inlineCode",{parentName:"li"},"isNull()"),", ..."),(0,i.kt)("li",{parentName:"ul"},"all ",(0,i.kt)("strong",{parentName:"li"},"3366 unit tests")," passed \ud83d\ude2e")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Currently, only the ",(0,i.kt)("inlineCode",{parentName:"p"},"MySQL")," database driver is supported and finished.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," can only be built with ",(0,i.kt)("inlineCode",{parentName:"p"},"Qt v6"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"Qt v5.15")," isn't supported.")),(0,i.kt)("admonition",{type:"note"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," library supports both build systems ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," and also ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake"),".")),(0,i.kt)("h2",{id:"differences-from-qtsql"},"Differences from QtSql"),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," doesn't return errors the the same way as the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql")," module, which means return a ",(0,i.kt)("inlineCode",{parentName:"p"},"bool")," and if it's the result ",(0,i.kt)("inlineCode",{parentName:"p"},"false")," then obtain the ",(0,i.kt)("inlineCode",{parentName:"p"},"SqlError")," instance using the ",(0,i.kt)("inlineCode",{parentName:"p"},"lastError()")," method from ",(0,i.kt)("inlineCode",{parentName:"p"},"SqlDatabase")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"SqlQuery")," instances. Instead, it throws exceptions, and methods returning a ",(0,i.kt)("inlineCode",{parentName:"p"},"bool")," type to report an error state always return ",(0,i.kt)("inlineCode",{parentName:"p"},"true"),"."),(0,i.kt)("h5",{id:"removed-features"},"Removed features"),(0,i.kt)("p",null,"Simulation of prepared statements while calling ",(0,i.kt)("inlineCode",{parentName:"p"},"SqlQuery::exec(QString)"),", this functionality is useless because you can call regular prepared statements using ",(0,i.kt)("inlineCode",{parentName:"p"},"SqlQuery::prepare(QString)")," and then ",(0,i.kt)("inlineCode",{parentName:"p"},"SqlQuery::exec()"),"."),(0,i.kt)("h5",{id:"missing-features"},"Missing features"),(0,i.kt)("p",null,"Fetching multiple result sets using ",(0,i.kt)("inlineCode",{parentName:"p"},"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."),(0,i.kt)("h3",{id:"build-system"},"Build system"),(0,i.kt)("p",null,"Another difference is that you can build the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," and its SQL drivers (",(0,i.kt)("inlineCode",{parentName:"p"},"TinyMySql"),") in 3 different ways; ",(0,i.kt)("inlineCode",{parentName:"p"},"Shared"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"Static"),", and as a ",(0,i.kt)("inlineCode",{parentName:"p"},"Loadable")," library at runtime using ",(0,i.kt)("inlineCode",{parentName:"p"},"LoadLibrary()")," on Windows or ",(0,i.kt)("inlineCode",{parentName:"p"},"dlopen()")," on Linux."),(0,i.kt)("h5",{id:"the-shared-library-build"},"The ",(0,i.kt)("inlineCode",{parentName:"h5"},"Shared")," library build"),(0,i.kt)("p",null,"It builds two shared libraries, the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," shared library that contains the core/common code and the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyMySql")," shared library that contains ",(0,i.kt)("inlineCode",{parentName:"p"},"MySQL")," implementation. The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyOrm")," links only against the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," shared library and ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyMySql")," is a private implementation."),(0,i.kt)("h5",{id:"the-static-build"},"The ",(0,i.kt)("inlineCode",{parentName:"h5"},"Static")," build"),(0,i.kt)("p",null,"It builds one ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," static archive that contains the core/common code and SQL drivers (",(0,i.kt)("inlineCode",{parentName:"p"},"TinyMySql"),"). This static library is linked or merged into the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyOrm")," shared or static library (both variants are supported)."),(0,i.kt)("h5",{id:"the-loadable-sql-drivers-build"},"The ",(0,i.kt)("inlineCode",{parentName:"h5"},"Loadable")," SQL drivers build"),(0,i.kt)("p",null,"It builds two shared libraries, the ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," shared library that contains the core/common code and ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyMySql")," shared library (module) that contains ",(0,i.kt)("inlineCode",{parentName:"p"},"MySQL")," implementation that is loaded at runtime using ",(0,i.kt)("inlineCode",{parentName:"p"},"LoadLibrary()")," on Windows or ",(0,i.kt)("inlineCode",{parentName:"p"},"dlopen()")," on Linux. The SQL driver library loader throws an exception if it cannot find this library at runtime."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyMySql")," links directly against the ",(0,i.kt)("inlineCode",{parentName:"p"},"MySQL C connector")," (",(0,i.kt)("inlineCode",{parentName:"p"},"libmysql")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"mysqlclient")," library).")),(0,i.kt)("h4",{id:"cmakeqmake-build-options"},(0,i.kt)("inlineCode",{parentName:"h4"},"CMake"),"/",(0,i.kt)("inlineCode",{parentName:"h4"},"qmake")," build options"),(0,i.kt)("h5",{id:"for-cmake"},"For ",(0,i.kt)("inlineCode",{parentName:"h5"},"CMake")),(0,i.kt)("p",null,"See ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#cmake-build-options"},"CMake build options"),", related ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," build options are:",(0,i.kt)("br",null),(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#BUILD_DRIVERS"},(0,i.kt)("inlineCode",{parentName:"a"},"BUILD_DRIVERS")),", ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#BUILD_MYSQL_DRIVERS"},(0,i.kt)("inlineCode",{parentName:"a"},"BUILD_MYSQL_DRIVERS")),", and ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#DRIVERS_TYPE"},(0,i.kt)("inlineCode",{parentName:"a"},"DRIVERS_TYPE"))),(0,i.kt)("p",null,"To control shared and static build use ",(0,i.kt)("a",{parentName:"p",href:"https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html"},(0,i.kt)("inlineCode",{parentName:"a"},"BUILD_SHARED_LIBS"))," ",(0,i.kt)("inlineCode",{parentName:"p"},"CMake")," configuration option."),(0,i.kt)("h5",{id:"for-qmake"},"For ",(0,i.kt)("inlineCode",{parentName:"h5"},"qmake")),(0,i.kt)("p",null,"See ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#qmake-build-options"},"qmake build options"),", related ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," configuration options are:",(0,i.kt)("br",null),(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#build_loadable_drivers"},(0,i.kt)("inlineCode",{parentName:"a"},"build_loadable_drivers")),", ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#build_mysql_driver"},(0,i.kt)("inlineCode",{parentName:"a"},"build_mysql_driver")),", ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#build_shared_drivers"},(0,i.kt)("inlineCode",{parentName:"a"},"build_shared_drivers")),", and ",(0,i.kt)("a",{parentName:"p",href:"/building/tinyorm#build_static_drivers"},(0,i.kt)("inlineCode",{parentName:"a"},"build_static_drivers"))),(0,i.kt)("p",null,"To control shared and static build use ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qmake-variable-reference.html#config"},(0,i.kt)("inlineCode",{parentName:"a"},"staticlib"))," ",(0,i.kt)("inlineCode",{parentName:"p"},"qmake")," configuration option."),(0,i.kt)("h3",{id:"performance"},"Performance"),(0,i.kt)("p",null,"Performance is several milliseconds faster compared to ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql")," with the ",(0,i.kt)("inlineCode",{parentName:"p"},"QMYSQL")," driver. It was tuned using the ",(0,i.kt)("inlineCode",{parentName:"p"},"KCacheGrind")," to be so. It's ~40ms faster on ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyOrmPlayground"},(0,i.kt)("inlineCode",{parentName:"a"},"TinyOrmPlayground"))," project with ",(0,i.kt)("strong",{parentName:"p"},"620")," database queries compiled using ",(0,i.kt)("inlineCode",{parentName:"p"},"GCC v13.2.1")," Debug build on Linux. Similar results can be expected on other platforms but it's not guaranteed."),(0,i.kt)("p",null,"This means performance is very similar to ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql"),". There is not much to speed up because ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," code is swift and 90% of the time is spent inside the ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/c-api/en/"},(0,i.kt)("inlineCode",{parentName:"a"},"MySQL C API"))," because we always have to wait for the database server, especially when creating database connections using eg. ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/c-api/en/mysql-real-connect.html"},(0,i.kt)("inlineCode",{parentName:"a"},"mysql_real_connect()"))," (this function is king among the slowest functions \ud83d\ude0e, which is understandable of course)."),(0,i.kt)("h2",{id:"internals"},"Internals"),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," internal design can be divided into 3 different layers:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Driver layer"),(0,i.kt)("li",{parentName:"ul"},"SQL API layer"),(0,i.kt)("li",{parentName:"ul"},"Public API layer")),(0,i.kt)("p",null,"The Driver layer is eg. ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyMySql")," library which is responsible for communicating with the underlying database driver (eg. ",(0,i.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/c-api/en/"},(0,i.kt)("inlineCode",{parentName:"a"},"MySQL C API")),")."),(0,i.kt)("p",null,"The SQL API layer is a semi-layer that glues everything up and sits between the Public interface API and the Driver layer."),(0,i.kt)("p",null,"The Public interface API layer are the end classes like ",(0,i.kt)("inlineCode",{parentName:"p"},"SqlDatabase")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"SqlQuery")," which are exposed to the end user."),(0,i.kt)("h5",{id:"sqldatabase"},"SqlDatabase"),(0,i.kt)("p",null,"One more thing worth mentioning is the ",(0,i.kt)("inlineCode",{parentName:"p"},"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,i.kt)("inlineCode",{parentName:"p"},"SqlDatabase")," represents a physical database connection. It's not a good design because it breaks the ",(0,i.kt)("a",{parentName:"p",href:"https://en.wikipedia.org/wiki/Single_responsibility_principle"},"Single Responsibility principle"),", but it's what it is."),(0,i.kt)("h5",{id:"namespaces"},"Namespaces"),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," classes are defined in the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Drivers")," namespace and ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyMySql")," classes in the ",(0,i.kt)("inlineCode",{parentName:"p"},"Orm::Drivers::MySql")," namespace."),(0,i.kt)("h5",{id:"documentation"},"Documentation"),(0,i.kt)("p",null,"For all other APIs you can follow the ",(0,i.kt)("a",{parentName:"p",href:"https://doc.qt.io/qt/qtsql-index.html"},"QtSql documentation")," as the API is 1:1. The exception is of course the build system, ",(0,i.kt)("inlineCode",{parentName:"p"},"TinyOrm")," has its own build system that doesn't follow the ",(0,i.kt)("inlineCode",{parentName:"p"},"QtSql")," module."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/cbe663fe.0aaaebcb.js b/assets/js/cbe663fe.8fc7d46f.js similarity index 99% rename from assets/js/cbe663fe.0aaaebcb.js rename to assets/js/cbe663fe.8fc7d46f.js index ad59acccd..cf7290542 100644 --- a/assets/js/cbe663fe.0aaaebcb.js +++ b/assets/js/cbe663fe.8fc7d46f.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[594],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>c});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),u=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},p="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},h=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,o=e.originalType,s=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),p=u(n),h=r,c=p["".concat(s,".").concat(h)]||p[h]||m[h]||o;return n?a.createElement(c,i(i({ref:t},d),{},{components:n})):a.createElement(c,i({ref:t},d))}));function c(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=n.length,i=new Array(o);i[0]=h;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:r,i[1]=l;for(var u=2;u{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>l,toc:()=>u});var a=n(7462),r=(n(7294),n(3905));const o={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"]},i="Database: Query Builder",l={unversionedId:"database/query-builder",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,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/database/query-builder.mdx",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"}},s={},u=[{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}],d={toc:u},p="wrapper";function m(e){let{components:t,...n}=e;return(0,r.kt)(p,(0,a.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"database-query-builder"},"Database: Query Builder"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#running-database-queries"},"Running Database Queries"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#chunking-results"},"Chunking Results")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#aggregates"},"Aggregates")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#select-statements"},"Select Statements")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#raw-expressions"},"Raw Expressions")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#joins"},"Joins")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#basic-where-clauses"},"Basic Where Clauses"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#where-clauses"},"Where Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#or-where-clauses"},"Or Where Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#where-not-clauses"},"Where Not Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#additional-where-clauses"},"Additional Where Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#condition-operator-overriding"},"Condition Operator Overriding")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#logical-grouping"},"Logical Grouping")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#advanced-where-clauses"},"Advanced Where Clauses"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#where-exists-clauses"},"Where Exists Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#subquery-where-clauses"},"Subquery Where Clauses")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#ordering-grouping-limit-and-offset"},"Ordering, Grouping, Limit & Offset"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#ordering"},"Ordering")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#grouping"},"Grouping")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#limit-and-offset"},"Limit & Offset")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#insert-statements"},"Insert Statements"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#upserts"},"Upserts")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#update-statements"},"Update Statements"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#increment-and-decrement"},"Increment & Decrement")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#delete-statements"},"Delete Statements"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#truncate-statement"},"Truncate Statement")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#pessimistic-locking"},"Pessimistic Locking")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#debugging"},"Debugging"))),(0,r.kt)("h2",{id:"introduction"},"Introduction"),(0,r.kt)("p",null,"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."),(0,r.kt)("p",null,"The TinyORM query builder uses ",(0,r.kt)("inlineCode",{parentName:"p"},"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."),(0,r.kt)("admonition",{type:"danger"},(0,r.kt)("p",{parentName:"admonition"},(0,r.kt)("inlineCode",{parentName:"p"},"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.')),(0,r.kt)("admonition",{type:"danger"},(0,r.kt)("p",{parentName:"admonition"},"The ",(0,r.kt)("inlineCode",{parentName:"p"},"QMYSQL")," Qt driver contains a bug, if your table contains a ",(0,r.kt)("inlineCode",{parentName:"p"},"json")," column type, then you must explicitly name columns other than ",(0,r.kt)("inlineCode",{parentName:"p"},"json")," columns instead of the ",(0,r.kt)("inlineCode",{parentName:"p"},"*")," 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.kt)("inlineCode",{parentName:"p"},"QPSQL")," driver returns correct results and doesn't have problem with ",(0,r.kt)("inlineCode",{parentName:"p"},"json")," columns. It was fixed in the Qt 5.15.12, 6.2.7, 6.5.0 ",(0,r.kt)("a",{parentName:"p",href:"https://bugreports.qt.io/browse/QTBUG-101680"},"QTBUG-101680"),".")),(0,r.kt)("h2",{id:"running-database-queries"},"Running Database Queries"),(0,r.kt)("h4",{id:"retrieving-all-rows-from-a-table"},"Retrieving All Rows From A Table"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"table")," method provided by the ",(0,r.kt)("inlineCode",{parentName:"p"},"DB")," facade to begin a query. The ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"get")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"get")," method returns a ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," containing the results of the query where each result can be accessed by ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery::next")," method, look into the ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery"),' documentation how to obtain results from the "query". You may access each column\'s value by ',(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery::value")," method. The first ",(0,r.kt)("inlineCode",{parentName:"p"},"bool")," return value is the value returned from ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery::exec")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\n#include \n\nauto users = DB::table("users")->get();\n\nwhile(users.next())\n qDebug() << users.value("name").toString();\n')),(0,r.kt)("h4",{id:"retrieving-a-single-row--column-from-a-table"},"Retrieving A Single Row / Column From A Table"),(0,r.kt)("p",null,"If you just need to retrieve a single row from a database table, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"QueryBuilder::first")," method. This method will return a ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," object, on which was internally called ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery::first")," method. This method retrieves the first record in the result, if available, and positions the query on the retrieved record:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto user = DB::table("users")->whereEq("name", "John").first();\n\nuser.value("email").toString();\n')),(0,r.kt)("p",null,"If you don't need an entire row, you may extract a single value from a record using the ",(0,r.kt)("inlineCode",{parentName:"p"},"value")," method. This method will return the value of the column directly as ",(0,r.kt)("inlineCode",{parentName:"p"},"QVariant"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto email = DB::table("users")->whereEq("name", "John").value("email").toString();\n')),(0,r.kt)("p",null,"To retrieve a single row by its ",(0,r.kt)("inlineCode",{parentName:"p"},"id")," column value, use the ",(0,r.kt)("inlineCode",{parentName:"p"},"find")," method. This method retrieves the first record in the result, if available, and positions the query on the retrieved record:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto user = DB::table("users")->find(3);\n\nuser.value("email").toString();\n')),(0,r.kt)("h4",{id:"retrieving-a-list-of-column-values"},"Retrieving A List Of Column Values"),(0,r.kt)("p",null,"If you would like to retrieve the ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," instance containing the values of a single column, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"pluck")," method. In this example, we'll retrieve a collection of user titles:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\n#include \n\nconst auto titles = DB::table("users")->pluck("title");\n\nfor (const auto &title : titles)\n qDebug() << title.value();\n')),(0,r.kt)("p",null," You may specify the column that the resulting collection should use as its keys by providing a second argument to the ",(0,r.kt)("inlineCode",{parentName:"p"},"pluck")," method, following example returns the ",(0,r.kt)("inlineCode",{parentName:"p"},"std::map"),' of "titles" keyed by "names":'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\nauto titles = DB::table("users")->pluck("title", "name");\n\nfor (auto &&[name, title] : titles)\n qDebug() << name << ":" << title.value();\n')),(0,r.kt)("p",null,"You may also use ",(0,r.kt)("inlineCode",{parentName:"p"},'pluck("name", "id")'),", it returns the ",(0,r.kt)("inlineCode",{parentName:"p"},"std::map"),' of "names" keyed by its "ids".'),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"This second ",(0,r.kt)("inlineCode",{parentName:"p"},"pluck")," overload returns ",(0,r.kt)("inlineCode",{parentName:"p"},"std::map")," so you have to provide a template argument for the key type.")),(0,r.kt)("h4",{id:"concatenate-column-values"},"Concatenate column values"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"implode")," method can be used to join column values. For example, you may use this method to concatenate prices with the ",(0,r.kt)("inlineCode",{parentName:"p"},", ")," character as the glue:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("orders")->where("price", ">", 100).implode("price", ", ");\n')),(0,r.kt)("h3",{id:"chunking-results"},"Chunking Results"),(0,r.kt)("p",null,"If you need to work with thousands of database records, consider using the ",(0,r.kt)("inlineCode",{parentName:"p"},"chunk")," method provided by the ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"users")," table in chunks of 100 records at a time:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"You may stop further chunks from being processed by returning ",(0,r.kt)("inlineCode",{parentName:"p"},"false")," from the closure:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->orderBy("id").chunk(100, [](QSqlQuery &users, const int page)\n{\n // Process the records...\n\n return false;\n});\n')),(0,r.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"chunkById")," method instead. This method will automatically paginate the results based on the record's primary key:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"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.kt)("inlineCode",{parentName:"p"},"chunkById")," method.")),(0,r.kt)("h3",{id:"aggregates"},"Aggregates"),(0,r.kt)("p",null,"The query builder also provides a variety of methods for retrieving aggregate values like ",(0,r.kt)("inlineCode",{parentName:"p"},"count"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"max"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"min"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"avg"),", and ",(0,r.kt)("inlineCode",{parentName:"p"},"sum"),". You may call any of these methods after constructing your query:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\nauto users = DB::table("users")->count();\n\nauto price = DB::table("orders")->max("price");\n')),(0,r.kt)("p",null,"Of course, you may combine these methods with other clauses to fine-tune how your aggregate value is calculated:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto price = DB::table("orders")\n ->whereEq("finalized", 1)\n .avg("price");\n')),(0,r.kt)("h4",{id:"determining-if-records-exist"},"Determining If Records Exist"),(0,r.kt)("p",null,"Instead of using the ",(0,r.kt)("inlineCode",{parentName:"p"},"count")," method to determine if any records exist that match your query's constraints, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"exists")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"doesntExist")," methods:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'if (DB::table("orders")->whereEq("finalized", 1).exists()) {\n // ...\n}\n\nif (DB::table("orders")->whereEq("finalized", 1).doesntExist()) {\n // ...\n}\n')),(0,r.kt)("h2",{id:"select-statements"},"Select Statements"),(0,r.kt)("h4",{id:"specifying-a-select-clause"},"Specifying A Select Clause"),(0,r.kt)("p",null,"You may not always want to select all columns from a database table. Using the ",(0,r.kt)("inlineCode",{parentName:"p"},"select"),' method, you can specify a custom "select" clause for the query:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\nauto users = DB::table("users")\n ->select({"name", "email as user_email"})\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"distinct")," method allows you to force the query to return distinct results:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")->distinct().get();\n')),(0,r.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"addSelect")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto query = DB::table("users")->select("name");\n\nauto users = query.addSelect("age").get();\n')),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"You can also pass subqueries to the ",(0,r.kt)("inlineCode",{parentName:"p"},"select")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"addSelect")," methods. A subquery can be a lambda expression, raw string, or the ",(0,r.kt)("inlineCode",{parentName:"p"},"QueryBuilder")," instance.")),(0,r.kt)("h2",{id:"raw-expressions"},"Raw Expressions"),(0,r.kt)("p",null,"Sometimes you may need to insert an arbitrary string into a query. To create a raw string expression, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"raw")," method provided by the ",(0,r.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->select(DB::raw("count(*) as user_count, status"))\n .where("status", "<>", 1)\n .groupBy("status")\n .get();\n')),(0,r.kt)("admonition",{type:"danger"},(0,r.kt)("p",{parentName:"admonition"},"Raw statements will be injected into the query as strings, so you should be extremely careful to avoid creating SQL injection vulnerabilities.")),(0,r.kt)("h3",{id:"raw-methods"},"Raw Methods"),(0,r.kt)("p",null,"Instead of using the ",(0,r.kt)("inlineCode",{parentName:"p"},"DB::raw")," method, you may also use the following methods to insert a raw expression into various parts of your query. ",(0,r.kt)("strong",{parentName:"p"},"Remember, TinyORM can not guarantee that any query using raw expressions is protected against SQL injection vulnerabilities.")),(0,r.kt)("h4",{id:"selectraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"selectRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"selectRaw")," method can be used in place of ",(0,r.kt)("inlineCode",{parentName:"p"},"addSelect(DB::raw(...))"),". This method accepts an optional vector of bindings as its second argument:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto orders = DB::table("orders")\n ->selectRaw("price * ? as price_with_tax", {1.0825})\n .get();\n')),(0,r.kt)("h4",{id:"fromraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"fromRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"fromRaw"),' method may be used to provide a raw string as the value of the "from" clause:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"whereraw--orwhereraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"whereRaw / orWhereRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereRaw")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"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:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto orders = DB::table("orders")\n ->whereRaw("price > IF(state = \\"TX\\", ?, 100)", {200})\n .get();\n')),(0,r.kt)("h3",{id:"groupbyraw"},(0,r.kt)("inlineCode",{parentName:"h3"},"groupByRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"groupByRaw")," method may be used to provide a raw string as the value of the ",(0,r.kt)("inlineCode",{parentName:"p"},"group by")," clause:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto orders = DB::table("orders")\n ->select({"city", "state"})\n .groupByRaw("city, state")\n .get();\n')),(0,r.kt)("h4",{id:"havingraw--orhavingraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"havingRaw / orHavingRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"havingRaw")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"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:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"orderbyraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"orderByRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"orderByRaw"),' method may be used to provide a raw string as the value of the "order by" clause:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto orders = DB::table("orders")\n ->orderByRaw("updated_at - created_at DESC")\n .get();\n')),(0,r.kt)("h2",{id:"joins"},"Joins"),(0,r.kt)("h4",{id:"inner-join-clause"},"Inner Join Clause"),(0,r.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"join")," method on a query builder instance. The first argument passed to the ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("h4",{id:"left-join--right-join-clause"},"Left Join / Right Join Clause"),(0,r.kt)("p",null,'If you would like to perform a "left join" or "right join" instead of an "inner join", use the ',(0,r.kt)("inlineCode",{parentName:"p"},"leftJoin")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"rightJoin")," methods. These methods have the same signature as the ",(0,r.kt)("inlineCode",{parentName:"p"},"join")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"cross-join-clause"},"Cross Join Clause"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"crossJoin"),' method to perform a "cross join". Cross joins generate a cartesian product between the first table and the joined table:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto sizes = DB::table("sizes")\n ->crossJoin("colors")\n .get();\n')),(0,r.kt)("h4",{id:"advanced-join-clauses"},"Advanced Join Clauses"),(0,r.kt)("p",null,"You may also specify more advanced join clauses. To get started, pass a lambda expression as the second argument to the ",(0,r.kt)("inlineCode",{parentName:"p"},"join")," method. The lambda expression will receive a ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::Query::JoinClause"),' instance which allows you to specify constraints on the "join" clause:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("p",null,'If you would like to use a "where" clause on your joins, you may use the ',(0,r.kt)("inlineCode",{parentName:"p"},"where")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhere")," methods provided by the ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::Query::JoinClause")," instance. Instead of comparing two columns, these methods will compare the column against a value:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"subquery-joins"},"Subquery Joins"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"joinSub"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"leftJoinSub"),", and ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"created_at")," timestamp of the user's most recently published blog post:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h2",{id:"basic-where-clauses"},"Basic Where Clauses"),(0,r.kt)("h3",{id:"where-clauses"},"Where Clauses"),(0,r.kt)("p",null,"You may use the query builder's ",(0,r.kt)("inlineCode",{parentName:"p"},"where"),' method to add "where" clauses to the query. The most basic call to the ',(0,r.kt)("inlineCode",{parentName:"p"},"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."),(0,r.kt)("p",null,"For example, the following query retrieves users where the value of the ",(0,r.kt)("inlineCode",{parentName:"p"},"votes")," column is equal to ",(0,r.kt)("inlineCode",{parentName:"p"},"100")," and the value of the ",(0,r.kt)("inlineCode",{parentName:"p"},"age")," column is greater than ",(0,r.kt)("inlineCode",{parentName:"p"},"35"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where("votes", "=", 100)\n .where("age", ">", 35)\n .get();\n')),(0,r.kt)("p",null,"For convenience, if you want to verify that a column is ",(0,r.kt)("inlineCode",{parentName:"p"},"=")," to a given value, you may call ",(0,r.kt)("inlineCode",{parentName:"p"},"whereEq")," method. Similar ",(0,r.kt)("inlineCode",{parentName:"p"},"XxxEq")," methods are also defined for other commands:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")->whereEq("votes", 100).get();\n')),(0,r.kt)("p",null,"As previously mentioned, you may use any operator that is supported by your database system:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"You may also pass a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," of conditions to the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," function. Each ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::WhereItem")," structure should contain the four arguments typically passed to the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where({\n {"status", 1}, // "=" by default\n {"subscribed", 1, "<>"},\n }).get();\n')),(0,r.kt)("h3",{id:"or-where-clauses"},"Or Where Clauses"),(0,r.kt)("p",null,"When chaining together calls to the query builder's ",(0,r.kt)("inlineCode",{parentName:"p"},"where"),' method, the "where" clauses will be joined together using the ',(0,r.kt)("inlineCode",{parentName:"p"},"and")," operator. However, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhere")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhereEq")," method to join a clause to the query using the ",(0,r.kt)("inlineCode",{parentName:"p"},"or")," operator. The ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhere")," method accepts the same arguments as the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where("votes", ">", 100)\n .orWhere("name", "=", "John")\n .orWhereEq("name", "Jack")\n .get();\n')),(0,r.kt)("p",null,'If you need to group an "or" condition within parentheses, you may pass a lambda expression as the first argument to the ',(0,r.kt)("inlineCode",{parentName:"p"},"orWhere")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"The example above will produce the following SQL:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sql"},'select * from users where votes > 100 or (name = "Abigail" and votes > 50)\n')),(0,r.kt)("h3",{id:"condition-operator-overriding"},"Condition Operator Overriding"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method overload with a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," as the first argument joins conditions using the ",(0,r.kt)("inlineCode",{parentName:"p"},"and")," operator by default:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"votes", 50, ">"},\n }).get();\n')),(0,r.kt)("p",null,"Conditions operator can be overridden by the fourth argument in the ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::WhereItem")," structure:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"votes", 50, ">", "or"},\n }).get();\n')),(0,r.kt)("p",null,"Or by the second ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"Orm::WhereItem")," structure:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"last_name", "Smith"},\n {"votes", 50, ">", "and"},\n }, "or")\n .get();\n')),(0,r.kt)("p",null,"The example above will produce the following SQL:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sql"},'select * from users where (first_name = "John" or last_name = "Smith" and votes > 50)\n')),(0,r.kt)("admonition",{type:"tip"},(0,r.kt)("p",{parentName:"admonition"},"Still, it is a better idea to use ",(0,r.kt)("a",{parentName:"p",href:"#logical-grouping"},"Logical Grouping")," described few lines below, which allows better control of the parentheses.")),(0,r.kt)("h3",{id:"where-not-clauses"},"Where Not Clauses"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNot")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto products = DB::table("products")\n ->whereNot([](auto &query) {\n query.whereEq("clearance", true)\n .orWhere("price", "<", 10);\n })\n .get();\n')),(0,r.kt)("h3",{id:"additional-where-clauses"},"Additional Where Clauses"),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereBetween / orWhereBetween")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereBetween")," method verifies that a column's value is between two values:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereBetween("votes", {1, 100})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereNotBetween / orWhereNotBetween")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNotBetween")," method verifies that a column's value lies outside of two values:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereNotBetween("votes", {1, 100})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereBetweenColumns / orWhereBetweenColumns")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereBetweenColumns")," method verifies that a column's value is between two values in given columns:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto files = DB::table("files")\n ->whereBetweenColumns("quota", {"min_allowed_quota", "max_allowed_quota"})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereNotBetweenColumns / orWhereNotBetweenColumns")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNotBetweenColumns")," method verifies that a column's value lies outside of two values in given columns:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto files = DB::table("files")\n ->whereNotBetweenColumns("quota", {"min_allowed_quota", "max_allowed_quota"})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereIn / whereNotIn / orWhereIn / orWhereNotIn")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereIn")," method verifies that a given column's value is contained within the given ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereIn("id", {1, 2, 3})\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNotIn")," method verifies that the given column's value is not contained in the given ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereNotIn("id", {1, 2, 3})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereNull / whereNotNull / orWhereNull / orWhereNotNull")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNull")," method verifies that the value of the given column is ",(0,r.kt)("inlineCode",{parentName:"p"},"NULL"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereNull("updated_at")\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNotNull")," method verifies that the column's value is not ",(0,r.kt)("inlineCode",{parentName:"p"},"NULL"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereNotNull("updated_at")\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereDate / whereTime / whereDay / whereMonth / whereYear")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereDate")," method may be used to compare a column's value against a date:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereDate("created_at", EQ, QDate(2022, 11, 18))\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereTime")," method may be used to compare a column's value against a specific time:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereTime("created_at", "=", QTime(11, 14, 23))\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereDay")," method may be used to compare a column's value against a specific day of the month:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereDay("created_at", "<=", 15)\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereMonth")," method may be used to compare a column's value against a specific month:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereEqMonth("created_at", 12)\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereYear")," method may be used to compare a column's value against a specific year:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereEqYear("created_at", 2016)\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereDate")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"whereTime")," methods also accept a ",(0,r.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance or you can pass values as a ",(0,r.kt)("inlineCode",{parentName:"p"},"QString")," in ",(0,r.kt)("inlineCode",{parentName:"p"},"2022-12-31")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"09:15:11")," formats."),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereDay"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"whereMoth"),", and ",(0,r.kt)("inlineCode",{parentName:"p"},"whereYear")," accept ",(0,r.kt)("inlineCode",{parentName:"p"},"QDate")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"QDateTime")," instances, an integral number or a ",(0,r.kt)("inlineCode",{parentName:"p"},"QString")," that contains an integral number."),(0,r.kt)("admonition",{type:"info"},(0,r.kt)("p",{parentName:"admonition"},"All the above methods offer ",(0,r.kt)("inlineCode",{parentName:"p"},"whereEqXyz")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhereXyz")," shortcut methods.")),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereColumn / orWhereColumn")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereColumnEq")," method may be used to verify that two columns are equal:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumnEq("first_name", "last_name")\n .get();\n')),(0,r.kt)("p",null,"You may also pass a comparison operator to the ",(0,r.kt)("inlineCode",{parentName:"p"},"whereColumn")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumn("updated_at", ">", "created_at")\n .get();\n')),(0,r.kt)("p",null,"You may also pass a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," of column comparisons to the ",(0,r.kt)("inlineCode",{parentName:"p"},"whereColumn")," method. These conditions will be joined using the ",(0,r.kt)("inlineCode",{parentName:"p"},"and")," operator:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">"},\n }).get();\n')),(0,r.kt)("p",null,"Conditions operator can also be overridden by the fourth argument in the ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::WhereColumnItem")," structure:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">", "or"},\n }).get();\n')),(0,r.kt)("p",null,"Or by the second ",(0,r.kt)("inlineCode",{parentName:"p"},"whereColumn")," argument:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">"},\n }, "or")\n .get();\n')),(0,r.kt)("h3",{id:"logical-grouping"},"Logical Grouping"),(0,r.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"orWhere")," method in parentheses in order to avoid unexpected query behavior. To accomplish this, you may pass a lambda expression to the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"As you can see, passing a lambda expression into the ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sql"},'select * from users where name = "John" and (votes > 100 or title = "Admin")\n')),(0,r.kt)("h2",{id:"advanced-where-clauses"},"Advanced Where Clauses"),(0,r.kt)("h3",{id:"where-exists-clauses"},"Where Exists Clauses"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereExists"),' method allows you to write "where exists" SQL clauses. The ',(0,r.kt)("inlineCode",{parentName:"p"},"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:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"Alternatively, you may provide a query object to the ",(0,r.kt)("inlineCode",{parentName:"p"},"whereExists")," method instead of a lambda expression:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'// 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')),(0,r.kt)("p",null,"Or directly:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"All of the examples above will produce the following SQL:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sql"},"select * from users\nwhere exists (\n select 1\n from orders\n where orders.user_id = users.id\n)\n")),(0,r.kt)("h3",{id:"subquery-where-clauses"},"Subquery Where Clauses"),(0,r.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"where"),' method. For example, the following query will retrieve all users who have a recent "membership" of a given type:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"where")," method. For example, the following query will retrieve all income records where the amount is less than average;"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("h2",{id:"ordering-grouping-limit-and-offset"},"Ordering, Grouping, Limit & Offset"),(0,r.kt)("h3",{id:"ordering"},"Ordering"),(0,r.kt)("h4",{id:"the-orderby-method"},"The ",(0,r.kt)("inlineCode",{parentName:"h4"},"orderBy")," Method"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"orderBy")," method allows you to sort the results of the query by a given column. The first argument accepted by the ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"asc")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"desc"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->orderBy("name", "desc")\n .get();\n')),(0,r.kt)("p",null,"To sort by multiple columns, you may simply invoke ",(0,r.kt)("inlineCode",{parentName:"p"},"orderBy")," as many times as necessary:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->orderBy("name", "desc")\n .orderBy("email", "asc")\n .get();\n')),(0,r.kt)("h4",{id:"the-latest--oldest-methods"},"The ",(0,r.kt)("inlineCode",{parentName:"h4"},"latest")," & ",(0,r.kt)("inlineCode",{parentName:"h4"},"oldest")," Methods"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"latest")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"oldest")," methods allow you to easily order results by date. By default, the result will be ordered by the table's ",(0,r.kt)("inlineCode",{parentName:"p"},"created_at")," column. Or, you may pass the column name that you wish to sort by:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto user = DB::table("users")\n ->latest()\n .first();\n')),(0,r.kt)("h4",{id:"random-ordering"},"Random Ordering"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"inRandomOrder")," method may be used to sort the query results randomly. For example, you may use this method to fetch a random user:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto randomUser = DB::table("users")\n ->inRandomOrder()\n .first();\n')),(0,r.kt)("h4",{id:"removing-existing-orderings"},"Removing Existing Orderings"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"reorder"),' method removes all of the "order by" clauses that have previously been applied to the query:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto &query = DB::table("users")->orderBy("name");\n\nauto unorderedUsers = query.reorder().get();\n')),(0,r.kt)("p",null,"You may pass a column and direction when calling the ",(0,r.kt)("inlineCode",{parentName:"p"},"reorder"),' method in order to remove all existing "order by" clauses and apply an entirely new order to the query:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto &query = DB::table("users")->orderBy("name");\n\nauto usersOrderedByEmail = query.reorder("email", "desc").get();\n')),(0,r.kt)("h3",{id:"grouping"},"Grouping"),(0,r.kt)("h4",{id:"the-groupby--having-methods"},"The ",(0,r.kt)("inlineCode",{parentName:"h4"},"groupBy")," & ",(0,r.kt)("inlineCode",{parentName:"h4"},"having")," Methods"),(0,r.kt)("p",null,"As you might expect, the ",(0,r.kt)("inlineCode",{parentName:"p"},"groupBy")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"having")," methods may be used to group the query results. The ",(0,r.kt)("inlineCode",{parentName:"p"},"having")," method's signature is similar to that of the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->groupBy("account_id")\n .having("account_id", ">", 100)\n .get();\n')),(0,r.kt)("p",null,"You may pass multiple items to the ",(0,r.kt)("inlineCode",{parentName:"p"},"groupBy")," method to group by multiple columns:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->groupBy({"first_name", "status"})\n .having("account_id", ">", 100)\n .get();\n')),(0,r.kt)("h3",{id:"limit-and-offset"},"Limit & Offset"),(0,r.kt)("h4",{id:"the-skip--take-methods"},"The ",(0,r.kt)("inlineCode",{parentName:"h4"},"skip")," & ",(0,r.kt)("inlineCode",{parentName:"h4"},"take")," Methods"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"skip")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"take")," methods to limit the number of results returned from the query or to skip a given number of results in the query:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")->skip(10).take(5).get();\n')),(0,r.kt)("p",null,"Alternatively, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"limit")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"offset")," methods. These methods are functionally equivalent to the ",(0,r.kt)("inlineCode",{parentName:"p"},"take")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"skip")," methods, respectively:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->offset(10)\n .limit(5)\n .get();\n')),(0,r.kt)("h2",{id:"insert-statements"},"Insert Statements"),(0,r.kt)("p",null,"The query builder also provides an ",(0,r.kt)("inlineCode",{parentName:"p"},"insert")," method that may be used to insert records into the database table. The ",(0,r.kt)("inlineCode",{parentName:"p"},"insert")," method accepts the ",(0,r.kt)("inlineCode",{parentName:"p"},"QVariantMap")," of column names and values:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->insert({\n {"email", "kayla@example.com"},\n {"votes", 0},\n});\n')),(0,r.kt)("a",{id:"multi-insert-overload"}),(0,r.kt)("p",null,"You may insert several records at once by passing a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," for column names as the first argument and ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector>")," for values as the second argument. Each ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->insert({"email", "votes"},\n{\n {"picard@example.com", 0},\n {"janeway@example.com", 0},\n});\n')),(0,r.kt)("p",null,"You may also insert several records at once by passing a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector"),". Each ",(0,r.kt)("inlineCode",{parentName:"p"},"QVariantMap")," represents a record that should be inserted into the table:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->insert({\n {{"email", "picard@example.com"}, {"votes", 0}},\n {{"email", "janeway@example.com"}, {"votes", 0}},\n});\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"insertOrIgnore")," method will ignore duplicate record errors while inserting records into the database and also provides the same overloads like the ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"insertOrIgnore")," will ",(0,r.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/en/sql-mode.html#ignore-effect-on-execution"},"bypass MySQL's strict mode"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"auto-incrementing-ids"},"Auto-Incrementing IDs"),(0,r.kt)("p",null,"If the table has an auto-incrementing id, use the ",(0,r.kt)("inlineCode",{parentName:"p"},"insertGetId")," method to insert a record and then retrieve the ID:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto id = DB::table("users")->insertGetId({\n {"email", "john@example.com"},\n {"votes", 0},\n});\n')),(0,r.kt)("h3",{id:"upserts"},"Upserts"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"In the example above, TinyORM will attempt to insert two records. If a record already exists with the same ",(0,r.kt)("inlineCode",{parentName:"p"},"departure")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"destination")," column values, TinyORM will update that record's ",(0,r.kt)("inlineCode",{parentName:"p"},"price")," column."),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"All databases except SQL Server require the columns in the second argument of the ",(0,r.kt)("inlineCode",{parentName:"p"},"upsert"),' method to have a "primary" or "unique" index. In addition, the MySQL database driver ignores the second argument of the ',(0,r.kt)("inlineCode",{parentName:"p"},"upsert"),' method and always uses the "primary" and "unique" indexes of the table to detect existing records.')),(0,r.kt)("admonition",{type:"info"},(0,r.kt)("p",{parentName:"admonition"},"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.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.1/en/insert-on-duplicate.html"},"documentation"),". The MySQL server version is auto-detected and can be overridden in the ",(0,r.kt)("a",{parentName:"p",href:"/database/getting-started#configuration"},"configuration"),".")),(0,r.kt)("h2",{id:"update-statements"},"Update Statements"),(0,r.kt)("p",null,"In addition to inserting records into the database, the query builder can also update existing records using the ",(0,r.kt)("inlineCode",{parentName:"p"},"update")," method. The ",(0,r.kt)("inlineCode",{parentName:"p"},"update")," method, accepts a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," of column and value pairs, indicating the columns to be updated and returns a ",(0,r.kt)("inlineCode",{parentName:"p"},"std::tuple")," . You may constrain the ",(0,r.kt)("inlineCode",{parentName:"p"},"update")," query using ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," clauses:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto [affected, query] = DB::table("users")\n ->whereEq("id", 1)\n .update({{"votes", 1}});\n')),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"An ",(0,r.kt)("inlineCode",{parentName:"p"},"update")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"delete")," are affecting statements, so they return ",(0,r.kt)("inlineCode",{parentName:"p"},"std::tuple"),".")),(0,r.kt)("h4",{id:"update-or-insert"},"Update Or Insert"),(0,r.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"updateOrInsert")," method may be used. The ",(0,r.kt)("inlineCode",{parentName:"p"},"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."),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")\n ->updateOrInsert(\n {{"email", "john@example.com"}, {"name", "John"}},\n {{"votes", 2}}\n );\n')),(0,r.kt)("h3",{id:"increment-and-decrement"},"Increment & Decrement"),(0,r.kt)("p",null,"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->increment("votes");\n\nDB::table("users")->increment("votes", 5);\n\nDB::table("users")->decrement("votes");\n\nDB::table("users")->decrement("votes", 5.2); // float or double type\n')),(0,r.kt)("p",null,"You may also specify additional columns to update during the operation as a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->increment("votes", 1, {{"name", "John"}});\n')),(0,r.kt)("p",null,"You should constrain ",(0,r.kt)("inlineCode",{parentName:"p"},"increment"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"decrement")," by ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," to update only specific record in the database, otherwise a column in all records will be modified."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->whereEq("id", 1).increment("votes", 5);\n')),(0,r.kt)("h2",{id:"delete-statements"},"Delete Statements"),(0,r.kt)("p",null,"The query builder's ",(0,r.kt)("inlineCode",{parentName:"p"},"remove"),", or an alias ",(0,r.kt)("inlineCode",{parentName:"p"},"deleteRow")," method may be used to delete records from the table. You may constrain ",(0,r.kt)("inlineCode",{parentName:"p"},"delete"),' statements by adding "where" clauses before calling the ',(0,r.kt)("inlineCode",{parentName:"p"},"delete")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->remove();\n\nDB::table("users")->where("votes", ">", 100).remove();\n')),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},(0,r.kt)("inlineCode",{parentName:"p"},"delete")," can not be used as the method name because it is the reserved word.")),(0,r.kt)("p",null,"You may also pass record ",(0,r.kt)("inlineCode",{parentName:"p"},"id")," to the ",(0,r.kt)("inlineCode",{parentName:"p"},"remove")," method as the first argument, it is the shortcut method, which internally calls ",(0,r.kt)("inlineCode",{parentName:"p"},"where"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->remove(2);\n')),(0,r.kt)("h3",{id:"truncate-statement"},"Truncate Statement"),(0,r.kt)("p",null,"If you wish to truncate an entire table, which will remove all records from the table and reset the auto-incrementing ID to zero, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"truncate")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->truncate();\n')),(0,r.kt)("h4",{id:"table-truncation--postgresql"},"Table Truncation & PostgreSQL"),(0,r.kt)("p",null,"When truncating a PostgreSQL database, the ",(0,r.kt)("inlineCode",{parentName:"p"},"CASCADE")," behavior will be applied. This means that all foreign key related records in other tables will be deleted as well."),(0,r.kt)("h2",{id:"pessimistic-locking"},"Pessimistic Locking"),(0,r.kt)("p",null,'The query builder also includes a few functions to help you achieve "pessimistic locking" when executing your ',(0,r.kt)("inlineCode",{parentName:"p"},"select"),' statements. To execute a statement with a "shared lock", you may call the ',(0,r.kt)("inlineCode",{parentName:"p"},"sharedLock")," method. A shared lock prevents the selected rows from being modified until your transaction is committed:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")\n ->where("votes", ">", 100)\n .sharedLock()\n .get();\n')),(0,r.kt)("p",null,"Alternatively, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"lockForUpdate"),' method. A "for update" lock prevents the selected records from being modified or from being selected with another shared lock:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")\n ->where("votes", ">", 100)\n .lockForUpdate()\n .get();\n')),(0,r.kt)("h2",{id:"debugging"},"Debugging"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"dd")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"dump")," methods while building a query to dump the current query bindings and SQL. The ",(0,r.kt)("inlineCode",{parentName:"p"},"dd")," method will display the debug information and then stop executing using the ",(0,r.kt)("inlineCode",{parentName:"p"},"exit(1)"),". The ",(0,r.kt)("inlineCode",{parentName:"p"},"dump")," method will display the debug information and continue executing:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->where("votes", ">", 100).dd();\n\nDB::table("users")->where("votes", ">", 100).dump();\n')))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[594],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>c});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),u=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},p="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},h=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,o=e.originalType,s=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),p=u(n),h=r,c=p["".concat(s,".").concat(h)]||p[h]||m[h]||o;return n?a.createElement(c,i(i({ref:t},d),{},{components:n})):a.createElement(c,i({ref:t},d))}));function c(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=n.length,i=new Array(o);i[0]=h;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:r,i[1]=l;for(var u=2;u{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>l,toc:()=>u});var a=n(7462),r=(n(7294),n(3905));const o={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"]},i="Database: Query Builder",l={unversionedId:"database/query-builder",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,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/database/query-builder.mdx",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"}},s={},u=[{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}],d={toc:u},p="wrapper";function m(e){let{components:t,...n}=e;return(0,r.kt)(p,(0,a.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"database-query-builder"},"Database: Query Builder"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#running-database-queries"},"Running Database Queries"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#chunking-results"},"Chunking Results")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#aggregates"},"Aggregates")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#select-statements"},"Select Statements")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#raw-expressions"},"Raw Expressions")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#joins"},"Joins")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#basic-where-clauses"},"Basic Where Clauses"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#where-clauses"},"Where Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#or-where-clauses"},"Or Where Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#where-not-clauses"},"Where Not Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#additional-where-clauses"},"Additional Where Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#condition-operator-overriding"},"Condition Operator Overriding")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#logical-grouping"},"Logical Grouping")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#advanced-where-clauses"},"Advanced Where Clauses"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#where-exists-clauses"},"Where Exists Clauses")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#subquery-where-clauses"},"Subquery Where Clauses")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#ordering-grouping-limit-and-offset"},"Ordering, Grouping, Limit & Offset"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#ordering"},"Ordering")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#grouping"},"Grouping")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#limit-and-offset"},"Limit & Offset")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#insert-statements"},"Insert Statements"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#upserts"},"Upserts")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#update-statements"},"Update Statements"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#increment-and-decrement"},"Increment & Decrement")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#delete-statements"},"Delete Statements"),(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#truncate-statement"},"Truncate Statement")))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#pessimistic-locking"},"Pessimistic Locking")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#debugging"},"Debugging"))),(0,r.kt)("h2",{id:"introduction"},"Introduction"),(0,r.kt)("p",null,"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."),(0,r.kt)("p",null,"The TinyORM query builder uses ",(0,r.kt)("inlineCode",{parentName:"p"},"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."),(0,r.kt)("admonition",{type:"danger"},(0,r.kt)("p",{parentName:"admonition"},(0,r.kt)("inlineCode",{parentName:"p"},"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.')),(0,r.kt)("admonition",{type:"danger"},(0,r.kt)("p",{parentName:"admonition"},"The ",(0,r.kt)("inlineCode",{parentName:"p"},"QMYSQL")," Qt driver contains a bug, if your table contains a ",(0,r.kt)("inlineCode",{parentName:"p"},"json")," column type, then you must explicitly name columns other than ",(0,r.kt)("inlineCode",{parentName:"p"},"json")," columns instead of the ",(0,r.kt)("inlineCode",{parentName:"p"},"*")," 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.kt)("inlineCode",{parentName:"p"},"QPSQL")," driver returns correct results and doesn't have problem with ",(0,r.kt)("inlineCode",{parentName:"p"},"json")," columns. It was fixed in the Qt 5.15.12, 6.2.7, 6.5.0 ",(0,r.kt)("a",{parentName:"p",href:"https://bugreports.qt.io/browse/QTBUG-101680"},"QTBUG-101680"),".")),(0,r.kt)("h2",{id:"running-database-queries"},"Running Database Queries"),(0,r.kt)("h4",{id:"retrieving-all-rows-from-a-table"},"Retrieving All Rows From A Table"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"table")," method provided by the ",(0,r.kt)("inlineCode",{parentName:"p"},"DB")," facade to begin a query. The ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"get")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"get")," method returns a ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," containing the results of the query where each result can be accessed by ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery::next")," method, look into the ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery"),' documentation how to obtain results from the "query". You may access each column\'s value by ',(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery::value")," method. The first ",(0,r.kt)("inlineCode",{parentName:"p"},"bool")," return value is the value returned from ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery::exec")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\n#include \n\nauto users = DB::table("users")->get();\n\nwhile(users.next())\n qDebug() << users.value("name").toString();\n')),(0,r.kt)("h4",{id:"retrieving-a-single-row--column-from-a-table"},"Retrieving A Single Row / Column From A Table"),(0,r.kt)("p",null,"If you just need to retrieve a single row from a database table, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"QueryBuilder::first")," method. This method will return a ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery")," object, on which was internally called ",(0,r.kt)("inlineCode",{parentName:"p"},"QSqlQuery::first")," method. This method retrieves the first record in the result, if available, and positions the query on the retrieved record:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto user = DB::table("users")->whereEq("name", "John").first();\n\nuser.value("email").toString();\n')),(0,r.kt)("p",null,"If you don't need an entire row, you may extract a single value from a record using the ",(0,r.kt)("inlineCode",{parentName:"p"},"value")," method. This method will return the value of the column directly as ",(0,r.kt)("inlineCode",{parentName:"p"},"QVariant"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto email = DB::table("users")->whereEq("name", "John").value("email").toString();\n')),(0,r.kt)("p",null,"To retrieve a single row by its ",(0,r.kt)("inlineCode",{parentName:"p"},"id")," column value, use the ",(0,r.kt)("inlineCode",{parentName:"p"},"find")," method. This method retrieves the first record in the result, if available, and positions the query on the retrieved record:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto user = DB::table("users")->find(3);\n\nuser.value("email").toString();\n')),(0,r.kt)("h4",{id:"retrieving-a-list-of-column-values"},"Retrieving A List Of Column Values"),(0,r.kt)("p",null,"If you would like to retrieve the ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," instance containing the values of a single column, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"pluck")," method. In this example, we'll retrieve a collection of user titles:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\n#include \n\nconst auto titles = DB::table("users")->pluck("title");\n\nfor (const auto &title : titles)\n qDebug() << title.value();\n')),(0,r.kt)("p",null," You may specify the column that the resulting collection should use as its keys by providing a second argument to the ",(0,r.kt)("inlineCode",{parentName:"p"},"pluck")," method, following example returns the ",(0,r.kt)("inlineCode",{parentName:"p"},"std::map"),' of "titles" keyed by "names":'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\nauto titles = DB::table("users")->pluck("title", "name");\n\nfor (auto &&[name, title] : titles)\n qDebug() << name << ":" << title.value();\n')),(0,r.kt)("p",null,"You may also use ",(0,r.kt)("inlineCode",{parentName:"p"},'pluck("name", "id")'),", it returns the ",(0,r.kt)("inlineCode",{parentName:"p"},"std::map"),' of "names" keyed by its "ids".'),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"This second ",(0,r.kt)("inlineCode",{parentName:"p"},"pluck")," overload returns ",(0,r.kt)("inlineCode",{parentName:"p"},"std::map")," so you have to provide a template argument for the key type.")),(0,r.kt)("h4",{id:"concatenate-column-values"},"Concatenate column values"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"implode")," method can be used to join column values. For example, you may use this method to concatenate prices with the ",(0,r.kt)("inlineCode",{parentName:"p"},", ")," character as the glue:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("orders")->where("price", ">", 100).implode("price", ", ");\n')),(0,r.kt)("h3",{id:"chunking-results"},"Chunking Results"),(0,r.kt)("p",null,"If you need to work with thousands of database records, consider using the ",(0,r.kt)("inlineCode",{parentName:"p"},"chunk")," method provided by the ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"users")," table in chunks of 100 records at a time:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"You may stop further chunks from being processed by returning ",(0,r.kt)("inlineCode",{parentName:"p"},"false")," from the closure:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->orderBy("id").chunk(100, [](QSqlQuery &users, const int page)\n{\n // Process the records...\n\n return false;\n});\n')),(0,r.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"chunkById")," method instead. This method will automatically paginate the results based on the record's primary key:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"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.kt)("inlineCode",{parentName:"p"},"chunkById")," method.")),(0,r.kt)("h3",{id:"aggregates"},"Aggregates"),(0,r.kt)("p",null,"The query builder also provides a variety of methods for retrieving aggregate values like ",(0,r.kt)("inlineCode",{parentName:"p"},"count"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"max"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"min"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"avg"),", and ",(0,r.kt)("inlineCode",{parentName:"p"},"sum"),". You may call any of these methods after constructing your query:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\nauto users = DB::table("users")->count();\n\nauto price = DB::table("orders")->max("price");\n')),(0,r.kt)("p",null,"Of course, you may combine these methods with other clauses to fine-tune how your aggregate value is calculated:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto price = DB::table("orders")\n ->whereEq("finalized", 1)\n .avg("price");\n')),(0,r.kt)("h4",{id:"determining-if-records-exist"},"Determining If Records Exist"),(0,r.kt)("p",null,"Instead of using the ",(0,r.kt)("inlineCode",{parentName:"p"},"count")," method to determine if any records exist that match your query's constraints, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"exists")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"doesntExist")," methods:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'if (DB::table("orders")->whereEq("finalized", 1).exists()) {\n // ...\n}\n\nif (DB::table("orders")->whereEq("finalized", 1).doesntExist()) {\n // ...\n}\n')),(0,r.kt)("h2",{id:"select-statements"},"Select Statements"),(0,r.kt)("h4",{id:"specifying-a-select-clause"},"Specifying A Select Clause"),(0,r.kt)("p",null,"You may not always want to select all columns from a database table. Using the ",(0,r.kt)("inlineCode",{parentName:"p"},"select"),' method, you can specify a custom "select" clause for the query:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#include \n\nauto users = DB::table("users")\n ->select({"name", "email as user_email"})\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"distinct")," method allows you to force the query to return distinct results:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")->distinct().get();\n')),(0,r.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"addSelect")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto query = DB::table("users")->select("name");\n\nauto users = query.addSelect("age").get();\n')),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"You can also pass subqueries to the ",(0,r.kt)("inlineCode",{parentName:"p"},"select")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"addSelect")," methods. A subquery can be a lambda expression, raw string, or the ",(0,r.kt)("inlineCode",{parentName:"p"},"QueryBuilder")," instance.")),(0,r.kt)("h2",{id:"raw-expressions"},"Raw Expressions"),(0,r.kt)("p",null,"Sometimes you may need to insert an arbitrary string into a query. To create a raw string expression, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"raw")," method provided by the ",(0,r.kt)("inlineCode",{parentName:"p"},"DB")," facade:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->select(DB::raw("count(*) as user_count, status"))\n .where("status", "<>", 1)\n .groupBy("status")\n .get();\n')),(0,r.kt)("admonition",{type:"danger"},(0,r.kt)("p",{parentName:"admonition"},"Raw statements will be injected into the query as strings, so you should be extremely careful to avoid creating SQL injection vulnerabilities.")),(0,r.kt)("h3",{id:"raw-methods"},"Raw Methods"),(0,r.kt)("p",null,"Instead of using the ",(0,r.kt)("inlineCode",{parentName:"p"},"DB::raw")," method, you may also use the following methods to insert a raw expression into various parts of your query. ",(0,r.kt)("strong",{parentName:"p"},"Remember, TinyORM can not guarantee that any query using raw expressions is protected against SQL injection vulnerabilities.")),(0,r.kt)("h4",{id:"selectraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"selectRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"selectRaw")," method can be used in place of ",(0,r.kt)("inlineCode",{parentName:"p"},"addSelect(DB::raw(...))"),". This method accepts an optional vector of bindings as its second argument:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto orders = DB::table("orders")\n ->selectRaw("price * ? as price_with_tax", {1.0825})\n .get();\n')),(0,r.kt)("h4",{id:"fromraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"fromRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"fromRaw"),' method may be used to provide a raw string as the value of the "from" clause:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"whereraw--orwhereraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"whereRaw / orWhereRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereRaw")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"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:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto orders = DB::table("orders")\n ->whereRaw("price > IF(state = \\"TX\\", ?, 100)", {200})\n .get();\n')),(0,r.kt)("h3",{id:"groupbyraw"},(0,r.kt)("inlineCode",{parentName:"h3"},"groupByRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"groupByRaw")," method may be used to provide a raw string as the value of the ",(0,r.kt)("inlineCode",{parentName:"p"},"group by")," clause:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto orders = DB::table("orders")\n ->select({"city", "state"})\n .groupByRaw("city, state")\n .get();\n')),(0,r.kt)("h4",{id:"havingraw--orhavingraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"havingRaw / orHavingRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"havingRaw")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"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:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"orderbyraw"},(0,r.kt)("inlineCode",{parentName:"h4"},"orderByRaw")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"orderByRaw"),' method may be used to provide a raw string as the value of the "order by" clause:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto orders = DB::table("orders")\n ->orderByRaw("updated_at - created_at DESC")\n .get();\n')),(0,r.kt)("h2",{id:"joins"},"Joins"),(0,r.kt)("h4",{id:"inner-join-clause"},"Inner Join Clause"),(0,r.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"join")," method on a query builder instance. The first argument passed to the ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("h4",{id:"left-join--right-join-clause"},"Left Join / Right Join Clause"),(0,r.kt)("p",null,'If you would like to perform a "left join" or "right join" instead of an "inner join", use the ',(0,r.kt)("inlineCode",{parentName:"p"},"leftJoin")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"rightJoin")," methods. These methods have the same signature as the ",(0,r.kt)("inlineCode",{parentName:"p"},"join")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"cross-join-clause"},"Cross Join Clause"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"crossJoin"),' method to perform a "cross join". Cross joins generate a cartesian product between the first table and the joined table:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto sizes = DB::table("sizes")\n ->crossJoin("colors")\n .get();\n')),(0,r.kt)("h4",{id:"advanced-join-clauses"},"Advanced Join Clauses"),(0,r.kt)("p",null,"You may also specify more advanced join clauses. To get started, pass a lambda expression as the second argument to the ",(0,r.kt)("inlineCode",{parentName:"p"},"join")," method. The lambda expression will receive a ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::Query::JoinClause"),' instance which allows you to specify constraints on the "join" clause:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("p",null,'If you would like to use a "where" clause on your joins, you may use the ',(0,r.kt)("inlineCode",{parentName:"p"},"where")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhere")," methods provided by the ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::Query::JoinClause")," instance. Instead of comparing two columns, these methods will compare the column against a value:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"subquery-joins"},"Subquery Joins"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"joinSub"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"leftJoinSub"),", and ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"created_at")," timestamp of the user's most recently published blog post:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h2",{id:"basic-where-clauses"},"Basic Where Clauses"),(0,r.kt)("h3",{id:"where-clauses"},"Where Clauses"),(0,r.kt)("p",null,"You may use the query builder's ",(0,r.kt)("inlineCode",{parentName:"p"},"where"),' method to add "where" clauses to the query. The most basic call to the ',(0,r.kt)("inlineCode",{parentName:"p"},"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."),(0,r.kt)("p",null,"For example, the following query retrieves users where the value of the ",(0,r.kt)("inlineCode",{parentName:"p"},"votes")," column is equal to ",(0,r.kt)("inlineCode",{parentName:"p"},"100")," and the value of the ",(0,r.kt)("inlineCode",{parentName:"p"},"age")," column is greater than ",(0,r.kt)("inlineCode",{parentName:"p"},"35"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where("votes", "=", 100)\n .where("age", ">", 35)\n .get();\n')),(0,r.kt)("p",null,"For convenience, if you want to verify that a column is ",(0,r.kt)("inlineCode",{parentName:"p"},"=")," to a given value, you may call ",(0,r.kt)("inlineCode",{parentName:"p"},"whereEq")," method. Similar ",(0,r.kt)("inlineCode",{parentName:"p"},"XxxEq")," methods are also defined for other commands:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")->whereEq("votes", 100).get();\n')),(0,r.kt)("p",null,"As previously mentioned, you may use any operator that is supported by your database system:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"You may also pass a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," of conditions to the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," function. Each ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::WhereItem")," structure should contain the four arguments typically passed to the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where({\n {"status", 1}, // "=" by default\n {"subscribed", 1, "<>"},\n }).get();\n')),(0,r.kt)("h3",{id:"or-where-clauses"},"Or Where Clauses"),(0,r.kt)("p",null,"When chaining together calls to the query builder's ",(0,r.kt)("inlineCode",{parentName:"p"},"where"),' method, the "where" clauses will be joined together using the ',(0,r.kt)("inlineCode",{parentName:"p"},"and")," operator. However, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhere")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhereEq")," method to join a clause to the query using the ",(0,r.kt)("inlineCode",{parentName:"p"},"or")," operator. The ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhere")," method accepts the same arguments as the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where("votes", ">", 100)\n .orWhere("name", "=", "John")\n .orWhereEq("name", "Jack")\n .get();\n')),(0,r.kt)("p",null,'If you need to group an "or" condition within parentheses, you may pass a lambda expression as the first argument to the ',(0,r.kt)("inlineCode",{parentName:"p"},"orWhere")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"The example above will produce the following SQL:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sql"},'select * from users where votes > 100 or (name = "Abigail" and votes > 50)\n')),(0,r.kt)("h3",{id:"condition-operator-overriding"},"Condition Operator Overriding"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method overload with a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," as the first argument joins conditions using the ",(0,r.kt)("inlineCode",{parentName:"p"},"and")," operator by default:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"votes", 50, ">"},\n }).get();\n')),(0,r.kt)("p",null,"Conditions operator can be overridden by the fourth argument in the ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::WhereItem")," structure:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"votes", 50, ">", "or"},\n }).get();\n')),(0,r.kt)("p",null,"Or by the second ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"Orm::WhereItem")," structure:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->where({\n {"first_name", "John"},\n {"last_name", "Smith"},\n {"votes", 50, ">", "and"},\n }, "or")\n .get();\n')),(0,r.kt)("p",null,"The example above will produce the following SQL:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sql"},'select * from users where (first_name = "John" or last_name = "Smith" and votes > 50)\n')),(0,r.kt)("admonition",{type:"tip"},(0,r.kt)("p",{parentName:"admonition"},"Still, it is a better idea to use ",(0,r.kt)("a",{parentName:"p",href:"#logical-grouping"},"Logical Grouping")," described few lines below, which allows better control of the parentheses.")),(0,r.kt)("h3",{id:"where-not-clauses"},"Where Not Clauses"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNot")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto products = DB::table("products")\n ->whereNot([](auto &query) {\n query.whereEq("clearance", true)\n .orWhere("price", "<", 10);\n })\n .get();\n')),(0,r.kt)("h3",{id:"additional-where-clauses"},"Additional Where Clauses"),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereBetween / orWhereBetween")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereBetween")," method verifies that a column's value is between two values:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereBetween("votes", {1, 100})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereNotBetween / orWhereNotBetween")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNotBetween")," method verifies that a column's value lies outside of two values:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereNotBetween("votes", {1, 100})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereBetweenColumns / orWhereBetweenColumns")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereBetweenColumns")," method verifies that a column's value is between two values in given columns:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto files = DB::table("files")\n ->whereBetweenColumns("quota", {"min_allowed_quota", "max_allowed_quota"})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereNotBetweenColumns / orWhereNotBetweenColumns")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNotBetweenColumns")," method verifies that a column's value lies outside of two values in given columns:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto files = DB::table("files")\n ->whereNotBetweenColumns("quota", {"min_allowed_quota", "max_allowed_quota"})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereIn / whereNotIn / orWhereIn / orWhereNotIn")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereIn")," method verifies that a given column's value is contained within the given ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereIn("id", {1, 2, 3})\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNotIn")," method verifies that the given column's value is not contained in the given ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereNotIn("id", {1, 2, 3})\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereNull / whereNotNull / orWhereNull / orWhereNotNull")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNull")," method verifies that the value of the given column is ",(0,r.kt)("inlineCode",{parentName:"p"},"NULL"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereNull("updated_at")\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereNotNull")," method verifies that the column's value is not ",(0,r.kt)("inlineCode",{parentName:"p"},"NULL"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereNotNull("updated_at")\n .get();\n')),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereDate / whereTime / whereDay / whereMonth / whereYear")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereDate")," method may be used to compare a column's value against a date:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereDate("created_at", EQ, QDate(2022, 11, 18))\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereTime")," method may be used to compare a column's value against a specific time:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereTime("created_at", "=", QTime(11, 14, 23))\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereDay")," method may be used to compare a column's value against a specific day of the month:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereDay("created_at", "<=", 15)\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereMonth")," method may be used to compare a column's value against a specific month:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereEqMonth("created_at", 12)\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereYear")," method may be used to compare a column's value against a specific year:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereEqYear("created_at", 2016)\n .get();\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereDate")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"whereTime")," methods also accept a ",(0,r.kt)("inlineCode",{parentName:"p"},"QDateTime")," instance or you can pass values as a ",(0,r.kt)("inlineCode",{parentName:"p"},"QString")," in ",(0,r.kt)("inlineCode",{parentName:"p"},"2022-12-31")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"09:15:11")," formats."),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereDay"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"whereMoth"),", and ",(0,r.kt)("inlineCode",{parentName:"p"},"whereYear")," accept ",(0,r.kt)("inlineCode",{parentName:"p"},"QDate")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"QDateTime")," instances, an integral number or a ",(0,r.kt)("inlineCode",{parentName:"p"},"QString")," that contains an integral number."),(0,r.kt)("admonition",{type:"info"},(0,r.kt)("p",{parentName:"admonition"},"All the above methods offer ",(0,r.kt)("inlineCode",{parentName:"p"},"whereEqXyz")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"orWhereXyz")," shortcut methods.")),(0,r.kt)("p",null,(0,r.kt)("strong",{parentName:"p"},"whereColumn / orWhereColumn")),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereColumnEq")," method may be used to verify that two columns are equal:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumnEq("first_name", "last_name")\n .get();\n')),(0,r.kt)("p",null,"You may also pass a comparison operator to the ",(0,r.kt)("inlineCode",{parentName:"p"},"whereColumn")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumn("updated_at", ">", "created_at")\n .get();\n')),(0,r.kt)("p",null,"You may also pass a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," of column comparisons to the ",(0,r.kt)("inlineCode",{parentName:"p"},"whereColumn")," method. These conditions will be joined using the ",(0,r.kt)("inlineCode",{parentName:"p"},"and")," operator:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">"},\n }).get();\n')),(0,r.kt)("p",null,"Conditions operator can also be overridden by the fourth argument in the ",(0,r.kt)("inlineCode",{parentName:"p"},"Orm::WhereColumnItem")," structure:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">", "or"},\n }).get();\n')),(0,r.kt)("p",null,"Or by the second ",(0,r.kt)("inlineCode",{parentName:"p"},"whereColumn")," argument:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->whereColumn({\n {"first_name", "last_name"},\n {"updated_at", "created_at", ">"},\n }, "or")\n .get();\n')),(0,r.kt)("h3",{id:"logical-grouping"},"Logical Grouping"),(0,r.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"orWhere")," method in parentheses in order to avoid unexpected query behavior. To accomplish this, you may pass a lambda expression to the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"As you can see, passing a lambda expression into the ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sql"},'select * from users where name = "John" and (votes > 100 or title = "Admin")\n')),(0,r.kt)("h2",{id:"advanced-where-clauses"},"Advanced Where Clauses"),(0,r.kt)("h3",{id:"where-exists-clauses"},"Where Exists Clauses"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"whereExists"),' method allows you to write "where exists" SQL clauses. The ',(0,r.kt)("inlineCode",{parentName:"p"},"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:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"Alternatively, you may provide a query object to the ",(0,r.kt)("inlineCode",{parentName:"p"},"whereExists")," method instead of a lambda expression:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'// 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')),(0,r.kt)("p",null,"Or directly:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"All of the examples above will produce the following SQL:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sql"},"select * from users\nwhere exists (\n select 1\n from orders\n where orders.user_id = users.id\n)\n")),(0,r.kt)("h3",{id:"subquery-where-clauses"},"Subquery Where Clauses"),(0,r.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"where"),' method. For example, the following query will retrieve all users who have a recent "membership" of a given type:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("p",null,'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.kt)("inlineCode",{parentName:"p"},"where")," method. For example, the following query will retrieve all income records where the amount is less than average;"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'#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')),(0,r.kt)("h2",{id:"ordering-grouping-limit-and-offset"},"Ordering, Grouping, Limit & Offset"),(0,r.kt)("h3",{id:"ordering"},"Ordering"),(0,r.kt)("h4",{id:"the-orderby-method"},"The ",(0,r.kt)("inlineCode",{parentName:"h4"},"orderBy")," Method"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"orderBy")," method allows you to sort the results of the query by a given column. The first argument accepted by the ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"asc")," or ",(0,r.kt)("inlineCode",{parentName:"p"},"desc"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->orderBy("name", "desc")\n .get();\n')),(0,r.kt)("p",null,"To sort by multiple columns, you may simply invoke ",(0,r.kt)("inlineCode",{parentName:"p"},"orderBy")," as many times as necessary:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->orderBy("name", "desc")\n .orderBy("email", "asc")\n .get();\n')),(0,r.kt)("h4",{id:"the-latest--oldest-methods"},"The ",(0,r.kt)("inlineCode",{parentName:"h4"},"latest")," & ",(0,r.kt)("inlineCode",{parentName:"h4"},"oldest")," Methods"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"latest")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"oldest")," methods allow you to easily order results by date. By default, the result will be ordered by the table's ",(0,r.kt)("inlineCode",{parentName:"p"},"created_at")," column. Or, you may pass the column name that you wish to sort by:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto user = DB::table("users")\n ->latest()\n .first();\n')),(0,r.kt)("h4",{id:"random-ordering"},"Random Ordering"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"inRandomOrder")," method may be used to sort the query results randomly. For example, you may use this method to fetch a random user:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto randomUser = DB::table("users")\n ->inRandomOrder()\n .first();\n')),(0,r.kt)("h4",{id:"removing-existing-orderings"},"Removing Existing Orderings"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"reorder"),' method removes all of the "order by" clauses that have previously been applied to the query:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto &query = DB::table("users")->orderBy("name");\n\nauto unorderedUsers = query.reorder().get();\n')),(0,r.kt)("p",null,"You may pass a column and direction when calling the ",(0,r.kt)("inlineCode",{parentName:"p"},"reorder"),' method in order to remove all existing "order by" clauses and apply an entirely new order to the query:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto &query = DB::table("users")->orderBy("name");\n\nauto usersOrderedByEmail = query.reorder("email", "desc").get();\n')),(0,r.kt)("h3",{id:"grouping"},"Grouping"),(0,r.kt)("h4",{id:"the-groupby--having-methods"},"The ",(0,r.kt)("inlineCode",{parentName:"h4"},"groupBy")," & ",(0,r.kt)("inlineCode",{parentName:"h4"},"having")," Methods"),(0,r.kt)("p",null,"As you might expect, the ",(0,r.kt)("inlineCode",{parentName:"p"},"groupBy")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"having")," methods may be used to group the query results. The ",(0,r.kt)("inlineCode",{parentName:"p"},"having")," method's signature is similar to that of the ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->groupBy("account_id")\n .having("account_id", ">", 100)\n .get();\n')),(0,r.kt)("p",null,"You may pass multiple items to the ",(0,r.kt)("inlineCode",{parentName:"p"},"groupBy")," method to group by multiple columns:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->groupBy({"first_name", "status"})\n .having("account_id", ">", 100)\n .get();\n')),(0,r.kt)("h3",{id:"limit-and-offset"},"Limit & Offset"),(0,r.kt)("h4",{id:"the-skip--take-methods"},"The ",(0,r.kt)("inlineCode",{parentName:"h4"},"skip")," & ",(0,r.kt)("inlineCode",{parentName:"h4"},"take")," Methods"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"skip")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"take")," methods to limit the number of results returned from the query or to skip a given number of results in the query:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")->skip(10).take(5).get();\n')),(0,r.kt)("p",null,"Alternatively, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"limit")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"offset")," methods. These methods are functionally equivalent to the ",(0,r.kt)("inlineCode",{parentName:"p"},"take")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"skip")," methods, respectively:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto users = DB::table("users")\n ->offset(10)\n .limit(5)\n .get();\n')),(0,r.kt)("h2",{id:"insert-statements"},"Insert Statements"),(0,r.kt)("p",null,"The query builder also provides an ",(0,r.kt)("inlineCode",{parentName:"p"},"insert")," method that may be used to insert records into the database table. The ",(0,r.kt)("inlineCode",{parentName:"p"},"insert")," method accepts the ",(0,r.kt)("inlineCode",{parentName:"p"},"QVariantMap")," of column names and values:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->insert({\n {"email", "kayla@example.com"},\n {"votes", 0},\n});\n')),(0,r.kt)("a",{id:"multi-insert-overload"}),(0,r.kt)("p",null,"You may insert several records at once by passing a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," for column names as the first argument and ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector>")," for values as the second argument. Each ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->insert({"email", "votes"},\n{\n {"picard@example.com", 0},\n {"janeway@example.com", 0},\n});\n')),(0,r.kt)("p",null,"You may also insert several records at once by passing a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector"),". Each ",(0,r.kt)("inlineCode",{parentName:"p"},"QVariantMap")," represents a record that should be inserted into the table:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->insert({\n {{"email", "picard@example.com"}, {"votes", 0}},\n {{"email", "janeway@example.com"}, {"votes", 0}},\n});\n')),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"insertOrIgnore")," method will ignore duplicate record errors while inserting records into the database and also provides the same overloads like the ",(0,r.kt)("inlineCode",{parentName:"p"},"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.kt)("inlineCode",{parentName:"p"},"insertOrIgnore")," will ",(0,r.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/en/sql-mode.html#ignore-effect-on-execution"},"bypass MySQL's strict mode"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("h4",{id:"auto-incrementing-ids"},"Auto-Incrementing IDs"),(0,r.kt)("p",null,"If the table has an auto-incrementing id, use the ",(0,r.kt)("inlineCode",{parentName:"p"},"insertGetId")," method to insert a record and then retrieve the ID:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto id = DB::table("users")->insertGetId({\n {"email", "john@example.com"},\n {"votes", 0},\n});\n')),(0,r.kt)("h3",{id:"upserts"},"Upserts"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'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')),(0,r.kt)("p",null,"In the example above, TinyORM will attempt to insert two records. If a record already exists with the same ",(0,r.kt)("inlineCode",{parentName:"p"},"departure")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"destination")," column values, TinyORM will update that record's ",(0,r.kt)("inlineCode",{parentName:"p"},"price")," column."),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"All databases except SQL Server require the columns in the second argument of the ",(0,r.kt)("inlineCode",{parentName:"p"},"upsert"),' method to have a "primary" or "unique" index. In addition, the MySQL database driver ignores the second argument of the ',(0,r.kt)("inlineCode",{parentName:"p"},"upsert"),' method and always uses the "primary" and "unique" indexes of the table to detect existing records.')),(0,r.kt)("admonition",{type:"info"},(0,r.kt)("p",{parentName:"admonition"},"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.kt)("a",{parentName:"p",href:"https://dev.mysql.com/doc/refman/8.3/en/insert-on-duplicate.html"},"documentation"),". The MySQL server version is auto-detected and can be overridden in the ",(0,r.kt)("a",{parentName:"p",href:"/database/getting-started#configuration"},"configuration"),".")),(0,r.kt)("h2",{id:"update-statements"},"Update Statements"),(0,r.kt)("p",null,"In addition to inserting records into the database, the query builder can also update existing records using the ",(0,r.kt)("inlineCode",{parentName:"p"},"update")," method. The ",(0,r.kt)("inlineCode",{parentName:"p"},"update")," method, accepts a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector")," of column and value pairs, indicating the columns to be updated and returns a ",(0,r.kt)("inlineCode",{parentName:"p"},"std::tuple")," . You may constrain the ",(0,r.kt)("inlineCode",{parentName:"p"},"update")," query using ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," clauses:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'auto [affected, query] = DB::table("users")\n ->whereEq("id", 1)\n .update({{"votes", 1}});\n')),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"An ",(0,r.kt)("inlineCode",{parentName:"p"},"update")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"delete")," are affecting statements, so they return ",(0,r.kt)("inlineCode",{parentName:"p"},"std::tuple"),".")),(0,r.kt)("h4",{id:"update-or-insert"},"Update Or Insert"),(0,r.kt)("p",null,"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.kt)("inlineCode",{parentName:"p"},"updateOrInsert")," method may be used. The ",(0,r.kt)("inlineCode",{parentName:"p"},"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."),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")\n ->updateOrInsert(\n {{"email", "john@example.com"}, {"name", "John"}},\n {{"votes", 2}}\n );\n')),(0,r.kt)("h3",{id:"increment-and-decrement"},"Increment & Decrement"),(0,r.kt)("p",null,"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:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->increment("votes");\n\nDB::table("users")->increment("votes", 5);\n\nDB::table("users")->decrement("votes");\n\nDB::table("users")->decrement("votes", 5.2); // float or double type\n')),(0,r.kt)("p",null,"You may also specify additional columns to update during the operation as a ",(0,r.kt)("inlineCode",{parentName:"p"},"QVector"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->increment("votes", 1, {{"name", "John"}});\n')),(0,r.kt)("p",null,"You should constrain ",(0,r.kt)("inlineCode",{parentName:"p"},"increment"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"decrement")," by ",(0,r.kt)("inlineCode",{parentName:"p"},"where")," to update only specific record in the database, otherwise a column in all records will be modified."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->whereEq("id", 1).increment("votes", 5);\n')),(0,r.kt)("h2",{id:"delete-statements"},"Delete Statements"),(0,r.kt)("p",null,"The query builder's ",(0,r.kt)("inlineCode",{parentName:"p"},"remove"),", or an alias ",(0,r.kt)("inlineCode",{parentName:"p"},"deleteRow")," method may be used to delete records from the table. You may constrain ",(0,r.kt)("inlineCode",{parentName:"p"},"delete"),' statements by adding "where" clauses before calling the ',(0,r.kt)("inlineCode",{parentName:"p"},"delete")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->remove();\n\nDB::table("users")->where("votes", ">", 100).remove();\n')),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},(0,r.kt)("inlineCode",{parentName:"p"},"delete")," can not be used as the method name because it is the reserved word.")),(0,r.kt)("p",null,"You may also pass record ",(0,r.kt)("inlineCode",{parentName:"p"},"id")," to the ",(0,r.kt)("inlineCode",{parentName:"p"},"remove")," method as the first argument, it is the shortcut method, which internally calls ",(0,r.kt)("inlineCode",{parentName:"p"},"where"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->remove(2);\n')),(0,r.kt)("h3",{id:"truncate-statement"},"Truncate Statement"),(0,r.kt)("p",null,"If you wish to truncate an entire table, which will remove all records from the table and reset the auto-incrementing ID to zero, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"truncate")," method:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->truncate();\n')),(0,r.kt)("h4",{id:"table-truncation--postgresql"},"Table Truncation & PostgreSQL"),(0,r.kt)("p",null,"When truncating a PostgreSQL database, the ",(0,r.kt)("inlineCode",{parentName:"p"},"CASCADE")," behavior will be applied. This means that all foreign key related records in other tables will be deleted as well."),(0,r.kt)("h2",{id:"pessimistic-locking"},"Pessimistic Locking"),(0,r.kt)("p",null,'The query builder also includes a few functions to help you achieve "pessimistic locking" when executing your ',(0,r.kt)("inlineCode",{parentName:"p"},"select"),' statements. To execute a statement with a "shared lock", you may call the ',(0,r.kt)("inlineCode",{parentName:"p"},"sharedLock")," method. A shared lock prevents the selected rows from being modified until your transaction is committed:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")\n ->where("votes", ">", 100)\n .sharedLock()\n .get();\n')),(0,r.kt)("p",null,"Alternatively, you may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"lockForUpdate"),' method. A "for update" lock prevents the selected records from being modified or from being selected with another shared lock:'),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")\n ->where("votes", ">", 100)\n .lockForUpdate()\n .get();\n')),(0,r.kt)("h2",{id:"debugging"},"Debugging"),(0,r.kt)("p",null,"You may use the ",(0,r.kt)("inlineCode",{parentName:"p"},"dd")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"dump")," methods while building a query to dump the current query bindings and SQL. The ",(0,r.kt)("inlineCode",{parentName:"p"},"dd")," method will display the debug information and then stop executing using the ",(0,r.kt)("inlineCode",{parentName:"p"},"exit(1)"),". The ",(0,r.kt)("inlineCode",{parentName:"p"},"dump")," method will display the debug information and continue executing:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'DB::table("users")->where("votes", ">", 100).dd();\n\nDB::table("users")->where("votes", ">", 100).dump();\n')))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/d459b1c4.adf683bd.js b/assets/js/d459b1c4.5ad4f430.js similarity index 99% rename from assets/js/d459b1c4.adf683bd.js rename to assets/js/d459b1c4.5ad4f430.js index 43bf354ab..0d9fc3213 100644 --- a/assets/js/d459b1c4.adf683bd.js +++ b/assets/js/d459b1c4.5ad4f430.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[966],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>k});var i=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function a(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var p=i.createContext({}),s=function(e){var t=i.useContext(p),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},d=function(e){var t=s(e.components);return i.createElement(p.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},c=i.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,p=e.parentName,d=o(e,["components","mdxType","originalType","parentName"]),m=s(n),c=r,k=m["".concat(p,".").concat(c)]||m[c]||u[c]||l;return n?i.createElement(k,a(a({ref:t},d),{},{components:n})):i.createElement(k,a({ref:t},d))}));function k(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,a=new Array(l);a[0]=c;var o={};for(var p in t)hasOwnProperty.call(t,p)&&(o[p]=t[p]);o.originalType=e,o[m]="string"==typeof e?e:r,a[1]=o;for(var s=2;s{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>a,default:()=>u,frontMatter:()=>l,metadata:()=>o,toc:()=>s});var i=n(7462),r=(n(7294),n(3905));const l={sidebar_position:2,sidebar_label:"\ud83d\ude80 Supported Compilers",hide_table_of_contents:!0,description:"Platform requirements, supported compilers and build systems for TinyORM C++ library.",keywords:["c++ orm","supported compilers","supported build systems","tinyorm"]},a="Supported Compilers",o={unversionedId:"supported-compilers",id:"supported-compilers",title:"Supported Compilers",description:"Platform requirements, supported compilers and build systems for TinyORM C++ library.",source:"@site/docs/supported-compilers.mdx",sourceDirName:".",slug:"/supported-compilers",permalink:"/supported-compilers",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/supported-compilers.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,sidebar_label:"\ud83d\ude80 Supported Compilers",hide_table_of_contents:!0,description:"Platform requirements, supported compilers and build systems for TinyORM C++ library.",keywords:["c++ orm","supported compilers","supported build systems","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"\ud83d\udd27 Dependencies",permalink:"/dependencies"},next:{title:"Getting Started",permalink:"/database/getting-started"}},p={},s=[{value:"Windows >=10",id:"windows-10",level:4},{value:"Linux",id:"linux",level:4},{value:"Supported build systems",id:"supported-build-systems",level:2},{value:"Make tools",id:"make-tools",level:5},{value:"Parallel building",id:"parallel-building",level:5}],d={toc:s},m="wrapper";function u(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,i.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"supported-compilers"},"Supported Compilers"),(0,r.kt)("p",null,"Following compilers are backed up by the GitHub Action ",(0,r.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/.github/workflows"},"workflows")," (CI pipelines), these workflows also include more then ",(0,r.kt)("strong",{parentName:"p"},"3269 unit tests")," \ud83d\ude2e\ud83d\udca5."),(0,r.kt)("div",{id:"supported-compilers"},(0,r.kt)("h4",{id:"windows-10"},(0,r.kt)("inlineCode",{parentName:"h4"},"Windows >=10")),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"MSVC 2019 ",(0,r.kt)("inlineCode",{parentName:"li"},">=16.9")),(0,r.kt)("li",{parentName:"ul"},"MSVC 2022 ",(0,r.kt)("inlineCode",{parentName:"li"},">=17")),(0,r.kt)("li",{parentName:"ul"},"MSYS2 UCRT64 GCC ",(0,r.kt)("inlineCode",{parentName:"li"},"10.2")," - ",(0,r.kt)("inlineCode",{parentName:"li"},"12.2")),(0,r.kt)("li",{parentName:"ul"},"MSYS2 UCRT64 Clang ",(0,r.kt)("inlineCode",{parentName:"li"},">=15")),(0,r.kt)("li",{parentName:"ul"},"clang-cl ",(0,r.kt)("inlineCode",{parentName:"li"},">=15")," with MSVC 2019/2022")),(0,r.kt)("h4",{id:"linux"},(0,r.kt)("inlineCode",{parentName:"h4"},"Linux")),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"GCC ",(0,r.kt)("inlineCode",{parentName:"li"},"10.2")," - ",(0,r.kt)("inlineCode",{parentName:"li"},"12.2")),(0,r.kt)("li",{parentName:"ul"},"Clang ",(0,r.kt)("inlineCode",{parentName:"li"},">=15")," ",(0,r.kt)("small",{className:"darker"},"(libstdc++ only)")))),(0,r.kt)("admonition",{type:"tip"},(0,r.kt)("p",{parentName:"admonition"},"You can compile TinyORM with the MSVC 2022 even if Qt doesn't provide binaries for the MSVC 2022, you can link against Qt MSVC 2019 binaries without any limitations.")),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"The ",(0,r.kt)("inlineCode",{parentName:"p"},"macOS")," and Clang with ",(0,r.kt)("inlineCode",{parentName:"p"},"libc++")," are not supported.")),(0,r.kt)("h2",{id:"supported-build-systems"},"Supported build systems"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"CMake")," ",(0,r.kt)("inlineCode",{parentName:"li"},">=3.22")," ",(0,r.kt)("small",{className:"darker"},"(policies <= CMP0128 default to NEW)")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"qmake")," distributed by the Qt Framework")),(0,r.kt)("h5",{id:"make-tools"},"Make tools"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"jom")," - highly recommended with the ",(0,r.kt)("inlineCode",{parentName:"li"},"qmake")," build system on Windows ",(0,r.kt)("small",{className:"darker"},"(replacement for nmake)")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ninja")," - recommended for ",(0,r.kt)("inlineCode",{parentName:"li"},"CMake")," as the make file generator")),(0,r.kt)("h5",{id:"parallel-building"},"Parallel building"),(0,r.kt)("p",null,"You can control parallel building using the following environment variables."),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"CMake - ",(0,r.kt)("inlineCode",{parentName:"li"},"CMAKE_BUILD_PARALLEL_LEVEL")," eg. to ",(0,r.kt)("inlineCode",{parentName:"li"},"10")),(0,r.kt)("li",{parentName:"ul"},"jom - ",(0,r.kt)("inlineCode",{parentName:"li"},"JOMFLAGS")," eg. to ",(0,r.kt)("inlineCode",{parentName:"li"},"j11")),(0,r.kt)("li",{parentName:"ul"},"make - ",(0,r.kt)("inlineCode",{parentName:"li"},"MAKEFLAGS")," eg. to ",(0,r.kt)("inlineCode",{parentName:"li"},"-j10")),(0,r.kt)("li",{parentName:"ul"},"vcpkg - ",(0,r.kt)("inlineCode",{parentName:"li"},"VCPKG_MAX_CONCURRENCY")," eg. to ",(0,r.kt)("inlineCode",{parentName:"li"},"10"))))}u.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[966],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>k});var i=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function a(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var p=i.createContext({}),s=function(e){var t=i.useContext(p),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},d=function(e){var t=s(e.components);return i.createElement(p.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},c=i.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,p=e.parentName,d=o(e,["components","mdxType","originalType","parentName"]),m=s(n),c=r,k=m["".concat(p,".").concat(c)]||m[c]||u[c]||l;return n?i.createElement(k,a(a({ref:t},d),{},{components:n})):i.createElement(k,a({ref:t},d))}));function k(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,a=new Array(l);a[0]=c;var o={};for(var p in t)hasOwnProperty.call(t,p)&&(o[p]=t[p]);o.originalType=e,o[m]="string"==typeof e?e:r,a[1]=o;for(var s=2;s{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>a,default:()=>u,frontMatter:()=>l,metadata:()=>o,toc:()=>s});var i=n(7462),r=(n(7294),n(3905));const l={sidebar_position:2,sidebar_label:"\ud83d\ude80 Supported Compilers",hide_table_of_contents:!0,description:"Platform requirements, supported compilers and build systems for TinyORM C++ library.",keywords:["c++ orm","supported compilers","supported build systems","tinyorm"]},a="Supported Compilers",o={unversionedId:"supported-compilers",id:"supported-compilers",title:"Supported Compilers",description:"Platform requirements, supported compilers and build systems for TinyORM C++ library.",source:"@site/docs/supported-compilers.mdx",sourceDirName:".",slug:"/supported-compilers",permalink:"/supported-compilers",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/supported-compilers.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,sidebar_label:"\ud83d\ude80 Supported Compilers",hide_table_of_contents:!0,description:"Platform requirements, supported compilers and build systems for TinyORM C++ library.",keywords:["c++ orm","supported compilers","supported build systems","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"\ud83d\udd27 Dependencies",permalink:"/dependencies"},next:{title:"Getting Started",permalink:"/database/getting-started"}},p={},s=[{value:"Windows >=10",id:"windows-10",level:4},{value:"Linux",id:"linux",level:4},{value:"Supported build systems",id:"supported-build-systems",level:2},{value:"Make tools",id:"make-tools",level:5},{value:"Parallel building",id:"parallel-building",level:5}],d={toc:s},m="wrapper";function u(e){let{components:t,...n}=e;return(0,r.kt)(m,(0,i.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"supported-compilers"},"Supported Compilers"),(0,r.kt)("p",null,"Following compilers are backed up by the GitHub Action ",(0,r.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyORM/tree/main/.github/workflows"},"workflows")," (CI pipelines), these workflows also include more then ",(0,r.kt)("strong",{parentName:"p"},"3366 unit tests")," \ud83d\ude2e\ud83d\udca5."),(0,r.kt)("div",{id:"supported-compilers"},(0,r.kt)("h4",{id:"windows-10"},(0,r.kt)("inlineCode",{parentName:"h4"},"Windows >=10")),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"MSVC 2019 ",(0,r.kt)("inlineCode",{parentName:"li"},">=16.9")),(0,r.kt)("li",{parentName:"ul"},"MSVC 2022 ",(0,r.kt)("inlineCode",{parentName:"li"},">=17")),(0,r.kt)("li",{parentName:"ul"},"MSYS2 UCRT64 GCC ",(0,r.kt)("inlineCode",{parentName:"li"},"10.2")," - ",(0,r.kt)("inlineCode",{parentName:"li"},"12.2")),(0,r.kt)("li",{parentName:"ul"},"MSYS2 UCRT64 Clang ",(0,r.kt)("inlineCode",{parentName:"li"},">=15")),(0,r.kt)("li",{parentName:"ul"},"clang-cl ",(0,r.kt)("inlineCode",{parentName:"li"},">=15")," with MSVC 2019/2022")),(0,r.kt)("h4",{id:"linux"},(0,r.kt)("inlineCode",{parentName:"h4"},"Linux")),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"GCC ",(0,r.kt)("inlineCode",{parentName:"li"},"10.2")," - ",(0,r.kt)("inlineCode",{parentName:"li"},"12.2")),(0,r.kt)("li",{parentName:"ul"},"Clang ",(0,r.kt)("inlineCode",{parentName:"li"},">=15")," ",(0,r.kt)("small",{className:"darker"},"(libstdc++ only)")))),(0,r.kt)("admonition",{type:"tip"},(0,r.kt)("p",{parentName:"admonition"},"You can compile TinyORM with the MSVC 2022 even if Qt doesn't provide binaries for the MSVC 2022, you can link against Qt MSVC 2019 binaries without any limitations.")),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"The ",(0,r.kt)("inlineCode",{parentName:"p"},"macOS")," and Clang with ",(0,r.kt)("inlineCode",{parentName:"p"},"libc++")," are not supported.")),(0,r.kt)("h2",{id:"supported-build-systems"},"Supported build systems"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"CMake")," ",(0,r.kt)("inlineCode",{parentName:"li"},">=3.22")," ",(0,r.kt)("small",{className:"darker"},"(policies <= CMP0128 default to NEW)")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"qmake")," distributed by the Qt Framework")),(0,r.kt)("h5",{id:"make-tools"},"Make tools"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"jom")," - highly recommended with the ",(0,r.kt)("inlineCode",{parentName:"li"},"qmake")," build system on Windows ",(0,r.kt)("small",{className:"darker"},"(replacement for nmake)")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ninja")," - recommended for ",(0,r.kt)("inlineCode",{parentName:"li"},"CMake")," as the make file generator")),(0,r.kt)("h5",{id:"parallel-building"},"Parallel building"),(0,r.kt)("p",null,"You can control parallel building using the following environment variables."),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"CMake - ",(0,r.kt)("inlineCode",{parentName:"li"},"CMAKE_BUILD_PARALLEL_LEVEL")," eg. to ",(0,r.kt)("inlineCode",{parentName:"li"},"10")),(0,r.kt)("li",{parentName:"ul"},"jom - ",(0,r.kt)("inlineCode",{parentName:"li"},"JOMFLAGS")," eg. to ",(0,r.kt)("inlineCode",{parentName:"li"},"j11")),(0,r.kt)("li",{parentName:"ul"},"make - ",(0,r.kt)("inlineCode",{parentName:"li"},"MAKEFLAGS")," eg. to ",(0,r.kt)("inlineCode",{parentName:"li"},"-j10")),(0,r.kt)("li",{parentName:"ul"},"vcpkg - ",(0,r.kt)("inlineCode",{parentName:"li"},"VCPKG_MAX_CONCURRENCY")," eg. to ",(0,r.kt)("inlineCode",{parentName:"li"},"10"))))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/e19c288b.c1091e7e.js b/assets/js/e19c288b.8ce43523.js similarity index 96% rename from assets/js/e19c288b.c1091e7e.js rename to assets/js/e19c288b.8ce43523.js index 4fbcd409d..2ca4e21b8 100644 --- a/assets/js/e19c288b.c1091e7e.js +++ b/assets/js/e19c288b.8ce43523.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[865],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var l=n.createContext({}),p=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):s(s({},t),e)),r},c=function(e){var t=p(e.components);return n.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),u=p(r),m=o,f=u["".concat(l,".").concat(m)]||u[m]||d[m]||a;return r?n.createElement(f,s(s({ref:t},c),{},{components:r})):n.createElement(f,s({ref:t},c))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,s=new Array(a);s[0]=m;var i={};for(var l in t)hasOwnProperty.call(t,l)&&(i[l]=t[l]);i.originalType=e,i[u]="string"==typeof e?e:o,s[1]=i;for(var p=2;p{r.d(t,{Z:()=>i});var n=r(7294),o=r(6550);const a={apiTable:"apiTable_flxF"};const s=(0,n.forwardRef)(((e,t)=>{let{name:r,children:a}=e;const s=function(e){let t=e;for(;(0,n.isValidElement)(t);)[t]=n.Children.toArray(t.props.children);return t}(a),i=r?`#${r}-${s}`:`#${s}`,l=(0,o.k6)();return n.createElement("tr",{id:s,tabIndex:0,ref:l.location.hash===i?t:void 0,onClick:()=>{l.push(i)},onKeyDown:e=>{"Enter"===e.key&&l.push(i)}},a.props.children)}));function i(e){let{children:t,name:r}=e;const[o,i]=n.Children.toArray(t.props.children),l=(0,n.useRef)(null);(0,n.useEffect)((()=>{l.current?.focus()}),[l]);const p=n.Children.map(i.props.children,(e=>n.createElement(s,{name:r,ref:l},e)));return n.createElement("table",{className:a.apiTable},o,n.createElement("tbody",null,p))}},6903:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>m,frontMatter:()=>s,metadata:()=>l,toc:()=>c});var n=r(7462),o=(r(7294),r(3905)),a=r(5178);const s={sidebar_position:7,sidebar_label:"\u2764\ufe0f Sponsors",hide_table_of_contents:!0,description:"How to sponsor and support the TinyORM project.",keywords:["c++ orm","tinyorm","support","fund","funding","sponsors","donations","sponsors"]},i="Sponsors",l={unversionedId:"sponsors",id:"sponsors",title:"Sponsors",description:"How to sponsor and support the TinyORM project.",source:"@site/docs/sponsors.mdx",sourceDirName:".",slug:"/sponsors",permalink:"/sponsors",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/sponsors.mdx",tags:[],version:"current",sidebarPosition:7,frontMatter:{sidebar_position:7,sidebar_label:"\u2764\ufe0f Sponsors",hide_table_of_contents:!0,description:"How to sponsor and support the TinyORM project.",keywords:["c++ orm","tinyorm","support","fund","funding","sponsors","donations","sponsors"]},sidebar:"tinyormSidebar",previous:{title:"\ud83d\udcc4 Features Summary",permalink:"/features-summary"}},p={},c=[],u={toc:c},d="wrapper";function m(e){let{components:t,...r}=e;return(0,o.kt)(d,(0,n.Z)({},u,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"sponsors"},"Sponsors"),(0,o.kt)("p",null,"I have spent ~2 years every day 10 hours of coding (excluding weekends and sick days) to make this project real. Everything was funded from my personal resources, I had no problem with it to be honest, it was really fun \ud83c\udf89, but I had to move to the new apartment a few months ago and I'm out of money now. \u2639\ufe0f"),(0,o.kt)("p",null,"I would like to continue developing and enhancing this project and I will as long as I can. But the future is unclear now."),(0,o.kt)(a.Z,{mdxType:"APITable"},(0,o.kt)("table",null,(0,o.kt)("thead",{parentName:"table"},(0,o.kt)("tr",{parentName:"thead"},(0,o.kt)("th",{parentName:"tr",align:null},"Service"),(0,o.kt)("th",{parentName:"tr",align:null},"Address"))),(0,o.kt)("tbody",{parentName:"table"},(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"Bitcoin address"),(0,o.kt)("td",{parentName:"tr",align:null},"1NiF2cTvYxUj8FTZJnGn1ycN4yisWfo1vJ")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"PayPal"),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("a",{parentName:"td",href:"https://paypal.me/silverzachara"},"https://paypal.me/silverzachara")))))))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[865],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>f});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var l=n.createContext({}),p=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):s(s({},t),e)),r},c=function(e){var t=p(e.components);return n.createElement(l.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),u=p(r),m=o,f=u["".concat(l,".").concat(m)]||u[m]||d[m]||a;return r?n.createElement(f,s(s({ref:t},c),{},{components:r})):n.createElement(f,s({ref:t},c))}));function f(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,s=new Array(a);s[0]=m;var i={};for(var l in t)hasOwnProperty.call(t,l)&&(i[l]=t[l]);i.originalType=e,i[u]="string"==typeof e?e:o,s[1]=i;for(var p=2;p{r.d(t,{Z:()=>i});var n=r(7294),o=r(6550);const a={apiTable:"apiTable_flxF"};const s=(0,n.forwardRef)(((e,t)=>{let{name:r,children:a}=e;const s=function(e){let t=e;for(;(0,n.isValidElement)(t);)[t]=n.Children.toArray(t.props.children);return t}(a),i=r?`#${r}-${s}`:`#${s}`,l=(0,o.k6)();return n.createElement("tr",{id:s,tabIndex:0,ref:l.location.hash===i?t:void 0,onClick:()=>{l.push(i)},onKeyDown:e=>{"Enter"===e.key&&l.push(i)}},a.props.children)}));function i(e){let{children:t,name:r}=e;const[o,i]=n.Children.toArray(t.props.children),l=(0,n.useRef)(null);(0,n.useEffect)((()=>{l.current?.focus()}),[l]);const p=n.Children.map(i.props.children,(e=>n.createElement(s,{name:r,ref:l},e)));return n.createElement("table",{className:a.apiTable},o,n.createElement("tbody",null,p))}},6903:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>p,contentTitle:()=>i,default:()=>m,frontMatter:()=>s,metadata:()=>l,toc:()=>c});var n=r(7462),o=(r(7294),r(3905)),a=r(5178);const s={sidebar_position:8,sidebar_label:"\u2764\ufe0f Sponsors",hide_table_of_contents:!0,description:"How to sponsor and support the TinyORM project.",keywords:["c++ orm","tinyorm","support","fund","funding","sponsors","donations","sponsors"]},i="Sponsors",l={unversionedId:"sponsors",id:"sponsors",title:"Sponsors",description:"How to sponsor and support the TinyORM project.",source:"@site/docs/sponsors.mdx",sourceDirName:".",slug:"/sponsors",permalink:"/sponsors",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/sponsors.mdx",tags:[],version:"current",sidebarPosition:8,frontMatter:{sidebar_position:8,sidebar_label:"\u2764\ufe0f Sponsors",hide_table_of_contents:!0,description:"How to sponsor and support the TinyORM project.",keywords:["c++ orm","tinyorm","support","fund","funding","sponsors","donations","sponsors"]},sidebar:"tinyormSidebar",previous:{title:"\ud83d\udcc4 Features Summary",permalink:"/features-summary"}},p={},c=[],u={toc:c},d="wrapper";function m(e){let{components:t,...r}=e;return(0,o.kt)(d,(0,n.Z)({},u,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"sponsors"},"Sponsors"),(0,o.kt)("p",null,"I have spent ~2 years every day 10 hours of coding (excluding weekends and sick days) to make this project real. Everything was funded from my personal resources, I had no problem with it to be honest, it was really fun \ud83c\udf89, but I had to move to the new apartment a few months ago and I'm out of money now. \u2639\ufe0f"),(0,o.kt)("p",null,"I would like to continue developing and enhancing this project and I will as long as I can. But the future is unclear now."),(0,o.kt)(a.Z,{mdxType:"APITable"},(0,o.kt)("table",null,(0,o.kt)("thead",{parentName:"table"},(0,o.kt)("tr",{parentName:"thead"},(0,o.kt)("th",{parentName:"tr",align:null},"Service"),(0,o.kt)("th",{parentName:"tr",align:null},"Address"))),(0,o.kt)("tbody",{parentName:"table"},(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"Bitcoin address"),(0,o.kt)("td",{parentName:"tr",align:null},"1NiF2cTvYxUj8FTZJnGn1ycN4yisWfo1vJ")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"PayPal"),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("a",{parentName:"td",href:"https://paypal.me/silverzachara"},"https://paypal.me/silverzachara")))))))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/e3ac21cb.058c6bdf.js b/assets/js/e3ac21cb.f62ee0b6.js similarity index 99% rename from assets/js/e3ac21cb.058c6bdf.js rename to assets/js/e3ac21cb.f62ee0b6.js index e78056318..e0d5c7186 100644 --- a/assets/js/e3ac21cb.058c6bdf.js +++ b/assets/js/e3ac21cb.f62ee0b6.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[8],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>h});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var d=a.createContext({}),p=function(e){var t=a.useContext(d),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},s=function(e){var t=p(e.components);return a.createElement(d.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},u=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,d=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),c=p(n),u=r,h=c["".concat(d,".").concat(u)]||c[u]||m[u]||i;return n?a.createElement(h,o(o({ref:t},s),{},{components:n})):a.createElement(h,o({ref:t},s))}));function h(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,o=new Array(i);o[0]=u;var l={};for(var d in t)hasOwnProperty.call(t,d)&&(l[d]=t[d]);l.originalType=e,l[c]="string"==typeof e?e:r,o[1]=l;for(var p=2;p{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var a=n(7462),r=(n(7294),n(3905));const i={sidebar_position:1,sidebar_label:"\ud83d\udd27 Dependencies",hide_table_of_contents:!0,description:"Library dependencies are MySQL Connector/C 8, range-v3 >=0.11.0, tabulate and the Qt framework version used during development was 5.15.2 and >=6.2. The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16.",keywords:["c++ orm","dependencies","tinyorm"]},o="Dependencies",l={unversionedId:"dependencies",id:"dependencies",title:"Dependencies",description:"Library dependencies are MySQL Connector/C 8, range-v3 >=0.11.0, tabulate and the Qt framework version used during development was 5.15.2 and >=6.2. The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16.",source:"@site/docs/dependencies.mdx",sourceDirName:".",slug:"/dependencies",permalink:"/dependencies",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/dependencies.mdx",tags:[],version:"current",sidebarPosition:1,frontMatter:{sidebar_position:1,sidebar_label:"\ud83d\udd27 Dependencies",hide_table_of_contents:!0,description:"Library dependencies are MySQL Connector/C 8, range-v3 >=0.11.0, tabulate and the Qt framework version used during development was 5.15.2 and >=6.2. The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16.",keywords:["c++ orm","dependencies","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"\ud83d\udd25 Prologue",permalink:"/"},next:{title:"\ud83d\ude80 Supported Compilers",permalink:"/supported-compilers"}},d={},p=[{value:"Required",id:"required",level:5},{value:"Optional",id:"optional",level:5},{value:"Install dependencies",id:"install-dependencies",level:3}],s={toc:p},c="wrapper";function m(e){let{components:t,...n}=e;return(0,r.kt)(c,(0,a.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"dependencies"},"Dependencies"),(0,r.kt)("p",null,"The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16, so may be assumed it will work on future releases of these compilers. Minimum required ISO C++ standard is C++20.\nThe Qt framework version used during development was 5.15.2 and >=6.2."),(0,r.kt)("h5",{id:"required"},"Required"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"minimum ISO C++ standard is C++20"),(0,r.kt)("li",{parentName:"ul"},">","= ",(0,r.kt)("a",{parentName:"li",href:"https://www.qt.io/download-qt-installer"},"Qt Framework 5.15.2")," - ",(0,r.kt)("a",{parentName:"li",href:"https://doc.qt.io/qt-5/qtcore-module.html"},(0,r.kt)("inlineCode",{parentName:"a"},"QtCore"))," and ",(0,r.kt)("a",{parentName:"li",href:"https://doc.qt.io/qt-5/qtsql-index.html"},(0,r.kt)("inlineCode",{parentName:"a"},"QtSql"))," modules"),(0,r.kt)("li",{parentName:"ul"},">","= ",(0,r.kt)("a",{parentName:"li",href:"https://www.qt.io/download-qt-installer"},"Qt Framework 6.2")," - ",(0,r.kt)("a",{parentName:"li",href:"https://doc.qt.io/qt-6/qtcore-module.html"},(0,r.kt)("inlineCode",{parentName:"a"},"QtCore"))," and ",(0,r.kt)("a",{parentName:"li",href:"https://doc.qt.io/qt-6/qtsql-index.html"},(0,r.kt)("inlineCode",{parentName:"a"},"QtSql"))," modules"),(0,r.kt)("li",{parentName:"ul"},">","= ",(0,r.kt)("a",{parentName:"li",href:"https://github.com/ericniebler/range-v3"},"range-v3 0.11.0")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://github.com/p-ranav/tabulate"},"tabulate"))),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"Be aware that the standard support for the last release of the ",(0,r.kt)("strong",{parentName:"p"},"Qt 5")," series ended on ",(0,r.kt)("strong",{parentName:"p"},"26. May 2023"),". [",(0,r.kt)("a",{parentName:"p",href:"https://endoflife.date/qt"},"1"),"][",(0,r.kt)("a",{parentName:"p",href:"https://www.qt.io/blog/qt-5.15-support-ends"},"2"),"]")),(0,r.kt)("h5",{id:"optional"},"Optional"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},">","= ",(0,r.kt)("a",{parentName:"li",href:"https://dev.mysql.com/downloads/c-api/"},"MySQL Connector/C 8")," - used only for the ",(0,r.kt)("a",{parentName:"li",href:"https://dev.mysql.com/doc/c-api/8.1/en/mysql-ping.html"},(0,r.kt)("inlineCode",{parentName:"a"},"mysql_ping"))," function and provided by ",(0,r.kt)("a",{parentName:"li",href:"https://dev.mysql.com/downloads/mysql/"},"MySQL 8 Server"))),(0,r.kt)("admonition",{type:"info"},(0,r.kt)("p",{parentName:"admonition"},"The ",(0,r.kt)("inlineCode",{parentName:"p"},"TinyORM")," will support ",(0,r.kt)("inlineCode",{parentName:"p"},"Qt")," versions that aren't ",(0,r.kt)("a",{parentName:"p",href:"https://endoflife.date/qt"},"end-of-life"),".")),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"You can view the supported database servers in the ",(0,r.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"Database - Getting Started")," section.")),(0,r.kt)("h3",{id:"install-dependencies"},"Install dependencies"),(0,r.kt)("p",null,"On ",(0,r.kt)("inlineCode",{parentName:"p"},"Linux"),", you can install dependencies with the package manager."),(0,r.kt)("small",null,(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-text",metastring:"title='MySQL C library'",title:"'MySQL",C:!0,"library'":!0},"Arch - pacman -S mariadb-libs\nGentoo - emerge dev-db/mysql (package.use: -server -perl)\nUbuntu - apt install libmysqlclient-dev\n")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-text",metastring:"title='range-v3 library (header only)'",title:"'range-v3",library:!0,"(header":!0,"only)'":!0},"Arch - pacman -S range-v3\nGentoo - emerge dev-cpp/range-v3\nUbuntu - apt install librange-v3-dev\n")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-text",metastring:"title='ccache'",title:"'ccache'"},"Arch - pacman -S ccache\nGentoo - emerge dev-util/ccache\nUbuntu - apt install ccache\n"))))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[8],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>h});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var d=a.createContext({}),p=function(e){var t=a.useContext(d),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},s=function(e){var t=p(e.components);return a.createElement(d.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},u=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,d=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),c=p(n),u=r,h=c["".concat(d,".").concat(u)]||c[u]||m[u]||i;return n?a.createElement(h,o(o({ref:t},s),{},{components:n})):a.createElement(h,o({ref:t},s))}));function h(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,o=new Array(i);o[0]=u;var l={};for(var d in t)hasOwnProperty.call(t,d)&&(l[d]=t[d]);l.originalType=e,l[c]="string"==typeof e?e:r,o[1]=l;for(var p=2;p{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var a=n(7462),r=(n(7294),n(3905));const i={sidebar_position:1,sidebar_label:"\ud83d\udd27 Dependencies",hide_table_of_contents:!0,description:"Library dependencies are MySQL Connector/C 8, range-v3 >=0.11.0, tabulate and the Qt framework version used during development was 5.15.2 and >=6.2. The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16.",keywords:["c++ orm","dependencies","tinyorm"]},o="Dependencies",l={unversionedId:"dependencies",id:"dependencies",title:"Dependencies",description:"Library dependencies are MySQL Connector/C 8, range-v3 >=0.11.0, tabulate and the Qt framework version used during development was 5.15.2 and >=6.2. The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16.",source:"@site/docs/dependencies.mdx",sourceDirName:".",slug:"/dependencies",permalink:"/dependencies",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/dependencies.mdx",tags:[],version:"current",sidebarPosition:1,frontMatter:{sidebar_position:1,sidebar_label:"\ud83d\udd27 Dependencies",hide_table_of_contents:!0,description:"Library dependencies are MySQL Connector/C 8, range-v3 >=0.11.0, tabulate and the Qt framework version used during development was 5.15.2 and >=6.2. The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16.",keywords:["c++ orm","dependencies","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"\ud83d\udd25 Prologue",permalink:"/"},next:{title:"\ud83d\ude80 Supported Compilers",permalink:"/supported-compilers"}},d={},p=[{value:"Required",id:"required",level:5},{value:"Optional",id:"optional",level:5},{value:"Install dependencies",id:"install-dependencies",level:3}],s={toc:p},c="wrapper";function m(e){let{components:t,...n}=e;return(0,r.kt)(c,(0,a.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"dependencies"},"Dependencies"),(0,r.kt)("p",null,"The code was developed on MSVC 16.9-16.11, MSVC 17.2-17.5, GCC 10.2-12.2, and Clang 11-16, so may be assumed it will work on future releases of these compilers. Minimum required ISO C++ standard is C++20.\nThe Qt framework version used during development was 5.15.2 and >=6.2."),(0,r.kt)("h5",{id:"required"},"Required"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"minimum ISO C++ standard is C++20"),(0,r.kt)("li",{parentName:"ul"},">","= ",(0,r.kt)("a",{parentName:"li",href:"https://www.qt.io/download-qt-installer"},"Qt Framework 5.15.2")," - ",(0,r.kt)("a",{parentName:"li",href:"https://doc.qt.io/qt-5/qtcore-module.html"},(0,r.kt)("inlineCode",{parentName:"a"},"QtCore"))," and ",(0,r.kt)("a",{parentName:"li",href:"https://doc.qt.io/qt-5/qtsql-index.html"},(0,r.kt)("inlineCode",{parentName:"a"},"QtSql"))," modules"),(0,r.kt)("li",{parentName:"ul"},">","= ",(0,r.kt)("a",{parentName:"li",href:"https://www.qt.io/download-qt-installer"},"Qt Framework 6.2")," - ",(0,r.kt)("a",{parentName:"li",href:"https://doc.qt.io/qt-6/qtcore-module.html"},(0,r.kt)("inlineCode",{parentName:"a"},"QtCore"))," and ",(0,r.kt)("a",{parentName:"li",href:"https://doc.qt.io/qt-6/qtsql-index.html"},(0,r.kt)("inlineCode",{parentName:"a"},"QtSql"))," modules"),(0,r.kt)("li",{parentName:"ul"},">","= ",(0,r.kt)("a",{parentName:"li",href:"https://github.com/ericniebler/range-v3"},"range-v3 0.11.0")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://github.com/p-ranav/tabulate"},"tabulate"))),(0,r.kt)("admonition",{type:"caution"},(0,r.kt)("p",{parentName:"admonition"},"Be aware that the standard support for the last release of the ",(0,r.kt)("strong",{parentName:"p"},"Qt 5")," series ended on ",(0,r.kt)("strong",{parentName:"p"},"26. May 2023"),". [",(0,r.kt)("a",{parentName:"p",href:"https://endoflife.date/qt"},"1"),"][",(0,r.kt)("a",{parentName:"p",href:"https://www.qt.io/blog/qt-5.15-support-ends"},"2"),"]")),(0,r.kt)("h5",{id:"optional"},"Optional"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},">","= ",(0,r.kt)("a",{parentName:"li",href:"https://dev.mysql.com/downloads/c-api/"},"MySQL Connector/C 8")," - used only for the ",(0,r.kt)("a",{parentName:"li",href:"https://dev.mysql.com/doc/c-api/8.3/en/mysql-ping.html"},(0,r.kt)("inlineCode",{parentName:"a"},"mysql_ping"))," function and provided by ",(0,r.kt)("a",{parentName:"li",href:"https://dev.mysql.com/downloads/mysql/"},"MySQL 8 Server"))),(0,r.kt)("admonition",{type:"info"},(0,r.kt)("p",{parentName:"admonition"},"The ",(0,r.kt)("inlineCode",{parentName:"p"},"TinyORM")," will support ",(0,r.kt)("inlineCode",{parentName:"p"},"Qt")," versions that aren't ",(0,r.kt)("a",{parentName:"p",href:"https://endoflife.date/qt"},"end-of-life"),".")),(0,r.kt)("admonition",{type:"note"},(0,r.kt)("p",{parentName:"admonition"},"You can view the supported database servers in the ",(0,r.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"Database - Getting Started")," section.")),(0,r.kt)("h3",{id:"install-dependencies"},"Install dependencies"),(0,r.kt)("p",null,"On ",(0,r.kt)("inlineCode",{parentName:"p"},"Linux"),", you can install dependencies with the package manager."),(0,r.kt)("small",null,(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-text",metastring:"title='MySQL C library'",title:"'MySQL",C:!0,"library'":!0},"Arch - pacman -S mariadb-libs\nGentoo - emerge dev-db/mysql (package.use: -server -perl)\nUbuntu - apt install libmysqlclient-dev\n")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-text",metastring:"title='range-v3 library (header only)'",title:"'range-v3",library:!0,"(header":!0,"only)'":!0},"Arch - pacman -S range-v3\nGentoo - emerge dev-cpp/range-v3\nUbuntu - apt install librange-v3-dev\n")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-text",metastring:"title='ccache'",title:"'ccache'"},"Arch - pacman -S ccache\nGentoo - emerge dev-util/ccache\nUbuntu - apt install ccache\n"))))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/fb313d4e.1faf534f.js b/assets/js/fb313d4e.246c2a2a.js similarity index 77% rename from assets/js/fb313d4e.1faf534f.js rename to assets/js/fb313d4e.246c2a2a.js index 1521e495a..a8c506088 100644 --- a/assets/js/fb313d4e.1faf534f.js +++ b/assets/js/fb313d4e.246c2a2a.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[832],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>y});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var o=n.createContext({}),m=function(e){var t=n.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},u=function(e){var t=m(e.components);return n.createElement(o.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},c=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,i=e.originalType,o=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),p=m(a),c=r,y=p["".concat(o,".").concat(c)]||p[c]||d[c]||i;return a?n.createElement(y,l(l({ref:t},u),{},{components:a})):n.createElement(y,l({ref:t},u))}));function y(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=a.length,l=new Array(i);l[0]=c;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[p]="string"==typeof e?e:r,l[1]=s;for(var m=2;m{a.r(t),a.d(t,{assets:()=>o,contentTitle:()=>l,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>m});var n=a(7462),r=(a(7294),a(3905));const i={sidebar_position:6,sidebar_label:"\ud83d\udcc4 Features Summary",hide_table_of_contents:!0,description:"List that fastly summarizes all TinyORM features.",keywords:["c++ orm","tinyorm","features","summary","features summary"]},l="Features Summary",s={unversionedId:"features-summary",id:"features-summary",title:"Features Summary",description:"List that fastly summarizes all TinyORM features.",source:"@site/docs/features-summary.mdx",sourceDirName:".",slug:"/features-summary",permalink:"/features-summary",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/features-summary.mdx",tags:[],version:"current",sidebarPosition:6,frontMatter:{sidebar_position:6,sidebar_label:"\ud83d\udcc4 Features Summary",hide_table_of_contents:!0,description:"List that fastly summarizes all TinyORM features.",keywords:["c++ orm","tinyorm","features","summary","features summary"]},sidebar:"tinyormSidebar",previous:{title:"Migrations",permalink:"/building/migrations"},next:{title:"\u2764\ufe0f Sponsors",permalink:"/sponsors"}},o={},m=[{value:"Summary List",id:"summary-list",level:2},{value:"Showcase Images",id:"showcase-images",level:2},{value:"Tom console application",id:"tom-console-application",level:6},{value:"Passed all unit tests \ud83e\udd73",id:"passed-all-unit-tests-",level:6},{value:"TinyOrmPlayground",id:"tinyormplayground",level:4},{value:"TinyOrmPlayground single-threaded",id:"tinyormplayground-single-threaded",level:6},{value:"TinyOrmPlayground multi-threaded",id:"tinyormplayground-multi-threaded",level:6}],u={toc:m},p="wrapper";function d(e){let{components:t,...i}=e;return(0,r.kt)(p,(0,n.Z)({},u,i,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"features-summary"},"Features Summary"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#summary-list"},"Summary List")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#showcase-images"},"Showcase Images"))),(0,r.kt)("h2",{id:"summary-list"},"Summary List"),(0,r.kt)("p",null,"The following list fastly summarizes all the ",(0,r.kt)("inlineCode",{parentName:"p"},"TinyORM")," features."),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"simple database connections management")," \ud83e\uddec",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"database manager that helps with the database connections management"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"Orm::DB")," facade class for nicer and shorter syntax"),(0,r.kt)("li",{parentName:"ul"},"MySQL, MariaDB, SQLite, and PostgreSQL support for ",(0,r.kt)("strong",{parentName:"li"},"all")," features \ud83d\udc8e"),(0,r.kt)("li",{parentName:"ul"},"multi-threading support \ud83d\udc40"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"SSL")," connections support \ud83d\udd12"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"impressive query builder")," \ud83d\udd27",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"allows passing sub-queries and raw expressions practically everywhere, to column names, values, and to every SQL clause as select, where, joins, group by, having, order by \ud83d\udd25"),(0,r.kt)("li",{parentName:"ul"},"a logical grouping that offers to wrap logical groups in parenthesis"),(0,r.kt)("li",{parentName:"ul"},"chunked results for lower memory footprint \u2728"),(0,r.kt)("li",{parentName:"ul"},"raw methods for all SQL clauses"),(0,r.kt)("li",{parentName:"ul"},"all join types (left, right, cross, inner) and also join where clause support \ud83e\udee4"),(0,r.kt)("li",{parentName:"ul"},"aggregate methods min, max, sum, increment, decrement, ..."),(0,r.kt)("li",{parentName:"ul"},"whereExists and exists methods for an existence queries"),(0,r.kt)("li",{parentName:"ul"},"transactions and pessimistic locking \ud83d\udd12"),(0,r.kt)("li",{parentName:"ul"},"of course, insert, update, and delete SQL clauses support"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"correct QDateTime time zone")," using the ",(0,r.kt)("inlineCode",{parentName:"li"},"qt_timezone")," connection configuration option \ud83d\udcc5 (returned QDateTime instances will have the correct time zone, and also works for an ORM)",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"this feature allows you to set up the database server time zone to the UTC and all returned QDateTime instances will have the correct UTC time zone"))))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"clever ORM with all relation types support")," \ud83c\udf89",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"one-to-one, one-to-many, and many-to-many relation types (also inverse relationships) \ud83e\udde8"),(0,r.kt)("li",{parentName:"ul"},"eager and lazy loading with custom select and constraints \ud83d\ude80"),(0,r.kt)("li",{parentName:"ul"},"fluent ",(0,r.kt)("inlineCode",{parentName:"li"},"ModelsCollection")," that expose a variety of map / reduce operations that may be chained using an intuitive interface \u2728"),(0,r.kt)("li",{parentName:"ul"},"all query builder methods are proxied from the model instances and also from the relation instances back to the query builder \ud83e\udd2f (everything that can be called on the query builder can also be called on the model and relation instances)"),(0,r.kt)("li",{parentName:"ul"},"clean active record pattern"),(0,r.kt)("li",{parentName:"ul"},"advanced features like timestamps, touching parent timestamps, ",(0,r.kt)("strong",{parentName:"li"},"soft deleting"),", default models, default model attributes, and attribute casting \ud83e\udd13"),(0,r.kt)("li",{parentName:"ul"},"querying relationships existence/absence using the has, whereHas, and hasNested methods (using dot notation for selecting nested relationships ",(0,r.kt)("em",{parentName:"li"},"users.posts.comments"),")"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"serializing")," models and collection of models including all nested relations to ",(0,r.kt)("strong",{parentName:"li"},"JSON")," and converting to vectors and maps \ud83e\udea1",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"supports controlling a custom date format during serialization"),(0,r.kt)("li",{parentName:"ul"},"supports hiding and appending attributes"))))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"compiled database migrations and seeders")," \ud83d\udd7a",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"create, update, drop, and rename database tables"),(0,r.kt)("li",{parentName:"ul"},"create, drop, and rename table columns"),(0,r.kt)("li",{parentName:"ul"},"extensive schema builder that allows creating of all possible column types"),(0,r.kt)("li",{parentName:"ul"},"terser syntax for creating foreign keys and foreign key constraints"),(0,r.kt)("li",{parentName:"ul"},"supports creating, and dropping column indexes (primary, unique, fulltext, spatial)"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"the ",(0,r.kt)("inlineCode",{parentName:"strong"},"tom")," console application with tab completion for all shells (pwsh, bash, zsh)")," \ud83e\udd73",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"scaffolding of models, migrations, and seeders"),(0,r.kt)("li",{parentName:"ul"},"impressive models scaffolding, every feature that is supported by models can be generated using the ",(0,r.kt)("inlineCode",{parentName:"li"},"tom make:model")," cli command"))),(0,r.kt)("li",{parentName:"ul"},"a huge amount of code is unit tested, currently ",(0,r.kt)("strong",{parentName:"li"},"3269 unit tests")," \ud83e\udd2f"),(0,r.kt)("li",{parentName:"ul"},"C++20 only, with all the latest features used like concepts/constraints, ranges, smart pointers (no ",(0,r.kt)("inlineCode",{parentName:"li"},"new")," keyword in the whole code \ud83d\ude0e), folding expressions"),(0,r.kt)("li",{parentName:"ul"},"qmake and CMake build systems support",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"CMake FetchContent module support \ud83e\udd19"))),(0,r.kt)("li",{parentName:"ul"},"vcpkg support (also the vcpkg port, currently not committed to the vcpkg repository \u2639\ufe0f)"),(0,r.kt)("li",{parentName:"ul"},"it's really fast, you can run 1000 complex queries in 500ms (heavily DB dependant, the PostgreSQL is by far the fastest) \u231a"),(0,r.kt)("li",{parentName:"ul"},"extensive documentation \ud83d\udcc3"),(0,r.kt)("li",{parentName:"ul"},"...")),(0,r.kt)("h2",{id:"showcase-images"},"Showcase Images"),(0,r.kt)("h6",{id:"tom-console-application"},"Tom console application"),(0,r.kt)("img",{src:a(9566).Z,alt:"TinyORM - Tom console application - Showcase",title:"Tom console application"}),(0,r.kt)("h6",{id:"passed-all-unit-tests-"},"Passed all unit tests \ud83e\udd73"),(0,r.kt)("img",{src:a(5734).Z,alt:"TinyORM - Passed all unit tests - Showcase",title:"Passed all unit tests",width:"700",className:"no-blurry"}),(0,r.kt)("h4",{id:"tinyormplayground"},"TinyOrmPlayground"),(0,r.kt)("p",null,"The ",(0,r.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyOrmPlayground"},"TinyOrmPlayground")," project is my personal project where I have tested all the TinyORM database queries in the early development phases, currently, it executes ~1600 database queries across the whole TinyORM framework. Every query has a nice title header, is logged to the console, and is counted and measured (elapsed time). Every query also runs on all ",(0,r.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"supported databases"),"."),(0,r.kt)("p",null,"The TinyOrmPlayground project can be compiled in a single-threaded or multi-threaded mode. In the multi-threaded mode, every database connection runs in its own thread. At the end of every database connection is logged a connection summary and before an exit is logged the application summary. Whole TinyOrmPlayground application is configurable through the ",(0,r.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyOrmPlayground/blob/main/src/configuration.hpp"},"src/configuration.hpp")," class."),(0,r.kt)("h6",{id:"tinyormplayground-single-threaded"},"TinyOrmPlayground single-threaded"),(0,r.kt)("img",{src:a(3179).Z,alt:"TinyORM - Invoked TinyOrmPlayground single-threaded - Showcase",title:"Invoked TinyOrmPlayground single-threaded"}),(0,r.kt)("h6",{id:"tinyormplayground-multi-threaded"},"TinyOrmPlayground multi-threaded"),(0,r.kt)("img",{src:a(1177).Z,alt:"TinyORM - Invoked TinyOrmPlayground multi-threaded - Showcase",title:"Invoked TinyOrmPlayground multi-threaded"}))}d.isMDXComponent=!0},5734:(e,t,a)=>{a.d(t,{Z:()=>n});const n=a.p+"assets/images/tinyorm-passed_all_unit_tests-d730d995b6b490fb42c3671738e3b81e.png"},1177:(e,t,a)=>{a.d(t,{Z:()=>n});const n=a.p+"assets/images/tinyormplayground-multi-threaded-edb67030c75e2845e1fa7013e510174c.png"},3179:(e,t,a)=>{a.d(t,{Z:()=>n});const n=a.p+"assets/images/tinyormplayground-single-threaded-4e7a5769ad5a768a4d04c6dc856c4391.png"},9566:(e,t,a)=>{a.d(t,{Z:()=>n});const n=a.p+"assets/images/tom_cli-402f7dd4dfe7dbd0b20dfe5fb61838a2.png"}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[832],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>y});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var o=n.createContext({}),m=function(e){var t=n.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},u=function(e){var t=m(e.components);return n.createElement(o.Provider,{value:t},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},c=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,i=e.originalType,o=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),p=m(a),c=r,y=p["".concat(o,".").concat(c)]||p[c]||d[c]||i;return a?n.createElement(y,l(l({ref:t},u),{},{components:a})):n.createElement(y,l({ref:t},u))}));function y(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=a.length,l=new Array(i);l[0]=c;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[p]="string"==typeof e?e:r,l[1]=s;for(var m=2;m{a.r(t),a.d(t,{assets:()=>o,contentTitle:()=>l,default:()=>d,frontMatter:()=>i,metadata:()=>s,toc:()=>m});var n=a(7462),r=(a(7294),a(3905));const i={sidebar_position:7,sidebar_label:"\ud83d\udcc4 Features Summary",hide_table_of_contents:!0,description:"List that fastly summarizes all TinyORM features.",keywords:["c++ orm","tinyorm","features","summary","features summary"]},l="Features Summary",s={unversionedId:"features-summary",id:"features-summary",title:"Features Summary",description:"List that fastly summarizes all TinyORM features.",source:"@site/docs/features-summary.mdx",sourceDirName:".",slug:"/features-summary",permalink:"/features-summary",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/features-summary.mdx",tags:[],version:"current",sidebarPosition:7,frontMatter:{sidebar_position:7,sidebar_label:"\ud83d\udcc4 Features Summary",hide_table_of_contents:!0,description:"List that fastly summarizes all TinyORM features.",keywords:["c++ orm","tinyorm","features","summary","features summary"]},sidebar:"tinyormSidebar",previous:{title:"Migrations",permalink:"/building/migrations"},next:{title:"\u2764\ufe0f Sponsors",permalink:"/sponsors"}},o={},m=[{value:"Summary List",id:"summary-list",level:2},{value:"Showcase Images",id:"showcase-images",level:2},{value:"Tom console application",id:"tom-console-application",level:6},{value:"Passed all unit tests \ud83e\udd73",id:"passed-all-unit-tests-",level:6},{value:"TinyOrmPlayground",id:"tinyormplayground",level:4},{value:"TinyOrmPlayground single-threaded",id:"tinyormplayground-single-threaded",level:6},{value:"TinyOrmPlayground multi-threaded",id:"tinyormplayground-multi-threaded",level:6}],u={toc:m},p="wrapper";function d(e){let{components:t,...i}=e;return(0,r.kt)(p,(0,n.Z)({},u,i,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"features-summary"},"Features Summary"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#summary-list"},"Summary List")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"#showcase-images"},"Showcase Images"))),(0,r.kt)("h2",{id:"summary-list"},"Summary List"),(0,r.kt)("p",null,"The following list fastly summarizes all the ",(0,r.kt)("inlineCode",{parentName:"p"},"TinyORM")," features."),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"simple database connections management")," \ud83e\uddec",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"database manager that helps with the database connections management"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"Orm::DB")," facade class for nicer and shorter syntax"),(0,r.kt)("li",{parentName:"ul"},"MySQL, MariaDB, SQLite, and PostgreSQL support for ",(0,r.kt)("strong",{parentName:"li"},"all")," features \ud83d\udc8e"),(0,r.kt)("li",{parentName:"ul"},"multi-threading support \ud83d\udc40"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"SSL")," connections support \ud83d\udd12"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"impressive query builder")," \ud83d\udd27",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"allows passing sub-queries and raw expressions practically everywhere, to column names, values, and to every SQL clause as select, where, joins, group by, having, order by \ud83d\udd25"),(0,r.kt)("li",{parentName:"ul"},"a logical grouping that offers to wrap logical groups in parenthesis"),(0,r.kt)("li",{parentName:"ul"},"chunked results for lower memory footprint \u2728"),(0,r.kt)("li",{parentName:"ul"},"raw methods for all SQL clauses"),(0,r.kt)("li",{parentName:"ul"},"all join types (left, right, cross, inner) and also join where clause support \ud83e\udee4"),(0,r.kt)("li",{parentName:"ul"},"aggregate methods min, max, sum, increment, decrement, ..."),(0,r.kt)("li",{parentName:"ul"},"whereExists and exists methods for an existence queries"),(0,r.kt)("li",{parentName:"ul"},"transactions and pessimistic locking \ud83d\udd12"),(0,r.kt)("li",{parentName:"ul"},"of course, insert, update, and delete SQL clauses support"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"correct QDateTime time zone")," using the ",(0,r.kt)("inlineCode",{parentName:"li"},"qt_timezone")," connection configuration option \ud83d\udcc5 (returned QDateTime instances will have the correct time zone, and also works for an ORM)",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"this feature allows you to set up the database server time zone to the UTC and all returned QDateTime instances will have the correct UTC time zone"))))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"clever ORM with all relation types support")," \ud83c\udf89",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"one-to-one, one-to-many, and many-to-many relation types (also inverse relationships) \ud83e\udde8"),(0,r.kt)("li",{parentName:"ul"},"eager and lazy loading with custom select and constraints \ud83d\ude80"),(0,r.kt)("li",{parentName:"ul"},"fluent ",(0,r.kt)("inlineCode",{parentName:"li"},"ModelsCollection")," that expose a variety of map / reduce operations that may be chained using an intuitive interface \u2728"),(0,r.kt)("li",{parentName:"ul"},"all query builder methods are proxied from the model instances and also from the relation instances back to the query builder \ud83e\udd2f (everything that can be called on the query builder can also be called on the model and relation instances)"),(0,r.kt)("li",{parentName:"ul"},"clean active record pattern"),(0,r.kt)("li",{parentName:"ul"},"advanced features like timestamps, touching parent timestamps, ",(0,r.kt)("strong",{parentName:"li"},"soft deleting"),", default models, default model attributes, and attribute casting \ud83e\udd13"),(0,r.kt)("li",{parentName:"ul"},"querying relationships existence/absence using the has, whereHas, and hasNested methods (using dot notation for selecting nested relationships ",(0,r.kt)("em",{parentName:"li"},"users.posts.comments"),")"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"serializing")," models and collection of models including all nested relations to ",(0,r.kt)("strong",{parentName:"li"},"JSON")," and converting to vectors and maps \ud83e\udea1",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"supports controlling a custom date format during serialization"),(0,r.kt)("li",{parentName:"ul"},"supports hiding and appending attributes"))))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"compiled database migrations and seeders")," \ud83d\udd7a",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"create, update, drop, and rename database tables"),(0,r.kt)("li",{parentName:"ul"},"create, drop, and rename table columns"),(0,r.kt)("li",{parentName:"ul"},"extensive schema builder that allows creating of all possible column types"),(0,r.kt)("li",{parentName:"ul"},"terser syntax for creating foreign keys and foreign key constraints"),(0,r.kt)("li",{parentName:"ul"},"supports creating, and dropping column indexes (primary, unique, fulltext, spatial)"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"the ",(0,r.kt)("inlineCode",{parentName:"strong"},"tom")," console application with tab completion for all shells (pwsh, bash, zsh)")," \ud83e\udd73",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"scaffolding of models, migrations, and seeders"),(0,r.kt)("li",{parentName:"ul"},"impressive models scaffolding, every feature that is supported by models can be generated using the ",(0,r.kt)("inlineCode",{parentName:"li"},"tom make:model")," cli command"))),(0,r.kt)("li",{parentName:"ul"},"a huge amount of code is unit tested, currently ",(0,r.kt)("strong",{parentName:"li"},"3366 unit tests")," \ud83e\udd2f"),(0,r.kt)("li",{parentName:"ul"},"C++20 only, with all the latest features used like concepts/constraints, ranges, smart pointers (no ",(0,r.kt)("inlineCode",{parentName:"li"},"new")," keyword in the whole code \ud83d\ude0e), folding expressions"),(0,r.kt)("li",{parentName:"ul"},"qmake and CMake build systems support",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"CMake FetchContent module support \ud83e\udd19"))),(0,r.kt)("li",{parentName:"ul"},"vcpkg support (also the vcpkg port, currently not committed to the vcpkg repository \u2639\ufe0f)"),(0,r.kt)("li",{parentName:"ul"},"it's really fast, you can run 1000 complex queries in 500ms (heavily DB dependant, the PostgreSQL is by far the fastest) \u231a"),(0,r.kt)("li",{parentName:"ul"},"extensive documentation \ud83d\udcc3"),(0,r.kt)("li",{parentName:"ul"},"...")),(0,r.kt)("admonition",{type:"info"},(0,r.kt)("p",{parentName:"admonition"},"See the ",(0,r.kt)("inlineCode",{parentName:"p"},"TinyDrivers")," ",(0,r.kt)("a",{parentName:"p",href:"tinydrivers/getting-started#features-summary"},"Features summary"),".")),(0,r.kt)("h2",{id:"showcase-images"},"Showcase Images"),(0,r.kt)("h6",{id:"tom-console-application"},"Tom console application"),(0,r.kt)("img",{src:a(9566).Z,alt:"TinyORM - Tom console application - Showcase",title:"Tom console application"}),(0,r.kt)("h6",{id:"passed-all-unit-tests-"},"Passed all unit tests \ud83e\udd73"),(0,r.kt)("img",{src:a(5734).Z,alt:"TinyORM - Passed all unit tests - Showcase",title:"Passed all unit tests",width:"700",className:"no-blurry"}),(0,r.kt)("h4",{id:"tinyormplayground"},"TinyOrmPlayground"),(0,r.kt)("p",null,"The ",(0,r.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyOrmPlayground"},"TinyOrmPlayground")," project is my personal project where I have tested all the TinyORM database queries in the early development phases, currently, it executes ~1600 database queries across the whole TinyORM framework. Every query has a nice title header, is logged to the console, and is counted and measured (elapsed time). Every query also runs on all ",(0,r.kt)("a",{parentName:"p",href:"/database/getting-started#introduction"},"supported databases"),"."),(0,r.kt)("p",null,"The TinyOrmPlayground project can be compiled in a single-threaded or multi-threaded mode. In the multi-threaded mode, every database connection runs in its own thread. At the end of every database connection is logged a connection summary and before an exit is logged the application summary. Whole TinyOrmPlayground application is configurable through the ",(0,r.kt)("a",{parentName:"p",href:"https://github.com/silverqx/TinyOrmPlayground/blob/main/src/configuration.hpp"},"src/configuration.hpp")," class."),(0,r.kt)("h6",{id:"tinyormplayground-single-threaded"},"TinyOrmPlayground single-threaded"),(0,r.kt)("img",{src:a(3179).Z,alt:"TinyORM - Invoked TinyOrmPlayground single-threaded - Showcase",title:"Invoked TinyOrmPlayground single-threaded"}),(0,r.kt)("h6",{id:"tinyormplayground-multi-threaded"},"TinyOrmPlayground multi-threaded"),(0,r.kt)("img",{src:a(1177).Z,alt:"TinyORM - Invoked TinyOrmPlayground multi-threaded - Showcase",title:"Invoked TinyOrmPlayground multi-threaded"}))}d.isMDXComponent=!0},5734:(e,t,a)=>{a.d(t,{Z:()=>n});const n=a.p+"assets/images/tinyorm-passed_all_unit_tests-d730d995b6b490fb42c3671738e3b81e.png"},1177:(e,t,a)=>{a.d(t,{Z:()=>n});const n=a.p+"assets/images/tinyormplayground-multi-threaded-edb67030c75e2845e1fa7013e510174c.png"},3179:(e,t,a)=>{a.d(t,{Z:()=>n});const n=a.p+"assets/images/tinyormplayground-single-threaded-4e7a5769ad5a768a4d04c6dc856c4391.png"},9566:(e,t,a)=>{a.d(t,{Z:()=>n});const n=a.p+"assets/images/tom_cli-402f7dd4dfe7dbd0b20dfe5fb61838a2.png"}}]); \ No newline at end of file diff --git a/assets/js/feaee7f3.f93bb419.js b/assets/js/feaee7f3.d9eea7da.js similarity index 98% rename from assets/js/feaee7f3.f93bb419.js rename to assets/js/feaee7f3.d9eea7da.js index 67a677d8b..a86e184a8 100644 --- a/assets/js/feaee7f3.f93bb419.js +++ b/assets/js/feaee7f3.d9eea7da.js @@ -1 +1 @@ -"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[168],{5162:(e,t,n)=>{n.d(t,{Z:()=>i});var a=n(7294),l=n(6010);const o={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,l.Z)(o.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>f});var a=n(7462),l=n(7294),o=n(6010),i=n(2466),r=n(6550),d=n(1980),p=n(7392),s=n(12);function u(e){return function(e){return l.Children.map(e,(e=>{if(!e||(0,l.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:l}}=e;return{value:t,label:n,attributes:a,default:l}}))}function c(e){const{values:t,children:n}=e;return(0,l.useMemo)((()=>{const e=t??u(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function k(e){let{queryString:t=!1,groupId:n}=e;const a=(0,r.k6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,d._X)(o),(0,l.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(a.location.search);t.set(o,e),a.replace({...a.location,search:t.toString()})}),[o,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,o=c(e),[i,r]=(0,l.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:o}))),[d,p]=k({queryString:n,groupId:a}),[u,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,s.Nk)(n);return[a,(0,l.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:a}),g=(()=>{const e=d??u;return m({value:e,tabValues:o})?e:null})();(0,l.useLayoutEffect)((()=>{g&&r(g)}),[g]);return{selectedValue:i,selectValue:(0,l.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);r(e),p(e),h(e)}),[p,h,o]),tabValues:o}}var g=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function N(e){let{className:t,block:n,selectedValue:r,selectValue:d,tabValues:p}=e;const s=[],{blockElementScrollPositionUntilNextRender:u}=(0,i.o5)(),c=e=>{const t=e.currentTarget,n=s.indexOf(t),a=p[n].value;a!==r&&(u(t),d(a))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=s.indexOf(e.currentTarget)+1;t=s[n]??s[0];break}case"ArrowLeft":{const n=s.indexOf(e.currentTarget)-1;t=s[n]??s[s.length-1];break}}t?.focus()};return l.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":n},t)},p.map((e=>{let{value:t,label:n,attributes:i}=e;return l.createElement("li",(0,a.Z)({role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,key:t,ref:e=>s.push(e),onKeyDown:m,onClick:c},i,{className:(0,o.Z)("tabs__item",b.tabItem,i?.className,{"tabs__item--active":r===t})}),n??t)})))}function T(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,l.cloneElement)(e,{className:"margin-top--md"}):null}return l.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,l.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function C(e){const t=h(e);return l.createElement("div",{className:(0,o.Z)("tabs-container",b.tabList)},l.createElement(N,(0,a.Z)({},e,t)),l.createElement(T,(0,a.Z)({},e,t)))}function f(e){const t=(0,g.Z)();return l.createElement(C,(0,a.Z)({key:String(t)},e))}},2044:(e,t,n)=>{n.d(t,{$t:()=>u,Ae:()=>g,C:()=>k,DK:()=>b,Fo:()=>r,Fs:()=>l,IM:()=>h,IZ:()=>a,RS:()=>_,VE:()=>N,Wg:()=>C,_A:()=>p,al:()=>y,jk:()=>m,js:()=>d,of:()=>s,q5:()=>i,qb:()=>f,vk:()=>c,wU:()=>o,zg:()=>T});const a="shell",l="database",o="application",i="bash",r="pwsh",d="zsh",p="maria",s="mysql",u="postgres",c="sqlite",m="application",k="bash",h="pwsh",g="zsh",b="MariaDB",N="MySQL",T="PostgreSQL",C="SQLite",f="tinyorm.org",y="$HOME/Code/c/",_="$env:USERPROFILE\\Code\\c\\"},4355:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(7294),l=n(9482);function o(){const e=(0,a.useContext)(l.Z);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6005:(e,t,n)=>{n.d(t,{AE:()=>r,EA:()=>i,em:()=>p,go:()=>d,mT:()=>s,we:()=>u});var a=n(4355),l=n(2389),o=n(2044);const i=function(e,t){return void 0===t&&(t=!0),c((0,a.Z)().rootFolder[e]??p(e),e,t)},r=()=>(0,a.Z)().rootFolder[o.wU]??p(o.wU),d=function(e,t){if(void 0===t&&(t=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const n=t||e!==o.Fo?"/":"\\";return c(i(e)+n+r(),e,t)};function p(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,l.Z)())return"";switch(e){case o.Fo:return o.RS;case o.q5:return o.al;case o.wU:return o.qb;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function s(e){return e===o.wU}function u(e,t){if(null==t||""===t)return t;const n="$ENV{$1}$2";switch(e){case o.Fo:return k(t).replace(/\$env:(.+?)(\/.*)/,n);case o.q5:return t.replace(/\$(.+?)(\/.*)/,n);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function c(e,t,n){if(void 0===n&&(n=!0),null==e||""===e)return e;if(t!==o.Fo)return m(e);const a=m(e);return n?k(a):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(a)}function m(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function k(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},4588:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>m,contentTitle:()=>u,default:()=>b,frontMatter:()=>s,metadata:()=>c,toc:()=>k});var a=n(7462),l=(n(7294),n(3905)),o=n(7693),i=n(5162),r=n(4866),d=n(2044),p=n(6005);const s={sidebar_position:2,sidebar_label:"Hello world",description:"Hello world example created in the terminal and QtCreator IDE.",keywords:["c++ orm","building","hello world","tinyorm"]},u="Building: Hello world",c={unversionedId:"building/hello-world",id:"building/hello-world",title:"Building: Hello world",description:"Hello world example created in the terminal and QtCreator IDE.",source:"@site/docs/building/hello-world.mdx",sourceDirName:"building",slug:"/building/hello-world",permalink:"/building/hello-world",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/building/hello-world.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,sidebar_label:"Hello world",description:"Hello world example created in the terminal and QtCreator IDE.",keywords:["c++ orm","building","hello world","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"TinyORM",permalink:"/building/tinyorm"},next:{title:"Migrations",permalink:"/building/migrations"}},m={},k=[{value:"Introduction",id:"introduction",level:2},{value:"Prepare SQLite 3 database",id:"prepare-sqlite-3-database",level:2},{value:"Install dependencies",id:"install-dependencies",level:2},{value:"Using vcpkg.json (manifest mode)",id:"using-vcpkg-json-manifest-mode",level:4},{value:"Using vcpkg install (manually)",id:"using-vcpkg-install-manually",level:4},{value:"Source code",id:"source-code",level:2},{value:"Hello world with CMake",id:"hello-world-with-cmake",level:2},{value:"CMake project",id:"cmake-project",level:3},{value:"FetchContent",id:"fetchcontent",level:3},{value:"How FetchContent module works",id:"how-fetchcontent-module-works",level:4},{value:"Build Hello world",id:"build-hello-world-cmake",level:3},{value:"Execute Hello world",id:"execute-hello-world-cmake",level:3},{value:"Hello world with qmake",id:"hello-world-with-qmake",level:2},{value:"qmake project",id:"qmake-project",level:3},{value:"Auto-configure using .qmake.conf and .env",id:"auto-configure-using-qmake_conf-and-env",level:4},{value:"Build Hello world",id:"build-hello-world-qmake",level:3},{value:"Execute Hello world",id:"execute-hello-world-qmake",level:3}],h={toc:k},g="wrapper";function b(e){let{components:t,...s}=e;return(0,l.kt)(g,(0,a.Z)({},h,s,{components:t,mdxType:"MDXLayout"}),(0,l.kt)("h1",{id:"building-hello-world"},"Building: Hello world"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#prepare-sqlite-3-database"},"Prepare SQLite 3 database")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#install-dependencies"},"Install dependencies"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#using-vcpkg-json-manifest-mode"},"Using vcpkg.json")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#using-vcpkg-install-manually"},"Using vcpkg install")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#source-code"},"Source code")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#hello-world-with-cmake"},"Hello world with CMake"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#cmake-project"},"CMake project")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#fetchcontent"},"FetchContent")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#build-hello-world-cmake"},"Build Hello world")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#execute-hello-world-cmake"},"Execute Hello world")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#hello-world-with-qmake"},"Hello world with qmake"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#qmake-project"},"qmake project")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#build-hello-world-qmake"},"Build Hello world")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#execute-hello-world-qmake"},"Execute Hello world"))))),(0,l.kt)("h2",{id:"introduction"},"Introduction"),(0,l.kt)("p",null,"We will try to create the simplest working console application, in the terminal with the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," and in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE")," with the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build systems."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example also expects the following ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure"),", let's create them."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.Fo)}\nmkdir HelloWorld/HelloWorld\ncd HelloWorld`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.q5)}\nmkdir -p HelloWorld/HelloWorld\ncd HelloWorld`))),(0,l.kt)("h2",{id:"prepare-sqlite-3-database"},"Prepare SQLite 3 database"),(0,l.kt)("p",null,"The easiest way to demonstrate the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example will be with a ",(0,l.kt)("inlineCode",{parentName:"p"},"SQLite 3")," database."),(0,l.kt)("p",null,"Execute the following command in the terminal to create and insert two rows into the ",(0,l.kt)("inlineCode",{parentName:"p"},"SQLite 3")," database."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"sqlite3 HelloWorld.sqlite3 \"\ncreate table posts(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL);\ninsert into posts values(1, 'First Post');\ninsert into posts values(2, 'Second Post');\nselect * from posts;\"\n")),(0,l.kt)("h2",{id:"install-dependencies"},"Install dependencies"),(0,l.kt)("p",null,"First, install the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," package manager as is described ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#vcpkg"},"here"),"."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," libraries are required dependencies because ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," uses them in header files, you have to install them before you can use ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM"),". The ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," library is only needed in the ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," migrations it's used by the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:status")," command."),(0,l.kt)("p",null,"There are two ways how to install the ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," libraries using ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg"),"."),(0,l.kt)("h4",{id:"using-vcpkg-json-manifest-mode"},"Using vcpkg.json ",(0,l.kt)("small",null,"(manifest mode)")),(0,l.kt)("p",null,"Create a ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg.json")," file with the following content. ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," example below uses this method."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd HelloWorld\nvim vcpkg.json\n")),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-json",metastring:"title='vcpkg.json'",title:"'vcpkg.json'"},'{\n "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",\n "name": "tinyorm-helloworld",\n "version-semver": "0.1.0",\n "description": "Hello world console application for TinyORM C++ library",\n "homepage": "https://github.com/silverqx/TinyORM",\n "documentation": "https://www.tinyorm.org/building/hello-world",\n "maintainers": "Silver Zachara ",\n "supports": "!(uwp | arm | android | emscripten | osx | ios | xbox | freebsd | openbsd | wasm32)",\n "dependencies": [\n "range-v3",\n "tabulate"\n ]\n}\n')),(0,l.kt)("admonition",{type:"note"},(0,l.kt)("p",{parentName:"admonition"},"Only ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," via the ",(0,l.kt)("inlineCode",{parentName:"p"},"toolchain file")," supports this method.")),(0,l.kt)("h4",{id:"using-vcpkg-install-manually"},"Using vcpkg install ",(0,l.kt)("small",null,"(manually)")),(0,l.kt)("p",null,"This method can be used with both ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake"),"."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../../vcpkg\n\nvcpkg search range-v3\nvcpkg search tabulate\nvcpkg install range-v3 tabulate\nvcpkg list\n")),(0,l.kt)("h2",{id:"source-code"},"Source code"),(0,l.kt)("p",null,"Let's start in the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," project folder."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.Fo)}/HelloWorld/HelloWorld`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.q5)}/HelloWorld/HelloWorld`))),(0,l.kt)("p",null,"Create ",(0,l.kt)("inlineCode",{parentName:"p"},"main.cpp")," source file."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"vim main.cpp\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"To paste a source code correctly in ",(0,l.kt)("inlineCode",{parentName:"p"},"vim"),", press ",(0,l.kt)("kbd",null,"Shift")," + ",(0,l.kt)("kbd",null,"p"),".")),(0,l.kt)("p",null,"And paste the following code."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-cpp",metastring:"title='main.cpp'",title:"'main.cpp'"},'#include \n#include \n\n#ifdef _WIN32\n# include \n#endif\n\n#include \n\nusing Orm::DB;\n\nint main(int argc, char *argv[])\n{\n#ifdef _WIN32\n SetConsoleOutputCP(CP_UTF8);\n// SetConsoleOutputCP(1250);\n#endif\n\n /* Needed from Qt v6.5.3 to avoid:\n qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter */\n QCoreApplication app(argc, argv);\n\n // Ownership of a shared_ptr()\n auto manager = DB::create({\n {"driver", "QSQLITE"},\n {"database", qEnvironmentVariable("TINYORM_HELLOWORLD_DB_SQLITE_DATABASE",\n "../../HelloWorld.sqlite3")},\n {"check_database_exists", true},\n });\n\n auto posts = DB::select("select * from posts");\n\n while(posts.next())\n qDebug() << posts.value("id").toULongLong()\n << posts.value("name").toString();\n}\n')),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"QSqlDatabase")," depends on ",(0,l.kt)("inlineCode",{parentName:"p"},"QCoreApplication")," from ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt v6.5.3")," so you must create the ",(0,l.kt)("inlineCode",{parentName:"p"},"QCoreApplication")," instance before you will call anything from the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. \ud83e\udee4 The change was made ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/qt/qtbase/commit/8d2bdc9cd5482eace12ba7e45304857bd24db0e6#diff-1d355c25c0b0eddec2be48253407780c4dc510d986739aec61e1ec892ccaf86e"},"here"),".")),(0,l.kt)("h2",{id:"hello-world-with-cmake"},"Hello world with CMake"),(0,l.kt)("p",null,"Create a folder for the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," build."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},"cd ..\nmkdir HelloWorld-builds-cmake/build-debug\n\ncd HelloWorld")),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},"cd ..\nmkdir -p HelloWorld-builds-cmake/build-debug\n\ncd HelloWorld"))),(0,l.kt)("h3",{id:"cmake-project"},"CMake project"),(0,l.kt)("p",null,"Create ",(0,l.kt)("inlineCode",{parentName:"p"},"CMakeLists.txt")," file with the following content."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`cmake_minimum_required(VERSION VERSION 3.22...3.28 FATAL_ERROR)\n\nproject(HelloWorld LANGUAGES CXX)\n\n# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,p.we)(d.Fo,(0,p.go)(d.Fo))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\nadd_executable(HelloWorld\n main.cpp\n)\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt\${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.36.5 CONFIG REQUIRED)\n\ntarget_link_libraries(HelloWorld\n PRIVATE\n Qt\${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`cmake_minimum_required(VERSION VERSION 3.22...3.28 FATAL_ERROR)\n\nproject(HelloWorld LANGUAGES CXX)\n\n# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,p.we)(d.q5,(0,p.go)(d.q5))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\nadd_executable(HelloWorld\n main.cpp\n)\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt\${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.36.5 CONFIG REQUIRED)\n\ntarget_link_libraries(HelloWorld\n PRIVATE\n Qt\${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)`))),(0,l.kt)("h3",{id:"fetchcontent"},"FetchContent"),(0,l.kt)("p",null,"If you don't have cloned and built the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library, or you want to quickly try TinyORM without wasting time with cloning and building the TinyORM library, then you can use CMake's ",(0,l.kt)("a",{parentName:"p",href:"https://cmake.org/cmake/help/latest/module/FetchContent.html"},(0,l.kt)("inlineCode",{parentName:"a"},"FetchContent"))," module that will do all of this for you."),(0,l.kt)("p",null,"Instead of providing a path by the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_PREFIX_PATH")," (or using the ",(0,l.kt)("inlineCode",{parentName:"p"},"User Package Registry"),") like in the example below:"),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,p.we)(d.Fo,(0,p.go)(d.Fo))}/TinyORM/TinyORM-builds-cmake/build-debug")`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,p.we)(d.q5,(0,p.go)(d.q5))}/TinyORM/TinyORM-builds-cmake/build-debug")`))),(0,l.kt)("p",null,"You can use the ",(0,l.kt)("a",{parentName:"p",href:"https://cmake.org/cmake/help/latest/module/FetchContent.html"},(0,l.kt)("inlineCode",{parentName:"a"},"FetchContent"))," module like in the following example."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},"cmake_minimum_required(VERSION VERSION 3.22...3.28 FATAL_ERROR)\n\nproject(HelloWorld LANGUAGES CXX)\n\n# FetchContent method\ninclude(FetchContent)\nFetchContent_Declare(TinyOrm\n GIT_REPOSITORY https://github.com/silverqx/TinyORM.git\n GIT_TAG origin/main\n OVERRIDE_FIND_PACKAGE\n)\n# Here you can configure TinyORM CMake options\nset(MYSQL_PING OFF)\nset(TOM_EXAMPLE ON)\n\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\nadd_executable(HelloWorld\n main.cpp\n)\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.36.5 CONFIG REQUIRED)\n\ntarget_link_libraries(HelloWorld\n PRIVATE\n Qt${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)")),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},'cmake_minimum_required(VERSION VERSION 3.22...3.28 FATAL_ERROR)\n\nproject(HelloWorld LANGUAGES CXX)\n\n# FetchContent method\ninclude(FetchContent)\nFetchContent_Declare(TinyORM\n GIT_REPOSITORY https://github.com/silverqx/TinyORM.git\n GIT_TAG origin/main\n OVERRIDE_FIND_PACKAGE\n)\n# Here you can configure TinyORM CMake options\nset(MYSQL_PING OFF)\nset(TOM_EXAMPLE ON)\n\nTinyORM-builds-cmake/build-debug")\n\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\nadd_executable(HelloWorld\n main.cpp\n)\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.36.5 CONFIG REQUIRED)\n\ntarget_link_libraries(HelloWorld\n PRIVATE\n Qt${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)'))),(0,l.kt)("h4",{id:"how-fetchcontent-module-works"},"How FetchContent module works"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"FetchContent_Declare")," command is like calling the git clone inside the build folder and then adding a cloned folder in a similar way as the ",(0,l.kt)("inlineCode",{parentName:"p"},"add_subdirectory()")," command does."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"FetchContent_MakeAvailable()")," internally calls the ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package()")," command or if you pass the ",(0,l.kt)("inlineCode",{parentName:"p"},"OVERRIDE_FIND_PACKAGE")," argument, then you don't have to call the the ",(0,l.kt)("inlineCode",{parentName:"p"},"FetchContent_MakeAvailable"),", but you must call the ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package( x.y.z CONFIG REQUIRED)")," command manually."),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"An advantage of the ",(0,l.kt)("inlineCode",{parentName:"p"},"OVERRIDE_FIND_PACKAGE")," argument is that you can call the ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package")," command much later, and you can insert additional configurations between.")),(0,l.kt)("h3",{id:"build-hello-world-cmake"},"Build Hello world"),(0,l.kt)("p",null,"Now you are ready to configure ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," application."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../HelloWorld-builds-cmake/build-debug\n")),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cmake.exe \`\n-S "${(0,p.go)(d.Fo)}/HelloWorld/HelloWorld" \`\n-B "${(0,p.go)(d.Fo)}/HelloWorld/HelloWorld-builds-cmake/build-debug" \`\n-G 'Ninja' \`\n-D CMAKE_BUILD_TYPE:STRING='Debug' \`\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,p.EA)(d.Fo)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \`\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,p.EA)(d.Fo)}/tmp/HelloWorld"`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cmake \\\n-S "${(0,p.go)(d.q5)}/HelloWorld/HelloWorld" \\\n-B "${(0,p.go)(d.q5)}/HelloWorld/HelloWorld-builds-cmake/build-debug" \\\n-G 'Ninja' \\\n-D CMAKE_BUILD_TYPE:STRING='Debug' \\\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,p.EA)(d.q5)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \\\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,p.EA)(d.q5)}/tmp/TinyORM"`))),(0,l.kt)("p",null,"And build."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cmake --build . --target all\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"Enable the ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#cmake-strict_mode-option"},(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_STRICT_MODE"))," environment variable to produce better code and to follow good code practices.")),(0,l.kt)("h3",{id:"execute-hello-world-cmake"},"Execute Hello world"),(0,l.kt)("p",null,"Do not forget to add ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm0d.dll")," on the path on Windows and on the ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux, so ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," application can find it during execution, as is described ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#tinyorm-on-path-cmake"},"here"),"."),(0,l.kt)(r.Z,{groupId:d.IZ,name:"tinyorm-on-path",mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,p.go)(d.Fo,!1)}\\TinyORM\\TinyORM-builds-cmake\\build-debug;" + $env:Path`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export LD_LIBRARY_PATH=${(0,p.go)(d.q5)}/TinyORM/TinyORM-builds-cmake/build-debug\${PATH:+:}$PATH`))),(0,l.kt)("p",null,"Execute ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},".\\HelloWorld.exe\n"))),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"./HelloWorld\n")))),(0,l.kt)("p",null,"The output will look like this."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-less"},'Executed prepared query (6ms, -1 results, 0 affected, tinyorm_default) : select * from posts\n1 "First Post"\n2 "Second Post"\n')),(0,l.kt)("h2",{id:"hello-world-with-qmake"},"Hello world with qmake"),(0,l.kt)("p",null,"Create a folder for the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.Fo)}/HelloWorld\n\nmkdir HelloWorld-builds-qmake`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.q5)}/HelloWorld\n\nmkdir HelloWorld-builds-qmake`))),(0,l.kt)("p",null,"The ",(0,l.kt)("a",{parentName:"p",href:"#source-code"},(0,l.kt)("inlineCode",{parentName:"a"},"source code"))," is the same as for the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld CMake")," example."),(0,l.kt)("h3",{id:"qmake-project"},"qmake project"),(0,l.kt)("p",null,"Create ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld.pro")," qmake file with the following content."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd HelloWorld\nvim HelloWorld.pro\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"To paste a source code correctly in ",(0,l.kt)("inlineCode",{parentName:"p"},"vim"),", press ",(0,l.kt)("kbd",null,"Shift")," + ",(0,l.kt)("kbd",null,"p"),".")),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='HelloWorld.pro'",title:"'HelloWorld.pro'"},"QT -= gui\n\nTEMPLATE = app\n\nCONFIG *= cmdline\n\nDEFINES += PROJECT_TINYORM_HELLOWORLD\n\nSOURCES += $$PWD/main.cpp\n\n# Auto-configure TinyORM library \ud83d\udd25\ninclude($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n")),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The exact ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure")," is crucial in this example because the paths to the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," source and build folders are relative.")),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!")),(0,l.kt)("h4",{id:"auto-configure-using-qmake_conf-and-env"},(0,l.kt)("inlineCode",{parentName:"h4"},"Auto-configure")," using ",(0,l.kt)("inlineCode",{parentName:"h4"},".qmake.conf")," and ",(0,l.kt)("inlineCode",{parentName:"h4"},".env")),(0,l.kt)("p",null,"If you want to have properly configured ",(0,l.kt)("inlineCode",{parentName:"p"},"DEFINES")," (C preprocessor macros) or have Qt headers marked as system headers, then you need to specify a path to the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," qmake features (",(0,l.kt)("inlineCode",{parentName:"p"},".prf")," files) which handle this correctly; this path is provided by the ",(0,l.kt)("inlineCode",{parentName:"p"},"QMAKEFEATURES")," variable and can only be set in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"Read the ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#consume-tinyorm-library-qmake"},"Consume TinyOrm library (qmake)")," section, as everything that is described in that section applies here as well.")),(0,l.kt)("p",null,"Create the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file in the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," project root folder with the following content."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# Path to the PARENT folder of the TinyORM source folder\nTINY_MAIN_DIR = $$clean_path($$PWD/../../TinyORM/)\n# To find .env and .env.$$QMAKE_PLATFORM files\nTINY_DOTENV_ROOT = $$PWD\n# Path to the current build tree (used to guess the TinyORM build tree)\n#TINY_BUILD_TREE = $$shadowed($$PWD)\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")),(0,l.kt)("p",null,"Then, create a ",(0,l.kt)("code",null,".env.(win32","|","unix","|","mingw)")," file in the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," project root folder with the following content."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:".env.win32",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in HelloWorld.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_5_3_MSVC2022_64bit-Debug/)\n\n# Path to the vcpkg - range-v3\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-windows\n\n# Enable ccache wrapper\n#CONFIG *= tiny_ccache_win32\n"))),(0,l.kt)(i.Z,{value:d.q5,label:".env.unix",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in HelloWorld.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_5_3_clang16_64bit_ccache-Debug/)\n\n# Path to the vcpkg - range-v3\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-linux\n\n# Use faster linker\nclang: CONFIG *= use_lld_linker\nelse: CONFIG *= use_gold_linker\n\n# Or use the mold linker\n#QMAKE_LFLAGS *= -fuse-ld=mold\n"))),(0,l.kt)(i.Z,{value:"mingw",label:".env.mingw",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in HelloWorld.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_5_3_MSYS2_UCRT64_clang_64bit-Debug/)\n\n# Path to the vcpkg - range-v3\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-mingw-dynamic\n\n# Enable ccache wrapper\n#CONFIG *= tiny_ccache_win32\n\n# Use faster linker (for both GCC and Clang)\n# CONFIG *= use_lld_linker does not work on MinGW\nQMAKE_LFLAGS *= -fuse-ld=lld\n")))),(0,l.kt)("p",null,"Don't forget to update the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_VCPKG_ROOT")," folder paths to your needs if you are not using the recommended ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},(0,l.kt)("inlineCode",{parentName:"a"},"Folders structure")),"."),(0,l.kt)("p",null,"You can use the ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," if you don't like to specify it manually. Just comment out the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," and uncomment the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_BUILD_TREE = $$shadowed($$PWD)")," in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can entirely avoid the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files, just move the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," to the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," or remove it by help of ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," and set the ",(0,l.kt)("inlineCode",{parentName:"p"},"VCPKG_ROOT")," environment variable at system level as is described in ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#set-up-vcpkg-environment"},(0,l.kt)("inlineCode",{parentName:"a"},"Set up vcpkg environment")),".")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"Configuring by the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," and ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files has one big advantage, which is that you don't have to modify the project files.")),(0,l.kt)("h3",{id:"build-hello-world-qmake"},"Build Hello world"),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"I recommend creating a new ",(0,l.kt)("inlineCode",{parentName:"p"},"Session")," in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE")," as is described ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#open-qtcreator-ide"},"here"),".")),(0,l.kt)("p",null,"Now you can open the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld.pro")," project in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),"."),(0,l.kt)("p",null,"This will open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Configure Project")," tab, select some kit and update build folder paths to meet our ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure")," or like you want."),(0,l.kt)("img",{src:n(1465).Z,alt:"HelloWorld - QtCreator - Configure Project",width:"760"}),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can force the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator")," to generate a build folders structure as is described ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#qtcreator-default-build-directory"},"here"),".")),(0,l.kt)("p",null,"You are ready to configure build options, hit ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"5")," to open ",(0,l.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,l.kt)("inlineCode",{parentName:"p"},"Build")," in the left sidebar to open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Build Settings"),", it should look similar to the following picture."),(0,l.kt)("img",{src:n(6511).Z,className:"no-blurry",alt:"HelloWorld - QtCreator - Build Settings",width:"760"}),(0,l.kt)("p",null,"Disable ",(0,l.kt)("inlineCode",{parentName:"p"},"QML debugging and profiling")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt Quick Compiler"),", they are not used."),(0,l.kt)("p",null,"In the left sidebar open ",(0,l.kt)("inlineCode",{parentName:"p"},"Dependencies")," and check ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project and ",(0,l.kt)("inlineCode",{parentName:"p"},"Synchronize configuration"),", this setting ensures that the current project will be rebuilt correctly when the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library source code changes."),(0,l.kt)("p",null,"Everything is ready to build, you can press ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"b")," to build the project."),(0,l.kt)("h3",{id:"execute-hello-world-qmake"},"Execute Hello world"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator")," takes care of all the necessary configurations, sets up the build environment correctly, and also prepends dependency libraries on the system path on Windows and on the ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux."),(0,l.kt)("p",null,"The only thing you might want to change is to run the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example in the new terminal window. To do so, hit ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"5")," to open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,l.kt)("inlineCode",{parentName:"p"},"Run")," in the left sidebar to open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Run Settings"),", then in the ",(0,l.kt)("inlineCode",{parentName:"p"},"Run")," section select the ",(0,l.kt)("inlineCode",{parentName:"p"},"Run in terminal")," checkbox."),(0,l.kt)("p",null,"To execute the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example press ",(0,l.kt)("kbd",null,"Ctrl")," + ",(0,l.kt)("kbd",null,"r"),"."),(0,l.kt)("p",null,"The output will look like this."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-less"},'Executed prepared query (6ms, -1 results, 0 affected, tinyorm_default) : select * from posts\n1 "First Post"\n2 "Second Post"\n')))}b.isMDXComponent=!0},6511:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-build_settings-ebdc6c0c056d11462096ff10cba682a1.png"},1465:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-configure_project-8caf87e6af4452f0c28bd15c85c392fc.png"}}]); \ No newline at end of file +"use strict";(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[168],{5162:(e,t,n)=>{n.d(t,{Z:()=>i});var a=n(7294),l=n(6010);const o={tabItem:"tabItem_Ymn6"};function i(e){let{children:t,hidden:n,className:i}=e;return a.createElement("div",{role:"tabpanel",className:(0,l.Z)(o.tabItem,i),hidden:n},t)}},4866:(e,t,n)=>{n.d(t,{Z:()=>f});var a=n(7462),l=n(7294),o=n(6010),i=n(2466),r=n(6550),d=n(1980),p=n(7392),s=n(12);function u(e){return function(e){return l.Children.map(e,(e=>{if(!e||(0,l.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(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)??[]}(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:l}}=e;return{value:t,label:n,attributes:a,default:l}}))}function c(e){const{values:t,children:n}=e;return(0,l.useMemo)((()=>{const e=t??u(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function k(e){let{queryString:t=!1,groupId:n}=e;const a=(0,r.k6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)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 n??null}({queryString:t,groupId:n});return[(0,d._X)(o),(0,l.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(a.location.search);t.set(o,e),a.replace({...a.location,search:t.toString()})}),[o,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,o=c(e),[i,r]=(0,l.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:o}))),[d,p]=k({queryString:n,groupId:a}),[u,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,s.Nk)(n);return[a,(0,l.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:a}),g=(()=>{const e=d??u;return m({value:e,tabValues:o})?e:null})();(0,l.useLayoutEffect)((()=>{g&&r(g)}),[g]);return{selectedValue:i,selectValue:(0,l.useCallback)((e=>{if(!m({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);r(e),p(e),h(e)}),[p,h,o]),tabValues:o}}var g=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function N(e){let{className:t,block:n,selectedValue:r,selectValue:d,tabValues:p}=e;const s=[],{blockElementScrollPositionUntilNextRender:u}=(0,i.o5)(),c=e=>{const t=e.currentTarget,n=s.indexOf(t),a=p[n].value;a!==r&&(u(t),d(a))},m=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=s.indexOf(e.currentTarget)+1;t=s[n]??s[0];break}case"ArrowLeft":{const n=s.indexOf(e.currentTarget)-1;t=s[n]??s[s.length-1];break}}t?.focus()};return l.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":n},t)},p.map((e=>{let{value:t,label:n,attributes:i}=e;return l.createElement("li",(0,a.Z)({role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,key:t,ref:e=>s.push(e),onKeyDown:m,onClick:c},i,{className:(0,o.Z)("tabs__item",b.tabItem,i?.className,{"tabs__item--active":r===t})}),n??t)})))}function T(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,l.cloneElement)(e,{className:"margin-top--md"}):null}return l.createElement("div",{className:"margin-top--md"},o.map(((e,t)=>(0,l.cloneElement)(e,{key:t,hidden:e.props.value!==a}))))}function C(e){const t=h(e);return l.createElement("div",{className:(0,o.Z)("tabs-container",b.tabList)},l.createElement(N,(0,a.Z)({},e,t)),l.createElement(T,(0,a.Z)({},e,t)))}function f(e){const t=(0,g.Z)();return l.createElement(C,(0,a.Z)({key:String(t)},e))}},2044:(e,t,n)=>{n.d(t,{$t:()=>u,Ae:()=>g,C:()=>k,DK:()=>b,Fo:()=>r,Fs:()=>l,IM:()=>h,IZ:()=>a,RS:()=>_,VE:()=>N,Wg:()=>C,_A:()=>p,al:()=>y,jk:()=>m,js:()=>d,of:()=>s,q5:()=>i,qb:()=>f,vk:()=>c,wU:()=>o,zg:()=>T});const a="shell",l="database",o="application",i="bash",r="pwsh",d="zsh",p="maria",s="mysql",u="postgres",c="sqlite",m="application",k="bash",h="pwsh",g="zsh",b="MariaDB",N="MySQL",T="PostgreSQL",C="SQLite",f="tinyorm.org",y="$HOME/Code/c/",_="$env:USERPROFILE\\Code\\c\\"},4355:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(7294),l=n(9482);function o(){const e=(0,a.useContext)(l.Z);if(null!=e)return e;throw new Error("useRootFolderContext is used outside of Layout component.")}},6005:(e,t,n)=>{n.d(t,{AE:()=>r,EA:()=>i,em:()=>p,go:()=>d,mT:()=>s,we:()=>u});var a=n(4355),l=n(2389),o=n(2044);const i=function(e,t){return void 0===t&&(t=!0),c((0,a.Z)().rootFolder[e]??p(e),e,t)},r=()=>(0,a.Z)().rootFolder[o.wU]??p(o.wU),d=function(e,t){if(void 0===t&&(t=!0),null==e)throw new Error("The groupId in the applicationFolderPath() can not be empty.");const n=t||e!==o.Fo?"/":"\\";return c(i(e)+n+r(),e,t)};function p(e){if(null==e)throw new Error("The groupId in the folderDefaultValue() can not be empty.");if(!(0,l.Z)())return"";switch(e){case o.Fo:return o.RS;case o.q5:return o.al;case o.wU:return o.qb;default:throw new Error(`No default value for '${e}' groupId in the folderDefaultValue().`)}}function s(e){return e===o.wU}function u(e,t){if(null==t||""===t)return t;const n="$ENV{$1}$2";switch(e){case o.Fo:return k(t).replace(/\$env:(.+?)(\/.*)/,n);case o.q5:return t.replace(/\$(.+?)(\/.*)/,n);default:throw new Error(`Unsupported shell type '${e}' in the convertToCmakeEnvVariable().`)}}function c(e,t,n){if(void 0===n&&(n=!0),null==e||""===e)return e;if(t!==o.Fo)return m(e);const a=m(e);return n?k(a):function(e){return null==e||""===e?e:e.replaceAll(/\/+/g,"\\")}(a)}function m(e){return null==e||""===e?e:e.replace(/[/\\]+$/,"")}function k(e){return null==e||""===e?e:e.replaceAll(/\\+(?! )/g,"/")}},4588:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>m,contentTitle:()=>u,default:()=>b,frontMatter:()=>s,metadata:()=>c,toc:()=>k});var a=n(7462),l=(n(7294),n(3905)),o=n(7693),i=n(5162),r=n(4866),d=n(2044),p=n(6005);const s={sidebar_position:2,sidebar_label:"Hello world",description:"Hello world example created in the terminal and QtCreator IDE.",keywords:["c++ orm","building","hello world","tinyorm"]},u="Building: Hello world",c={unversionedId:"building/hello-world",id:"building/hello-world",title:"Building: Hello world",description:"Hello world example created in the terminal and QtCreator IDE.",source:"@site/docs/building/hello-world.mdx",sourceDirName:"building",slug:"/building/hello-world",permalink:"/building/hello-world",draft:!1,editUrl:"https://github.com/silverqx/TinyORM-github.io/edit/main/docs/building/hello-world.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,sidebar_label:"Hello world",description:"Hello world example created in the terminal and QtCreator IDE.",keywords:["c++ orm","building","hello world","tinyorm"]},sidebar:"tinyormSidebar",previous:{title:"TinyORM",permalink:"/building/tinyorm"},next:{title:"Migrations",permalink:"/building/migrations"}},m={},k=[{value:"Introduction",id:"introduction",level:2},{value:"Prepare SQLite 3 database",id:"prepare-sqlite-3-database",level:2},{value:"Install dependencies",id:"install-dependencies",level:2},{value:"Using vcpkg.json (manifest mode)",id:"using-vcpkg-json-manifest-mode",level:4},{value:"Using vcpkg install (manually)",id:"using-vcpkg-install-manually",level:4},{value:"Source code",id:"source-code",level:2},{value:"Hello world with CMake",id:"hello-world-with-cmake",level:2},{value:"CMake project",id:"cmake-project",level:3},{value:"FetchContent",id:"fetchcontent",level:3},{value:"How FetchContent module works",id:"how-fetchcontent-module-works",level:4},{value:"Build Hello world",id:"build-hello-world-cmake",level:3},{value:"Execute Hello world",id:"execute-hello-world-cmake",level:3},{value:"Hello world with qmake",id:"hello-world-with-qmake",level:2},{value:"qmake project",id:"qmake-project",level:3},{value:"Auto-configure using .qmake.conf and .env",id:"auto-configure-using-qmake_conf-and-env",level:4},{value:"Build Hello world",id:"build-hello-world-qmake",level:3},{value:"Execute Hello world",id:"execute-hello-world-qmake",level:3}],h={toc:k},g="wrapper";function b(e){let{components:t,...s}=e;return(0,l.kt)(g,(0,a.Z)({},h,s,{components:t,mdxType:"MDXLayout"}),(0,l.kt)("h1",{id:"building-hello-world"},"Building: Hello world"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#introduction"},"Introduction")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#prepare-sqlite-3-database"},"Prepare SQLite 3 database")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#install-dependencies"},"Install dependencies"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#using-vcpkg-json-manifest-mode"},"Using vcpkg.json")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#using-vcpkg-install-manually"},"Using vcpkg install")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#source-code"},"Source code")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#hello-world-with-cmake"},"Hello world with CMake"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#cmake-project"},"CMake project")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#fetchcontent"},"FetchContent")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#build-hello-world-cmake"},"Build Hello world")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#execute-hello-world-cmake"},"Execute Hello world")))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#hello-world-with-qmake"},"Hello world with qmake"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#qmake-project"},"qmake project")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#build-hello-world-qmake"},"Build Hello world")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#execute-hello-world-qmake"},"Execute Hello world"))))),(0,l.kt)("h2",{id:"introduction"},"Introduction"),(0,l.kt)("p",null,"We will try to create the simplest working console application, in the terminal with the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," and in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE")," with the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build systems."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example also expects the following ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure"),", let's create them."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.Fo)}\nmkdir HelloWorld/HelloWorld\ncd HelloWorld`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.q5)}\nmkdir -p HelloWorld/HelloWorld\ncd HelloWorld`))),(0,l.kt)("h2",{id:"prepare-sqlite-3-database"},"Prepare SQLite 3 database"),(0,l.kt)("p",null,"The easiest way to demonstrate the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example will be with a ",(0,l.kt)("inlineCode",{parentName:"p"},"SQLite 3")," database."),(0,l.kt)("p",null,"Execute the following command in the terminal to create and insert two rows into the ",(0,l.kt)("inlineCode",{parentName:"p"},"SQLite 3")," database."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"sqlite3 HelloWorld.sqlite3 \"\ncreate table posts(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL);\ninsert into posts values(1, 'First Post');\ninsert into posts values(2, 'Second Post');\nselect * from posts;\"\n")),(0,l.kt)("h2",{id:"install-dependencies"},"Install dependencies"),(0,l.kt)("p",null,"First, install the ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg")," package manager as is described ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#vcpkg"},"here"),"."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," libraries are required dependencies because ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," uses them in header files, you have to install them before you can use ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM"),". The ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," library is only needed in the ",(0,l.kt)("inlineCode",{parentName:"p"},"tom")," migrations it's used by the ",(0,l.kt)("inlineCode",{parentName:"p"},"migrate:status")," command."),(0,l.kt)("p",null,"There are two ways how to install the ",(0,l.kt)("inlineCode",{parentName:"p"},"range-v3")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"tabulate")," libraries using ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg"),"."),(0,l.kt)("h4",{id:"using-vcpkg-json-manifest-mode"},"Using vcpkg.json ",(0,l.kt)("small",null,"(manifest mode)")),(0,l.kt)("p",null,"Create a ",(0,l.kt)("inlineCode",{parentName:"p"},"vcpkg.json")," file with the following content. ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," example below uses this method."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd HelloWorld\nvim vcpkg.json\n")),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-json",metastring:"title='vcpkg.json'",title:"'vcpkg.json'"},'{\n "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",\n "name": "tinyorm-helloworld",\n "version-semver": "0.1.0",\n "description": "Hello world console application for TinyORM C++ library",\n "homepage": "https://github.com/silverqx/TinyORM",\n "documentation": "https://www.tinyorm.org/building/hello-world",\n "maintainers": "Silver Zachara ",\n "supports": "!(uwp | arm | android | emscripten | osx | ios | xbox | freebsd | openbsd | wasm32)",\n "dependencies": [\n "range-v3",\n "tabulate"\n ]\n}\n')),(0,l.kt)("admonition",{type:"note"},(0,l.kt)("p",{parentName:"admonition"},"Only ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," via the ",(0,l.kt)("inlineCode",{parentName:"p"},"toolchain file")," supports this method.")),(0,l.kt)("h4",{id:"using-vcpkg-install-manually"},"Using vcpkg install ",(0,l.kt)("small",null,"(manually)")),(0,l.kt)("p",null,"This method can be used with both ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake"),"."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../../vcpkg\n\nvcpkg search range-v3\nvcpkg search tabulate\nvcpkg install range-v3 tabulate\nvcpkg list\n")),(0,l.kt)("h2",{id:"source-code"},"Source code"),(0,l.kt)("p",null,"Let's start in the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," project folder."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.Fo)}/HelloWorld/HelloWorld`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.q5)}/HelloWorld/HelloWorld`))),(0,l.kt)("p",null,"Create ",(0,l.kt)("inlineCode",{parentName:"p"},"main.cpp")," source file."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"vim main.cpp\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"To paste a source code correctly in ",(0,l.kt)("inlineCode",{parentName:"p"},"vim"),", press ",(0,l.kt)("kbd",null,"Shift")," + ",(0,l.kt)("kbd",null,"p"),".")),(0,l.kt)("p",null,"And paste the following code."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-cpp",metastring:"title='main.cpp'",title:"'main.cpp'"},'#include \n#include \n\n#ifdef _WIN32\n# include \n#endif\n\n#include \n\nusing Orm::DB;\n\nint main(int argc, char *argv[])\n{\n#ifdef _WIN32\n SetConsoleOutputCP(CP_UTF8);\n// SetConsoleOutputCP(1250);\n#endif\n\n /* Needed from Qt v6.5.3 to avoid:\n qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter */\n QCoreApplication app(argc, argv);\n\n // Ownership of a shared_ptr()\n auto manager = DB::create({\n {"driver", "QSQLITE"},\n {"database", qEnvironmentVariable("TINYORM_HELLOWORLD_DB_SQLITE_DATABASE",\n "../../HelloWorld.sqlite3")},\n {"check_database_exists", true},\n });\n\n auto posts = DB::select("select * from posts");\n\n while(posts.next())\n qDebug() << posts.value("id").toULongLong()\n << posts.value("name").toString();\n}\n')),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"QSqlDatabase")," depends on ",(0,l.kt)("inlineCode",{parentName:"p"},"QCoreApplication")," from ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt v6.5.3")," so you must create the ",(0,l.kt)("inlineCode",{parentName:"p"},"QCoreApplication")," instance before you will call anything from the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library. \ud83e\udee4 The change was made ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/qt/qtbase/commit/8d2bdc9cd5482eace12ba7e45304857bd24db0e6#diff-1d355c25c0b0eddec2be48253407780c4dc510d986739aec61e1ec892ccaf86e"},"here"),".")),(0,l.kt)("h2",{id:"hello-world-with-cmake"},"Hello world with CMake"),(0,l.kt)("p",null,"Create a folder for the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," build."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},"cd ..\nmkdir HelloWorld-builds-cmake/build-debug\n\ncd HelloWorld")),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},"cd ..\nmkdir -p HelloWorld-builds-cmake/build-debug\n\ncd HelloWorld"))),(0,l.kt)("h3",{id:"cmake-project"},"CMake project"),(0,l.kt)("p",null,"Create ",(0,l.kt)("inlineCode",{parentName:"p"},"CMakeLists.txt")," file with the following content."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`cmake_minimum_required(VERSION VERSION 3.22...3.29 FATAL_ERROR)\n\nproject(HelloWorld LANGUAGES CXX)\n\n# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,p.we)(d.Fo,(0,p.go)(d.Fo))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\nadd_executable(HelloWorld\n main.cpp\n)\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt\${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.37.0 CONFIG REQUIRED)\n\ntarget_link_libraries(HelloWorld\n PRIVATE\n Qt\${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`cmake_minimum_required(VERSION VERSION 3.22...3.29 FATAL_ERROR)\n\nproject(HelloWorld LANGUAGES CXX)\n\n# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,p.we)(d.q5,(0,p.go)(d.q5))}/TinyORM/TinyORM-builds-cmake/build-debug")\n\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\nadd_executable(HelloWorld\n main.cpp\n)\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt\${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.37.0 CONFIG REQUIRED)\n\ntarget_link_libraries(HelloWorld\n PRIVATE\n Qt\${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)`))),(0,l.kt)("h3",{id:"fetchcontent"},"FetchContent"),(0,l.kt)("p",null,"If you don't have cloned and built the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library, or you want to quickly try TinyORM without wasting time with cloning and building the TinyORM library, then you can use CMake's ",(0,l.kt)("a",{parentName:"p",href:"https://cmake.org/cmake/help/latest/module/FetchContent.html"},(0,l.kt)("inlineCode",{parentName:"a"},"FetchContent"))," module that will do all of this for you."),(0,l.kt)("p",null,"Instead of providing a path by the ",(0,l.kt)("inlineCode",{parentName:"p"},"CMAKE_PREFIX_PATH")," (or using the ",(0,l.kt)("inlineCode",{parentName:"p"},"User Package Registry"),") like in the example below:"),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,p.we)(d.Fo,(0,p.go)(d.Fo))}/TinyORM/TinyORM-builds-cmake/build-debug")`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},`# build tree\nlist(APPEND CMAKE_PREFIX_PATH "${(0,p.we)(d.q5,(0,p.go)(d.q5))}/TinyORM/TinyORM-builds-cmake/build-debug")`))),(0,l.kt)("p",null,"You can use the ",(0,l.kt)("a",{parentName:"p",href:"https://cmake.org/cmake/help/latest/module/FetchContent.html"},(0,l.kt)("inlineCode",{parentName:"a"},"FetchContent"))," module like in the following example."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},"cmake_minimum_required(VERSION VERSION 3.22...3.29 FATAL_ERROR)\n\nproject(HelloWorld LANGUAGES CXX)\n\n# FetchContent method\ninclude(FetchContent)\nFetchContent_Declare(TinyOrm\n GIT_REPOSITORY https://github.com/silverqx/TinyORM.git\n GIT_TAG origin/main\n OVERRIDE_FIND_PACKAGE\n)\n# Here you can configure TinyORM CMake options\nset(MYSQL_PING OFF)\nset(TOM_EXAMPLE ON)\n\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\nadd_executable(HelloWorld\n main.cpp\n)\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.37.0 CONFIG REQUIRED)\n\ntarget_link_libraries(HelloWorld\n PRIVATE\n Qt${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)")),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-cmake",mdxType:"CodeBlock"},'cmake_minimum_required(VERSION VERSION 3.22...3.29 FATAL_ERROR)\n\nproject(HelloWorld LANGUAGES CXX)\n\n# FetchContent method\ninclude(FetchContent)\nFetchContent_Declare(TinyORM\n GIT_REPOSITORY https://github.com/silverqx/TinyORM.git\n GIT_TAG origin/main\n OVERRIDE_FIND_PACKAGE\n)\n# Here you can configure TinyORM CMake options\nset(MYSQL_PING OFF)\nset(TOM_EXAMPLE ON)\n\nTinyORM-builds-cmake/build-debug")\n\nset(CMAKE_CXX_STANDARD 20)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)\n\nadd_executable(HelloWorld\n main.cpp\n)\n\nfind_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\nfind_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\nfind_package(TinyOrm 0.37.0 CONFIG REQUIRED)\n\ntarget_link_libraries(HelloWorld\n PRIVATE\n Qt${QT_VERSION_MAJOR}::Core\n TinyOrm::TinyOrm\n)'))),(0,l.kt)("h4",{id:"how-fetchcontent-module-works"},"How FetchContent module works"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"FetchContent_Declare")," command is like calling the git clone inside the build folder and then adding a cloned folder in a similar way as the ",(0,l.kt)("inlineCode",{parentName:"p"},"add_subdirectory()")," command does."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"FetchContent_MakeAvailable()")," internally calls the ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package()")," command or if you pass the ",(0,l.kt)("inlineCode",{parentName:"p"},"OVERRIDE_FIND_PACKAGE")," argument, then you don't have to call the the ",(0,l.kt)("inlineCode",{parentName:"p"},"FetchContent_MakeAvailable"),", but you must call the ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package( x.y.z CONFIG REQUIRED)")," command manually."),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"An advantage of the ",(0,l.kt)("inlineCode",{parentName:"p"},"OVERRIDE_FIND_PACKAGE")," argument is that you can call the ",(0,l.kt)("inlineCode",{parentName:"p"},"find_package")," command much later, and you can insert additional configurations between.")),(0,l.kt)("h3",{id:"build-hello-world-cmake"},"Build Hello world"),(0,l.kt)("p",null,"Now you are ready to configure ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," ",(0,l.kt)("inlineCode",{parentName:"p"},"CMake")," application."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd ../HelloWorld-builds-cmake/build-debug\n")),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cmake.exe \`\n-S "${(0,p.go)(d.Fo)}/HelloWorld/HelloWorld" \`\n-B "${(0,p.go)(d.Fo)}/HelloWorld/HelloWorld-builds-cmake/build-debug" \`\n-G 'Ninja' \`\n-D CMAKE_BUILD_TYPE:STRING='Debug' \`\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,p.EA)(d.Fo)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \`\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,p.EA)(d.Fo)}/tmp/HelloWorld"`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cmake \\\n-S "${(0,p.go)(d.q5)}/HelloWorld/HelloWorld" \\\n-B "${(0,p.go)(d.q5)}/HelloWorld/HelloWorld-builds-cmake/build-debug" \\\n-G 'Ninja' \\\n-D CMAKE_BUILD_TYPE:STRING='Debug' \\\n-D CMAKE_TOOLCHAIN_FILE:FILEPATH="${(0,p.EA)(d.q5)}/vcpkg/scripts/buildsystems/vcpkg.cmake" \\\n-D CMAKE_INSTALL_PREFIX:PATH="${(0,p.EA)(d.q5)}/tmp/TinyORM"`))),(0,l.kt)("p",null,"And build."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cmake --build . --target all\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"Enable the ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#cmake-strict_mode-option"},(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_STRICT_MODE"))," environment variable to produce better code and to follow good code practices.")),(0,l.kt)("h3",{id:"execute-hello-world-cmake"},"Execute Hello world"),(0,l.kt)("p",null,"Do not forget to add ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyOrm0d.dll")," on the path on Windows and on the ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux, so ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," application can find it during execution, as is described ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#tinyorm-on-path-cmake"},"here"),"."),(0,l.kt)(r.Z,{groupId:d.IZ,name:"tinyorm-on-path",mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`$env:Path = "${(0,p.go)(d.Fo,!1)}\\TinyORM\\TinyORM-builds-cmake\\build-debug;" + $env:Path`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`export LD_LIBRARY_PATH=${(0,p.go)(d.q5)}/TinyORM/TinyORM-builds-cmake/build-debug\${PATH:+:}$PATH`))),(0,l.kt)("p",null,"Execute ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-powershell"},".\\HelloWorld.exe\n"))),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"./HelloWorld\n")))),(0,l.kt)("p",null,"The output will look like this."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-less"},'Executed prepared query (6ms, -1 results, 0 affected, tinyorm_default) : select * from posts\n1 "First Post"\n2 "Second Post"\n')),(0,l.kt)("h2",{id:"hello-world-with-qmake"},"Hello world with qmake"),(0,l.kt)("p",null,"Create a folder for the ",(0,l.kt)("inlineCode",{parentName:"p"},"qmake")," build."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:d.IM,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-powershell",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.Fo)}/HelloWorld\n\nmkdir HelloWorld-builds-qmake`)),(0,l.kt)(i.Z,{value:d.q5,label:d.C,mdxType:"TabItem"},(0,l.kt)(o.Z,{className:"language-bash",mdxType:"CodeBlock"},`cd ${(0,p.go)(d.q5)}/HelloWorld\n\nmkdir HelloWorld-builds-qmake`))),(0,l.kt)("p",null,"The ",(0,l.kt)("a",{parentName:"p",href:"#source-code"},(0,l.kt)("inlineCode",{parentName:"a"},"source code"))," is the same as for the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld CMake")," example."),(0,l.kt)("h3",{id:"qmake-project"},"qmake project"),(0,l.kt)("p",null,"Create ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld.pro")," qmake file with the following content."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"cd HelloWorld\nvim HelloWorld.pro\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"To paste a source code correctly in ",(0,l.kt)("inlineCode",{parentName:"p"},"vim"),", press ",(0,l.kt)("kbd",null,"Shift")," + ",(0,l.kt)("kbd",null,"p"),".")),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='HelloWorld.pro'",title:"'HelloWorld.pro'"},"QT -= gui\n\nTEMPLATE = app\n\nCONFIG *= cmdline\n\nDEFINES *= PROJECT_TINYORM_HELLOWORLD\n\nSOURCES += $$PWD/main.cpp\n\n# Auto-configure TinyORM library \ud83d\udd25\ninclude($$TINY_MAIN_DIR/TinyORM/qmake/TinyOrm.pri)\n")),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"The exact ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure")," is crucial in this example because the paths to the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," source and build folders are relative.")),(0,l.kt)("admonition",{type:"caution"},(0,l.kt)("p",{parentName:"admonition"},"Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!")),(0,l.kt)("h4",{id:"auto-configure-using-qmake_conf-and-env"},(0,l.kt)("inlineCode",{parentName:"h4"},"Auto-configure")," using ",(0,l.kt)("inlineCode",{parentName:"h4"},".qmake.conf")," and ",(0,l.kt)("inlineCode",{parentName:"h4"},".env")),(0,l.kt)("p",null,"If you want to have properly configured ",(0,l.kt)("inlineCode",{parentName:"p"},"DEFINES")," (C preprocessor macros) or have Qt headers marked as system headers, then you need to specify a path to the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," qmake features (",(0,l.kt)("inlineCode",{parentName:"p"},".prf")," files) which handle this correctly; this path is provided by the ",(0,l.kt)("inlineCode",{parentName:"p"},"QMAKEFEATURES")," variable and can only be set in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"Read the ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#consume-tinyorm-library-qmake"},"Consume TinyOrm library (qmake)")," section, as everything that is described in that section applies here as well.")),(0,l.kt)("p",null,"Create the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file in the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," project root folder with the following content."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake",metastring:"title='.qmake.conf'",title:"'.qmake.conf'"},"# Path to the PARENT folder of the TinyORM source folder\nTINY_MAIN_DIR = $$clean_path($$PWD/../../TinyORM/)\n# To find .env and .env.$$QMAKE_PLATFORM files\nTINY_DOTENV_ROOT = $$PWD\n# Path to the current build tree (used to guess the TinyORM build tree)\n#TINY_BUILD_TREE = $$shadowed($$PWD)\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")),(0,l.kt)("p",null,"Then, create a ",(0,l.kt)("code",null,".env.(win32","|","unix","|","mingw)")," file in the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," project root folder with the following content."),(0,l.kt)(r.Z,{groupId:d.IZ,mdxType:"Tabs"},(0,l.kt)(i.Z,{value:d.Fo,label:".env.win32",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in HelloWorld.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSVC2022_64bit-Debug/)\n\n# Path to the vcpkg - range-v3\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-windows\n\n# Enable ccache wrapper\n#CONFIG *= tiny_ccache_win32\n"))),(0,l.kt)(i.Z,{value:d.q5,label:".env.unix",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in HelloWorld.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_clang16_64bit_ccache-Debug/)\n\n# Path to the vcpkg - range-v3\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-linux\n\n# Use faster linker\nclang: CONFIG *= use_lld_linker\nelse: CONFIG *= use_gold_linker\n\n# Or use the mold linker\n#QMAKE_LFLAGS *= -fuse-ld=mold\n"))),(0,l.kt)(i.Z,{value:"mingw",label:".env.mingw",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-qmake"},"# Names and values of these qmake variables are crucial, they are used in HelloWorld.pro\n# Please pay special attention to letter casing in paths, especially TinyOrm vs TinyORM!\n\n# Path to the TinyORM build folder\nTINYORM_BUILD_TREE = $$quote($$TINY_MAIN_DIR/TinyORM-builds-qmake/build-TinyORM-Desktop_Qt_6_7_0_MSYS2_UCRT64_clang_64bit-Debug/)\n\n# Path to the vcpkg - range-v3\n# Will use the TINY_VCPKG_ROOT or VCPKG_ROOT environment variable if is empty\nTINY_VCPKG_ROOT = $$clean_path($$PWD/../../../vcpkg/)\nTINY_VCPKG_TRIPLET = x64-mingw-dynamic\n\n# Enable ccache wrapper\n#CONFIG *= tiny_ccache_win32\n\n# Use faster linker (for both GCC and Clang)\n# CONFIG *= use_lld_linker does not work on MinGW\nQMAKE_LFLAGS *= -fuse-ld=lld\n")))),(0,l.kt)("p",null,"Don't forget to update the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_VCPKG_ROOT")," folder paths to your needs if you are not using the recommended ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},(0,l.kt)("inlineCode",{parentName:"a"},"Folders structure")),"."),(0,l.kt)("p",null,"You can use the ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," if you don't like to specify it manually. Just comment out the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," and uncomment the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINY_BUILD_TREE = $$shadowed($$PWD)")," in the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," file."),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can entirely avoid the ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files, just move the ",(0,l.kt)("inlineCode",{parentName:"p"},"TINYORM_BUILD_TREE")," to the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," or remove it by help of ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#partial-guessing-of-the-tinyorm_build_tree"},"Partial guessing of the ",(0,l.kt)("inlineCode",{parentName:"a"},"TINYORM_BUILD_TREE"))," and set the ",(0,l.kt)("inlineCode",{parentName:"p"},"VCPKG_ROOT")," environment variable at system level as is described in ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#set-up-vcpkg-environment"},(0,l.kt)("inlineCode",{parentName:"a"},"Set up vcpkg environment")),".")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"Configuring by the ",(0,l.kt)("inlineCode",{parentName:"p"},".qmake.conf")," and ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," files has one big advantage, which is that you don't have to modify the project files.")),(0,l.kt)("h3",{id:"build-hello-world-qmake"},"Build Hello world"),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"I recommend creating a new ",(0,l.kt)("inlineCode",{parentName:"p"},"Session")," in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE")," as is described ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#open-qtcreator-ide"},"here"),".")),(0,l.kt)("p",null,"Now you can open the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld.pro")," project in the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator IDE"),"."),(0,l.kt)("p",null,"This will open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Configure Project")," tab, select some kit and update build folder paths to meet our ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#folders-structure"},"folders structure")," or like you want."),(0,l.kt)("img",{src:n(1465).Z,alt:"HelloWorld - QtCreator - Configure Project",width:"760"}),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can force the ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator")," to generate a build folders structure as is described ",(0,l.kt)("a",{parentName:"p",href:"/building/tinyorm#qtcreator-default-build-directory"},"here"),".")),(0,l.kt)("p",null,"You are ready to configure build options, hit ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"5")," to open ",(0,l.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,l.kt)("inlineCode",{parentName:"p"},"Build")," in the left sidebar to open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Build Settings"),", it should look similar to the following picture."),(0,l.kt)("img",{src:n(6511).Z,className:"no-blurry",alt:"HelloWorld - QtCreator - Build Settings",width:"760"}),(0,l.kt)("p",null,"Disable ",(0,l.kt)("inlineCode",{parentName:"p"},"QML debugging and profiling")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"Qt Quick Compiler"),", they are not used."),(0,l.kt)("p",null,"In the left sidebar open ",(0,l.kt)("inlineCode",{parentName:"p"},"Dependencies")," and check ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," project and ",(0,l.kt)("inlineCode",{parentName:"p"},"Synchronize configuration"),", this setting ensures that the current project will be rebuilt correctly when the ",(0,l.kt)("inlineCode",{parentName:"p"},"TinyORM")," library source code changes."),(0,l.kt)("p",null,"Everything is ready to build, you can press ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"b")," to build the project."),(0,l.kt)("h3",{id:"execute-hello-world-qmake"},"Execute Hello world"),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"QtCreator")," takes care of all the necessary configurations, sets up the build environment correctly, and also prepends dependency libraries on the system path on Windows and on the ",(0,l.kt)("inlineCode",{parentName:"p"},"LD_LIBRARY_PATH")," on Linux."),(0,l.kt)("p",null,"The only thing you might want to change is to run the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example in the new terminal window. To do so, hit ",(0,l.kt)("kbd",null,"Ctrl"),"+",(0,l.kt)("kbd",null,"5")," to open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Project Settings")," tab and select ",(0,l.kt)("inlineCode",{parentName:"p"},"Run")," in the left sidebar to open the ",(0,l.kt)("inlineCode",{parentName:"p"},"Run Settings"),", then in the ",(0,l.kt)("inlineCode",{parentName:"p"},"Run")," section select the ",(0,l.kt)("inlineCode",{parentName:"p"},"Run in terminal")," checkbox."),(0,l.kt)("p",null,"To execute the ",(0,l.kt)("inlineCode",{parentName:"p"},"HelloWorld")," example press ",(0,l.kt)("kbd",null,"Ctrl")," + ",(0,l.kt)("kbd",null,"r"),"."),(0,l.kt)("p",null,"The output will look like this."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-less"},'Executed prepared query (6ms, -1 results, 0 affected, tinyorm_default) : select * from posts\n1 "First Post"\n2 "Second Post"\n')))}b.isMDXComponent=!0},6511:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-build_settings-ebdc6c0c056d11462096ff10cba682a1.png"},1465:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/qmake-configure_project-8caf87e6af4452f0c28bd15c85c392fc.png"}}]); \ No newline at end of file diff --git a/assets/js/main.b1605669.js b/assets/js/main.b1605669.js new file mode 100644 index 000000000..779da8c20 --- /dev/null +++ b/assets/js/main.b1605669.js @@ -0,0 +1,2 @@ +/*! For license information please see main.b1605669.js.LICENSE.txt */ +(self.webpackChunktinyorm_org=self.webpackChunktinyorm_org||[]).push([[179],{830:(e,t,n)=>{"use strict";n.d(t,{W:()=>a});var r=n(7294);function a(){return r.createElement("svg",{width:"20",height:"20",className:"DocSearch-Search-Icon",viewBox:"0 0 20 20"},r.createElement("path",{d:"M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z",stroke:"currentColor",fill:"none",fillRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round"}))}},723:(e,t,n)=>{"use strict";n.d(t,{Z:()=>p});var r=n(7294),a=n(7462),o=n(8356),i=n.n(o),l=n(6887);const s={"0ab078a9":[()=>Promise.all([n.e(532),n.e(176),n.e(969)]).then(n.bind(n,4040)),"@site/docs/building/tinyorm.mdx",4040],"1222ea4e":[()=>n.e(535).then(n.bind(n,1412)),"@site/docs/tinyorm/serialization.mdx",1412],17896441:[()=>Promise.all([n.e(532),n.e(176),n.e(918)]).then(n.bind(n,5836)),"@theme/DocItem",5836],"1a4e3797":[()=>Promise.all([n.e(532),n.e(920)]).then(n.bind(n,6675)),"@theme/SearchPage",6675],"1be78505":[()=>Promise.all([n.e(532),n.e(514)]).then(n.bind(n,9963)),"@theme/DocPage",9963],"21dc2778":[()=>Promise.all([n.e(532),n.e(176),n.e(291)]).then(n.bind(n,6122)),"@site/docs/database/migrations.mdx",6122],"3dd307b5":[()=>n.e(108).then(n.bind(n,8503)),"@site/docs/tinyorm/collections.mdx",8503],"59b1a96c":[()=>n.e(67).then(n.bind(n,2075)),"@site/docs/README.mdx",2075],"5b254f70":[()=>n.e(116).then(n.bind(n,7923)),"@site/docs/tinyorm/getting-started.mdx",7923],"62a1276f":[()=>n.e(57).then(n.bind(n,9823)),"@site/docs/tinyorm/casts.mdx",9823],"7333c691":[()=>n.e(799).then(n.bind(n,7273)),"@site/docs/tinyorm/relationships.mdx",7273],"8156e19a":[()=>n.e(683).then(n.t.bind(n,3769,19)),"E:\\code\\nodejs\\TinyORM-github.io\\.docusaurus\\docusaurus-plugin-content-docs\\default\\plugin-route-context-module-100.json",3769],"8a8faf8d":[()=>Promise.all([n.e(532),n.e(176),n.e(225)]).then(n.bind(n,3974)),"@site/docs/building/migrations.mdx",3974],"935f2afb":[()=>n.e(53).then(n.t.bind(n,1109,19)),"~docs/default/version-current-metadata-prop-751.json",1109],a4d3e054:[()=>n.e(454).then(n.bind(n,8261)),"@site/docs/database/seeding.mdx",8261],ba3d4959:[()=>Promise.all([n.e(532),n.e(784)]).then(n.bind(n,288)),"@site/docs/database/getting-started.mdx",288],cb1e72f9:[()=>n.e(684).then(n.bind(n,5955)),"@site/docs/tinydrivers/getting-started.mdx",5955],cbe663fe:[()=>n.e(594).then(n.bind(n,9542)),"@site/docs/database/query-builder.mdx",9542],cdf0eeb2:[()=>n.e(113).then(n.t.bind(n,7085,19)),"E:\\code\\nodejs\\TinyORM-github.io\\.docusaurus\\docusaurus-theme-search-algolia\\default\\plugin-route-context-module-100.json",7085],d459b1c4:[()=>n.e(966).then(n.bind(n,4742)),"@site/docs/supported-compilers.mdx",4742],e19c288b:[()=>Promise.all([n.e(532),n.e(865)]).then(n.bind(n,6903)),"@site/docs/sponsors.mdx",6903],e3ac21cb:[()=>n.e(8).then(n.bind(n,5136)),"@site/docs/dependencies.mdx",5136],fb313d4e:[()=>n.e(832).then(n.bind(n,4716)),"@site/docs/features-summary.mdx",4716],feaee7f3:[()=>Promise.all([n.e(532),n.e(176),n.e(168)]).then(n.bind(n,4588)),"@site/docs/building/hello-world.mdx",4588]};function u(e){let{error:t,retry:n,pastDelay:a}=e;return t?r.createElement("div",{style:{textAlign:"center",color:"#fff",backgroundColor:"#fa383e",borderColor:"#fa383e",borderStyle:"solid",borderRadius:"0.25rem",borderWidth:"1px",boxSizing:"border-box",display:"block",padding:"1rem",flex:"0 0 50%",marginLeft:"25%",marginRight:"25%",marginTop:"5rem",maxWidth:"50%",width:"100%"}},r.createElement("p",null,String(t)),r.createElement("div",null,r.createElement("button",{type:"button",onClick:n},"Retry"))):a?r.createElement("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"}},r.createElement("svg",{id:"loader",style:{width:128,height:110,position:"absolute",top:"calc(100vh - 64%)"},viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",stroke:"#61dafb"},r.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(1 1)",strokeWidth:"2"},r.createElement("circle",{cx:"22",cy:"22",r:"6",strokeOpacity:"0"},r.createElement("animate",{attributeName:"r",begin:"1.5s",dur:"3s",values:"6;22",calcMode:"linear",repeatCount:"indefinite"}),r.createElement("animate",{attributeName:"stroke-opacity",begin:"1.5s",dur:"3s",values:"1;0",calcMode:"linear",repeatCount:"indefinite"}),r.createElement("animate",{attributeName:"stroke-width",begin:"1.5s",dur:"3s",values:"2;0",calcMode:"linear",repeatCount:"indefinite"})),r.createElement("circle",{cx:"22",cy:"22",r:"6",strokeOpacity:"0"},r.createElement("animate",{attributeName:"r",begin:"3s",dur:"3s",values:"6;22",calcMode:"linear",repeatCount:"indefinite"}),r.createElement("animate",{attributeName:"stroke-opacity",begin:"3s",dur:"3s",values:"1;0",calcMode:"linear",repeatCount:"indefinite"}),r.createElement("animate",{attributeName:"stroke-width",begin:"3s",dur:"3s",values:"2;0",calcMode:"linear",repeatCount:"indefinite"})),r.createElement("circle",{cx:"22",cy:"22",r:"8"},r.createElement("animate",{attributeName:"r",begin:"0s",dur:"1.5s",values:"6;1;2;3;4;5;6",calcMode:"linear",repeatCount:"indefinite"}))))):null}var c=n(9670),d=n(226);function f(e,t){if("*"===e)return i()({loading:u,loader:()=>n.e(972).then(n.bind(n,4972)),modules:["@theme/NotFound"],webpack:()=>[4972],render(e,t){const n=e.default;return r.createElement(d.z,{value:{plugin:{name:"native",id:"default"}}},r.createElement(n,t))}});const o=l[`${e}-${t}`],f={},p=[],m=[],h=(0,c.Z)(o);return Object.entries(h).forEach((e=>{let[t,n]=e;const r=s[n];r&&(f[t]=r[0],p.push(r[1]),m.push(r[2]))})),i().Map({loading:u,loader:f,modules:p,webpack:()=>m,render(t,n){const i=JSON.parse(JSON.stringify(o));Object.entries(t).forEach((t=>{let[n,r]=t;const a=r.default;if(!a)throw new Error(`The page component at ${e} doesn't have a default export. This makes it impossible to render anything. Consider default-exporting a React component.`);"object"!=typeof a&&"function"!=typeof a||Object.keys(r).filter((e=>"default"!==e)).forEach((e=>{a[e]=r[e]}));let o=i;const l=n.split(".");l.slice(0,-1).forEach((e=>{o=o[e]})),o[l[l.length-1]]=a}));const l=i.__comp;delete i.__comp;const s=i.__context;return delete i.__context,r.createElement(d.z,{value:s},r.createElement(l,(0,a.Z)({},i,n)))}})}const p=[{path:"/search",component:f("/search","c88"),exact:!0},{path:"/",component:f("/","848"),routes:[{path:"/",component:f("/","b76"),exact:!0,sidebar:"tinyormSidebar"},{path:"/building/hello-world",component:f("/building/hello-world","acb"),exact:!0,sidebar:"tinyormSidebar"},{path:"/building/migrations",component:f("/building/migrations","06d"),exact:!0,sidebar:"tinyormSidebar"},{path:"/building/tinyorm",component:f("/building/tinyorm","b42"),exact:!0,sidebar:"tinyormSidebar"},{path:"/database/getting-started",component:f("/database/getting-started","cc8"),exact:!0,sidebar:"tinyormSidebar"},{path:"/database/migrations",component:f("/database/migrations","15a"),exact:!0,sidebar:"tinyormSidebar"},{path:"/database/query-builder",component:f("/database/query-builder","258"),exact:!0,sidebar:"tinyormSidebar"},{path:"/database/seeding",component:f("/database/seeding","358"),exact:!0,sidebar:"tinyormSidebar"},{path:"/dependencies",component:f("/dependencies","a89"),exact:!0,sidebar:"tinyormSidebar"},{path:"/features-summary",component:f("/features-summary","652"),exact:!0,sidebar:"tinyormSidebar"},{path:"/sponsors",component:f("/sponsors","c1d"),exact:!0,sidebar:"tinyormSidebar"},{path:"/supported-compilers",component:f("/supported-compilers","24e"),exact:!0,sidebar:"tinyormSidebar"},{path:"/tinydrivers/getting-started",component:f("/tinydrivers/getting-started","d48"),exact:!0,sidebar:"tinyormSidebar"},{path:"/tinyorm/casts",component:f("/tinyorm/casts","331"),exact:!0,sidebar:"tinyormSidebar"},{path:"/tinyorm/collections",component:f("/tinyorm/collections","35b"),exact:!0,sidebar:"tinyormSidebar"},{path:"/tinyorm/getting-started",component:f("/tinyorm/getting-started","715"),exact:!0,sidebar:"tinyormSidebar"},{path:"/tinyorm/relationships",component:f("/tinyorm/relationships","04a"),exact:!0,sidebar:"tinyormSidebar"},{path:"/tinyorm/serialization",component:f("/tinyorm/serialization","9c7"),exact:!0,sidebar:"tinyormSidebar"}]},{path:"*",component:f("*")}]},8934:(e,t,n)=>{"use strict";n.d(t,{_:()=>a,t:()=>o});var r=n(7294);const a=r.createContext(!1);function o(e){let{children:t}=e;const[n,o]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{o(!0)}),[]),r.createElement(a.Provider,{value:n},t)}},85:(e,t,n)=>{"use strict";var r=n(7294),a=n(3935),o=n(3727),i=n(405),l=n(412);const s=[n(6657),n(2497),n(7021),n(8320),n(8213)];var u=n(723),c=n(6550),d=n(8790),f=n(9482),p=n(12);const m="tinyorm.rootFolder.",h=()=>{const[e,t]=(0,r.useState)({}),n=(0,r.useCallback)(((e,t)=>{(0,p.WA)(`${m}${e}`).set(t)}),[]);return(0,r.useEffect)((()=>{try{const e={};(0,p._f)().forEach((t=>{if(t.startsWith(m)){const n=t.substring(19);e[n]=(0,p.WA)(t).get()}})),t(e)}catch(e){console.error(e)}}),[]),{rootFolder:e,setRootFolder:(e,r)=>{t((t=>({...t,[e]:r}))),n(e,r)}}};function g(e){const{rootFolder:t,setRootFolder:n}=h(),a=(0,r.useMemo)((()=>({rootFolder:t,setRootFolder:n})),[t,n]);return r.createElement(f.Z.Provider,{value:a},e.children)}let b,v,y,E=0;function S(){const e=document.querySelector('.theme-doc-sidebar-container div[title="Expand sidebar"]');e&&(e.title+=" (q)",clearTimeout(v))}function _(){y=document.querySelector(".theme-doc-sidebar-container > div > div > button"),E>=50?clearInterval(b):y?(y.title+=" (q)",clearInterval(b),y.addEventListener("click",(()=>{v=setTimeout(S,300)}))):++E}function w(e){e.target.isContentEditable||"INPUT"===e.target.nodeName||"TEXTAREA"===e.target.nodeName||"SELECT"===e.target.nodeName||"KeyQ"===e.code&&(y.click(),v=setTimeout(S,300))}function T(){var e;e=()=>{b=setInterval(_,30),document.addEventListener("keyup",w)},"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e)}function k(e){let{children:t}=e;return r.createElement(g,null,t)}l.Z.canUseDOM&&T();var C=n(7462),A=n(5742),I=n(2263),O=n(4996),R=n(6668),N=n(833),L=n(4711),P=n(9727),x=n(3320),D=n(8780),M=n(197);function U(){const{i18n:{defaultLocale:e,localeConfigs:t}}=(0,I.Z)(),n=(0,L.l)();return r.createElement(A.Z,null,Object.entries(t).map((e=>{let[t,{htmlLang:a}]=e;return r.createElement("link",{key:t,rel:"alternate",href:n.createUrl({locale:t,fullyQualified:!0}),hrefLang:a})})),r.createElement("link",{rel:"alternate",href:n.createUrl({locale:e,fullyQualified:!0}),hrefLang:"x-default"}))}function F(e){let{permalink:t}=e;const{siteConfig:{url:n}}=(0,I.Z)(),a=function(){const{siteConfig:{url:e,baseUrl:t,trailingSlash:n}}=(0,I.Z)(),{pathname:r}=(0,c.TH)();return e+(0,D.applyTrailingSlash)((0,O.Z)(r),{trailingSlash:n,baseUrl:t})}(),o=t?`${n}${t}`:a;return r.createElement(A.Z,null,r.createElement("meta",{property:"og:url",content:o}),r.createElement("link",{rel:"canonical",href:o}))}function B(){const{i18n:{currentLocale:e}}=(0,I.Z)(),{metadata:t,image:n}=(0,R.L)();return r.createElement(r.Fragment,null,r.createElement(A.Z,null,r.createElement("meta",{name:"twitter:card",content:"summary_large_image"}),r.createElement("body",{className:P.h})),n&&r.createElement(N.d,{image:n}),r.createElement(F,null),r.createElement(U,null),r.createElement(M.Z,{tag:x.HX,locale:e}),r.createElement(A.Z,null,t.map(((e,t)=>r.createElement("meta",(0,C.Z)({key:t},e))))))}const $=new Map;function z(e){if($.has(e.pathname))return{...e,pathname:$.get(e.pathname)};if((0,d.f)(u.Z,e.pathname).some((e=>{let{route:t}=e;return!0===t.exact})))return $.set(e.pathname,e.pathname),e;const t=e.pathname.trim().replace(/(?:\/index)?\.html$/,"")||"/";return $.set(e.pathname,t),{...e,pathname:t}}var H=n(8934),j=n(8940);function G(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r{const r=t.default?.[e]??t[e];return r?.(...n)}));return()=>a.forEach((e=>e?.()))}const Z=function(e){let{children:t,location:n,previousLocation:a}=e;return(0,r.useLayoutEffect)((()=>{a!==n&&(!function(e){let{location:t,previousLocation:n}=e;if(!n)return;const r=t.pathname===n.pathname,a=t.hash===n.hash,o=t.search===n.search;if(r&&a&&!o)return;const{hash:i}=t;if(i){const e=decodeURIComponent(i.substring(1)),t=document.getElementById(e);t?.scrollIntoView()}else window.scrollTo(0,0)}({location:n,previousLocation:a}),G("onRouteDidUpdate",{previousLocation:a,location:n}))}),[a,n]),t};function V(e){const t=Array.from(new Set([e,decodeURI(e)])).map((e=>(0,d.f)(u.Z,e))).flat();return Promise.all(t.map((e=>e.route.component.preload?.())))}class W extends r.Component{previousLocation;routeUpdateCleanupCb;constructor(e){super(e),this.previousLocation=null,this.routeUpdateCleanupCb=l.Z.canUseDOM?G("onRouteUpdate",{previousLocation:null,location:this.props.location}):()=>{},this.state={nextRouteHasLoaded:!0}}shouldComponentUpdate(e,t){if(e.location===this.props.location)return t.nextRouteHasLoaded;const n=e.location;return this.previousLocation=this.props.location,this.setState({nextRouteHasLoaded:!1}),this.routeUpdateCleanupCb=G("onRouteUpdate",{previousLocation:this.previousLocation,location:n}),V(n.pathname).then((()=>{this.routeUpdateCleanupCb(),this.setState({nextRouteHasLoaded:!0})})).catch((e=>{console.warn(e),window.location.reload()})),!1}render(){const{children:e,location:t}=this.props;return r.createElement(Z,{previousLocation:this.previousLocation,location:t},r.createElement(c.AW,{location:t,render:()=>e}))}}const Y=W,K="__docusaurus-base-url-issue-banner-container",X="__docusaurus-base-url-issue-banner",q="__docusaurus-base-url-issue-banner-suggestion-container",Q="__DOCUSAURUS_INSERT_BASEURL_BANNER";function J(e){return`\nwindow['${Q}'] = true;\n\ndocument.addEventListener('DOMContentLoaded', maybeInsertBanner);\n\nfunction maybeInsertBanner() {\n var shouldInsert = window['${Q}'];\n shouldInsert && insertBanner();\n}\n\nfunction insertBanner() {\n var bannerContainer = document.getElementById('${K}');\n if (!bannerContainer) {\n return;\n }\n var bannerHtml = ${JSON.stringify(function(e){return`\n
\n

Your Docusaurus site did not load properly.

\n

A very common reason is a wrong site baseUrl configuration.

\n

Current configured baseUrl = ${e} ${"/"===e?" (default value)":""}

\n

We suggest trying baseUrl =

\n
\n`}(e)).replace(/{window[Q]=!1}),[]),r.createElement(r.Fragment,null,!l.Z.canUseDOM&&r.createElement(A.Z,null,r.createElement("script",null,J(e))),r.createElement("div",{id:K}))}function te(){const{siteConfig:{baseUrl:e,baseUrlIssueBanner:t}}=(0,I.Z)(),{pathname:n}=(0,c.TH)();return t&&n===e?r.createElement(ee,null):null}function ne(){const{siteConfig:{favicon:e,title:t,noIndex:n},i18n:{currentLocale:a,localeConfigs:o}}=(0,I.Z)(),i=(0,O.Z)(e),{htmlLang:l,direction:s}=o[a];return r.createElement(A.Z,null,r.createElement("html",{lang:l,dir:s}),r.createElement("title",null,t),r.createElement("meta",{property:"og:title",content:t}),r.createElement("meta",{name:"viewport",content:"width=device-width, initial-scale=1.0"}),n&&r.createElement("meta",{name:"robots",content:"noindex, nofollow"}),e&&r.createElement("link",{rel:"icon",href:i}))}var re=n(4763),ae=n(2389);function oe(){const e=(0,ae.Z)();return r.createElement(A.Z,null,r.createElement("html",{"data-has-hydrated":e}))}function ie(){const e=(0,d.H)(u.Z),t=(0,c.TH)();return r.createElement(re.Z,null,r.createElement(j.M,null,r.createElement(H.t,null,r.createElement(k,null,r.createElement(ne,null),r.createElement(B,null),r.createElement(te,null),r.createElement(Y,{location:z(t)},e)),r.createElement(oe,null))))}var le=n(6887);const se=function(e){try{return document.createElement("link").relList.supports(e)}catch{return!1}}("prefetch")?function(e){return new Promise(((t,n)=>{if("undefined"==typeof document)return void n();const r=document.createElement("link");r.setAttribute("rel","prefetch"),r.setAttribute("href",e),r.onload=()=>t(),r.onerror=()=>n();const a=document.getElementsByTagName("head")[0]??document.getElementsByName("script")[0]?.parentNode;a?.appendChild(r)}))}:function(e){return new Promise(((t,n)=>{const r=new XMLHttpRequest;r.open("GET",e,!0),r.withCredentials=!0,r.onload=()=>{200===r.status?t():n()},r.send(null)}))};var ue=n(9670);const ce=new Set,de=new Set,fe=()=>navigator.connection?.effectiveType.includes("2g")||navigator.connection?.saveData,pe={prefetch(e){if(!(e=>!fe()&&!de.has(e)&&!ce.has(e))(e))return!1;ce.add(e);const t=(0,d.f)(u.Z,e).flatMap((e=>{return t=e.route.path,Object.entries(le).filter((e=>{let[n]=e;return n.replace(/-[^-]+$/,"")===t})).flatMap((e=>{let[,t]=e;return Object.values((0,ue.Z)(t))}));var t}));return Promise.all(t.map((e=>{const t=n.gca(e);return t&&!t.includes("undefined")?se(t).catch((()=>{})):Promise.resolve()})))},preload:e=>!!(e=>!fe()&&!de.has(e))(e)&&(de.add(e),V(e))},me=Object.freeze(pe);if(l.Z.canUseDOM){window.docusaurus=me;const e=a.hydrate;V(window.location.pathname).then((()=>{e(r.createElement(i.B6,null,r.createElement(o.VK,null,r.createElement(ie,null))),document.getElementById("__docusaurus"))}))}},8940:(e,t,n)=>{"use strict";n.d(t,{_:()=>c,M:()=>d});var r=n(7294),a=n(6809);const o=JSON.parse('{"docusaurus-plugin-google-gtag":{"default":{"trackingID":["G-2QRS622BWQ"],"anonymizeIP":false,"id":"default"}},"docusaurus-plugin-content-docs":{"default":{"path":"/","versions":[{"name":"current","label":"Next","isLast":true,"path":"/","mainDocId":"README","docs":[{"id":"building/hello-world","path":"/building/hello-world","sidebar":"tinyormSidebar"},{"id":"building/migrations","path":"/building/migrations","sidebar":"tinyormSidebar"},{"id":"building/tinyorm","path":"/building/tinyorm","sidebar":"tinyormSidebar"},{"id":"database/getting-started","path":"/database/getting-started","sidebar":"tinyormSidebar"},{"id":"database/migrations","path":"/database/migrations","sidebar":"tinyormSidebar"},{"id":"database/query-builder","path":"/database/query-builder","sidebar":"tinyormSidebar"},{"id":"database/seeding","path":"/database/seeding","sidebar":"tinyormSidebar"},{"id":"dependencies","path":"/dependencies","sidebar":"tinyormSidebar"},{"id":"features-summary","path":"/features-summary","sidebar":"tinyormSidebar"},{"id":"README","path":"/","sidebar":"tinyormSidebar"},{"id":"sponsors","path":"/sponsors","sidebar":"tinyormSidebar"},{"id":"supported-compilers","path":"/supported-compilers","sidebar":"tinyormSidebar"},{"id":"tinydrivers/getting-started","path":"/tinydrivers/getting-started","sidebar":"tinyormSidebar"},{"id":"tinyorm/casts","path":"/tinyorm/casts","sidebar":"tinyormSidebar"},{"id":"tinyorm/collections","path":"/tinyorm/collections","sidebar":"tinyormSidebar"},{"id":"tinyorm/getting-started","path":"/tinyorm/getting-started","sidebar":"tinyormSidebar"},{"id":"tinyorm/relationships","path":"/tinyorm/relationships","sidebar":"tinyormSidebar"},{"id":"tinyorm/serialization","path":"/tinyorm/serialization","sidebar":"tinyormSidebar"}],"draftIds":[],"sidebars":{"tinyormSidebar":{"link":{"path":"/","label":"\ud83d\udd25 Prologue"}}}}],"breadcrumbs":true}}}'),i=JSON.parse('{"defaultLocale":"en","locales":["en"],"path":"i18n","currentLocale":"en","localeConfigs":{"en":{"label":"English","direction":"ltr","htmlLang":"en","calendar":"gregory","path":"en"}}}');var l=n(7529);const s=JSON.parse('{"docusaurusVersion":"2.4.3","siteVersion":"0.3.3","pluginVersions":{"docusaurus-plugin-content-docs":{"type":"package","name":"@docusaurus/plugin-content-docs","version":"2.4.3"},"docusaurus-plugin-content-pages":{"type":"package","name":"@docusaurus/plugin-content-pages","version":"2.4.3"},"docusaurus-plugin-google-gtag":{"type":"package","name":"@docusaurus/plugin-google-gtag","version":"2.4.3"},"docusaurus-plugin-sitemap":{"type":"package","name":"@docusaurus/plugin-sitemap","version":"2.4.3"},"docusaurus-theme-classic":{"type":"package","name":"@docusaurus/theme-classic","version":"2.4.3"},"docusaurus-theme-search-algolia":{"type":"package","name":"@docusaurus/theme-search-algolia","version":"2.4.3"},"docusaurus-plugin-client-redirects":{"type":"package","name":"@docusaurus/plugin-client-redirects","version":"2.4.3"},"webpack-configuration-plugin":{"type":"local"},"postcss-configuration-plugin":{"type":"local"},"tiny-common":{"type":"local"}}}'),u={siteConfig:a.default,siteMetadata:s,globalData:o,i18n:i,codeTranslations:l},c=r.createContext(u);function d(e){let{children:t}=e;return r.createElement(c.Provider,{value:u},t)}},4763:(e,t,n)=>{"use strict";n.d(t,{Z:()=>f});var r=n(7294),a=n(412),o=n(5742),i=n(8780),l=n(7452);function s(e){let{error:t,tryAgain:n}=e;return r.createElement("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"flex-start",minHeight:"100vh",width:"100%",maxWidth:"80ch",fontSize:"20px",margin:"0 auto",padding:"1rem"}},r.createElement("h1",{style:{fontSize:"3rem"}},"This page crashed"),r.createElement("button",{type:"button",onClick:n,style:{margin:"1rem 0",fontSize:"2rem",cursor:"pointer",borderRadius:20,padding:"1rem"}},"Try again"),r.createElement(u,{error:t}))}function u(e){let{error:t}=e;const n=(0,i.getErrorCausalChain)(t).map((e=>e.message)).join("\n\nCause:\n");return r.createElement("p",{style:{whiteSpace:"pre-wrap"}},n)}function c(e){let{error:t,tryAgain:n}=e;return r.createElement(f,{fallback:()=>r.createElement(s,{error:t,tryAgain:n})},r.createElement(o.Z,null,r.createElement("title",null,"Page Error")),r.createElement(l.Z,null,r.createElement(s,{error:t,tryAgain:n})))}const d=e=>r.createElement(c,e);class f extends r.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){a.Z.canUseDOM&&this.setState({error:e})}render(){const{children:e}=this.props,{error:t}=this.state;if(t){const e={error:t,tryAgain:()=>this.setState({error:null})};return(this.props.fallback??d)(e)}return e??null}}},412:(e,t,n)=>{"use strict";n.d(t,{Z:()=>a});const r="undefined"!=typeof window&&"document"in window&&"createElement"in window.document,a={canUseDOM:r,canUseEventListeners:r&&("addEventListener"in window||"attachEvent"in window),canUseIntersectionObserver:r&&"IntersectionObserver"in window,canUseViewport:r&&"screen"in window}},5742:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294),a=n(405);function o(e){return r.createElement(a.ql,e)}},9960:(e,t,n)=>{"use strict";n.d(t,{Z:()=>p});var r=n(7462),a=n(7294),o=n(3727),i=n(8780),l=n(2263),s=n(3919),u=n(412);const c=a.createContext({collectLink:()=>{}});var d=n(4996);function f(e,t){let{isNavLink:n,to:f,href:p,activeClassName:m,isActive:h,"data-noBrokenLinkCheck":g,autoAddBaseUrl:b=!0,...v}=e;const{siteConfig:{trailingSlash:y,baseUrl:E}}=(0,l.Z)(),{withBaseUrl:S}=(0,d.C)(),_=(0,a.useContext)(c),w=(0,a.useRef)(null);(0,a.useImperativeHandle)(t,(()=>w.current));const T=f||p;const k=(0,s.Z)(T),C=T?.replace("pathname://","");let A=void 0!==C?(I=C,b&&(e=>e.startsWith("/"))(I)?S(I):I):void 0;var I;A&&k&&(A=(0,i.applyTrailingSlash)(A,{trailingSlash:y,baseUrl:E}));const O=(0,a.useRef)(!1),R=n?o.OL:o.rU,N=u.Z.canUseIntersectionObserver,L=(0,a.useRef)(),P=()=>{O.current||null==A||(window.docusaurus.preload(A),O.current=!0)};(0,a.useEffect)((()=>(!N&&k&&null!=A&&window.docusaurus.prefetch(A),()=>{N&&L.current&&L.current.disconnect()})),[L,A,N,k]);const x=A?.startsWith("#")??!1,D=!A||!k||x;return D||g||_.collectLink(A),D?a.createElement("a",(0,r.Z)({ref:w,href:A},T&&!k&&{target:"_blank",rel:"noopener noreferrer"},v)):a.createElement(R,(0,r.Z)({},v,{onMouseEnter:P,onTouchStart:P,innerRef:e=>{w.current=e,N&&e&&k&&(L.current=new window.IntersectionObserver((t=>{t.forEach((t=>{e===t.target&&(t.isIntersecting||t.intersectionRatio>0)&&(L.current.unobserve(e),L.current.disconnect(),null!=A&&window.docusaurus.prefetch(A))}))})),L.current.observe(e))},to:A},n&&{isActive:h,activeClassName:m}))}const p=a.forwardRef(f)},5999:(e,t,n)=>{"use strict";n.d(t,{Z:()=>s,I:()=>l});var r=n(7294);function a(e,t){const n=e.split(/(\{\w+\})/).map(((e,n)=>{if(n%2==1){const n=t?.[e.slice(1,-1)];if(void 0!==n)return n}return e}));return n.some((e=>(0,r.isValidElement)(e)))?n.map(((e,t)=>(0,r.isValidElement)(e)?r.cloneElement(e,{key:t}):e)).filter((e=>""!==e)):n.join("")}var o=n(7529);function i(e){let{id:t,message:n}=e;if(void 0===t&&void 0===n)throw new Error("Docusaurus translation declarations must have at least a translation id or a default translation message");return o[t??n]??n??t}function l(e,t){let{message:n,id:r}=e;return a(i({message:n,id:r}),t)}function s(e){let{children:t,id:n,values:o}=e;if(t&&"string"!=typeof t)throw console.warn("Illegal children",t),new Error("The Docusaurus component only accept simple string values");const l=i({message:t,id:n});return r.createElement(r.Fragment,null,a(l,o))}},9935:(e,t,n)=>{"use strict";n.d(t,{m:()=>r});const r="default"},3919:(e,t,n)=>{"use strict";function r(e){return/^(?:\w*:|\/\/)/.test(e)}function a(e){return void 0!==e&&!r(e)}n.d(t,{Z:()=>a,b:()=>r})},4996:(e,t,n)=>{"use strict";n.d(t,{C:()=>i,Z:()=>l});var r=n(7294),a=n(2263),o=n(3919);function i(){const{siteConfig:{baseUrl:e,url:t}}=(0,a.Z)(),n=(0,r.useCallback)(((n,r)=>function(e,t,n,r){let{forcePrependBaseUrl:a=!1,absolute:i=!1}=void 0===r?{}:r;if(!n||n.startsWith("#")||(0,o.b)(n))return n;if(a)return t+n.replace(/^\//,"");if(n===t.replace(/\/$/,""))return t;const l=n.startsWith(t)?n:t+n.replace(/^\//,"");return i?e+l:l}(t,e,n,r)),[t,e]);return{withBaseUrl:n}}function l(e,t){void 0===t&&(t={});const{withBaseUrl:n}=i();return n(e,t)}},2263:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294),a=n(8940);function o(){return(0,r.useContext)(a._)}},2389:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294),a=n(8934);function o(){return(0,r.useContext)(a._)}},9670:(e,t,n)=>{"use strict";n.d(t,{Z:()=>a});const r=e=>"object"==typeof e&&!!e&&Object.keys(e).length>0;function a(e){const t={};return function e(n,a){Object.entries(n).forEach((n=>{let[o,i]=n;const l=a?`${a}.${o}`:o;r(i)?e(i,l):t[l]=i}))}(e),t}},226:(e,t,n)=>{"use strict";n.d(t,{_:()=>a,z:()=>o});var r=n(7294);const a=r.createContext(null);function o(e){let{children:t,value:n}=e;const o=r.useContext(a),i=(0,r.useMemo)((()=>function(e){let{parent:t,value:n}=e;if(!t){if(!n)throw new Error("Unexpected: no Docusaurus route context found");if(!("plugin"in n))throw new Error("Unexpected: Docusaurus topmost route context has no `plugin` attribute");return n}const r={...t.data,...n?.data};return{plugin:t.plugin,data:r}}({parent:o,value:n})),[o,n]);return r.createElement(a.Provider,{value:i},t)}},143:(e,t,n)=>{"use strict";n.d(t,{Iw:()=>b,gA:()=>p,WS:()=>m,_r:()=>d,Jo:()=>v,zh:()=>f,yW:()=>g,gB:()=>h});var r=n(6550),a=n(2263),o=n(9935);function i(e,t){void 0===t&&(t={});const n=function(){const{globalData:e}=(0,a.Z)();return e}()[e];if(!n&&t.failfast)throw new Error(`Docusaurus plugin global data not found for "${e}" plugin.`);return n}const l=e=>e.versions.find((e=>e.isLast));function s(e,t){const n=l(e);return[...e.versions.filter((e=>e!==n)),n].find((e=>!!(0,r.LX)(t,{path:e.path,exact:!1,strict:!1})))}function u(e,t){const n=s(e,t),a=n?.docs.find((e=>!!(0,r.LX)(t,{path:e.path,exact:!0,strict:!1})));return{activeVersion:n,activeDoc:a,alternateDocVersions:a?function(t){const n={};return e.versions.forEach((e=>{e.docs.forEach((r=>{r.id===t&&(n[e.name]=r)}))})),n}(a.id):{}}}const c={},d=()=>i("docusaurus-plugin-content-docs")??c,f=e=>function(e,t,n){void 0===t&&(t=o.m),void 0===n&&(n={});const r=i(e),a=r?.[t];if(!a&&n.failfast)throw new Error(`Docusaurus plugin global data not found for "${e}" plugin with id "${t}".`);return a}("docusaurus-plugin-content-docs",e,{failfast:!0});function p(e){void 0===e&&(e={});const t=d(),{pathname:n}=(0,r.TH)();return function(e,t,n){void 0===n&&(n={});const a=Object.entries(e).sort(((e,t)=>t[1].path.localeCompare(e[1].path))).find((e=>{let[,n]=e;return!!(0,r.LX)(t,{path:n.path,exact:!1,strict:!1})})),o=a?{pluginId:a[0],pluginData:a[1]}:void 0;if(!o&&n.failfast)throw new Error(`Can't find active docs plugin for "${t}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(e).map((e=>e.path)).join(", ")}`);return o}(t,n,e)}function m(e){void 0===e&&(e={});const t=p(e),{pathname:n}=(0,r.TH)();if(!t)return;return{activePlugin:t,activeVersion:s(t.pluginData,n)}}function h(e){return f(e).versions}function g(e){const t=f(e);return l(t)}function b(e){const t=f(e),{pathname:n}=(0,r.TH)();return u(t,n)}function v(e){const t=f(e),{pathname:n}=(0,r.TH)();return function(e,t){const n=l(e);return{latestDocSuggestion:u(e,t).alternateDocVersions[n.name],latestVersionSuggestion:n}}(t,n)}},6657:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>r});const r={onRouteDidUpdate(e){let{location:t,previousLocation:n}=e;!n||t.pathname===n.pathname&&t.search===n.search&&t.hash===n.hash||setTimeout((()=>{window.gtag("event","page_view",{page_title:document.title,page_location:window.location.href,page_path:t.pathname+t.search+t.hash})}))}}},8320:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>o});var r=n(4865),a=n.n(r);a().configure({showSpinner:!1});const o={onRouteUpdate(e){let{location:t,previousLocation:n}=e;if(n&&t.pathname!==n.pathname){const e=window.setTimeout((()=>{a().start()}),200);return()=>window.clearTimeout(e)}},onRouteDidUpdate(){a().done()}}},7021:(e,t,n)=>{"use strict";n.r(t);var r=n(7410),a=n(412),o=n(6809);const i=e=>{if(!a.Z.canUseDOM)return;const{themeConfig:{prism:t={}}}=o.default,{additionalLanguages:r=[]}=t;window.Prism=e,r.forEach((e=>{n(2295)(`./prism-${e}`)}));["qmake","bash"].forEach((e=>{n(7044)(`./prism-${e}`)})),delete window.Prism};i(r.Z)},9471:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294);const a={iconExternalLink:"iconExternalLink_nPIU"};function o(e){let{width:t=13.5,height:n=13.5}=e;return r.createElement("svg",{width:t,height:n,"aria-hidden":"true",viewBox:"0 0 24 24",className:a.iconExternalLink},r.createElement("path",{fill:"currentColor",d:"M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"}))}},7452:(e,t,n)=>{"use strict";n.d(t,{Z:()=>Rt});var r=n(7294),a=n(6010),o=n(4763),i=n(833),l=n(7462),s=n(6550),u=n(5999),c=n(5936);const d="__docusaurus_skipToContent_fallback";function f(e){e.setAttribute("tabindex","-1"),e.focus(),e.removeAttribute("tabindex")}function p(){const e=(0,r.useRef)(null),{action:t}=(0,s.k6)(),n=(0,r.useCallback)((e=>{e.preventDefault();const t=document.querySelector("main:first-of-type")??document.getElementById(d);t&&f(t)}),[]);return(0,c.S)((n=>{let{location:r}=n;e.current&&!r.hash&&"PUSH"===t&&f(e.current)})),{containerRef:e,onClick:n}}const m=(0,u.I)({id:"theme.common.skipToMainContent",description:"The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation",message:"Skip to main content"});function h(e){const t=e.children??m,{containerRef:n,onClick:a}=p();return r.createElement("div",{ref:n,role:"region","aria-label":m},r.createElement("a",(0,l.Z)({},e,{href:`#${d}`,onClick:a}),t))}var g=n(5281),b=n(9727);const v={skipToContent:"skipToContent_fXgn"};function y(){return r.createElement(h,{className:v.skipToContent})}var E=n(6668),S=n(9689);function _(e){let{width:t=21,height:n=21,color:a="currentColor",strokeWidth:o=1.2,className:i,...s}=e;return r.createElement("svg",(0,l.Z)({viewBox:"0 0 15 15",width:t,height:n},s),r.createElement("g",{stroke:a,strokeWidth:o},r.createElement("path",{d:"M.75.75l13.5 13.5M14.25.75L.75 14.25"})))}const w={closeButton:"closeButton_CVFx"};function T(e){return r.createElement("button",(0,l.Z)({type:"button","aria-label":(0,u.I)({id:"theme.AnnouncementBar.closeButtonAriaLabel",message:"Close",description:"The ARIA label for close button of announcement bar"})},e,{className:(0,a.Z)("clean-btn close",w.closeButton,e.className)}),r.createElement(_,{width:14,height:14,strokeWidth:3.1}))}const k={content:"content_knG7"};function C(e){const{announcementBar:t}=(0,E.L)(),{content:n}=t;return r.createElement("div",(0,l.Z)({},e,{className:(0,a.Z)(k.content,e.className),dangerouslySetInnerHTML:{__html:n}}))}const A={announcementBar:"announcementBar_mb4j",announcementBarPlaceholder:"announcementBarPlaceholder_vyr4",announcementBarClose:"announcementBarClose_gvF7",announcementBarContent:"announcementBarContent_xLdY"};function I(){const{announcementBar:e}=(0,E.L)(),{isActive:t,close:n}=(0,S.nT)();if(!t)return null;const{backgroundColor:a,textColor:o,isCloseable:i}=e;return r.createElement("div",{className:A.announcementBar,style:{backgroundColor:a,color:o},role:"banner"},i&&r.createElement("div",{className:A.announcementBarPlaceholder}),r.createElement(C,{className:A.announcementBarContent}),i&&r.createElement(T,{onClick:n,className:A.announcementBarClose}))}var O=n(3163),R=n(2466);var N=n(902),L=n(3102);const P=r.createContext(null);function x(e){let{children:t}=e;const n=function(){const e=(0,O.e)(),t=(0,L.HY)(),[n,a]=(0,r.useState)(!1),o=null!==t.component,i=(0,N.D9)(o);return(0,r.useEffect)((()=>{o&&!i&&a(!0)}),[o,i]),(0,r.useEffect)((()=>{o?e.shown||a(!0):a(!1)}),[e.shown,o]),(0,r.useMemo)((()=>[n,a]),[n])}();return r.createElement(P.Provider,{value:n},t)}function D(e){if(e.component){const t=e.component;return r.createElement(t,e.props)}}function M(){const e=(0,r.useContext)(P);if(!e)throw new N.i6("NavbarSecondaryMenuDisplayProvider");const[t,n]=e,a=(0,r.useCallback)((()=>n(!1)),[n]),o=(0,L.HY)();return(0,r.useMemo)((()=>({shown:t,hide:a,content:D(o)})),[a,o,t])}function U(e){let{header:t,primaryMenu:n,secondaryMenu:o}=e;const{shown:i}=M();return r.createElement("div",{className:"navbar-sidebar"},t,r.createElement("div",{className:(0,a.Z)("navbar-sidebar__items",{"navbar-sidebar__items--show-secondary":i})},r.createElement("div",{className:"navbar-sidebar__item menu"},n),r.createElement("div",{className:"navbar-sidebar__item menu"},o)))}var F=n(2949),B=n(2389);function $(e){return r.createElement("svg",(0,l.Z)({viewBox:"0 0 24 24",width:24,height:24},e),r.createElement("path",{fill:"currentColor",d:"M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"}))}function z(e){return r.createElement("svg",(0,l.Z)({viewBox:"0 0 24 24",width:24,height:24},e),r.createElement("path",{fill:"currentColor",d:"M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"}))}const H={toggle:"toggle_vylO",toggleButton:"toggleButton_gllP",darkToggleIcon:"darkToggleIcon_wfgR",lightToggleIcon:"lightToggleIcon_pyhR",toggleButtonDisabled:"toggleButtonDisabled_aARS"};function j(e){let{className:t,buttonClassName:n,value:o,onChange:i}=e;const l=(0,B.Z)(),s=(0,u.I)({message:"Switch between dark and light mode (currently {mode})",id:"theme.colorToggle.ariaLabel",description:"The ARIA label for the navbar color mode toggle"},{mode:"dark"===o?(0,u.I)({message:"dark mode",id:"theme.colorToggle.ariaLabel.mode.dark",description:"The name for the dark color mode"}):(0,u.I)({message:"light mode",id:"theme.colorToggle.ariaLabel.mode.light",description:"The name for the light color mode"})});return r.createElement("div",{className:(0,a.Z)(H.toggle,t)},r.createElement("button",{className:(0,a.Z)("clean-btn",H.toggleButton,!l&&H.toggleButtonDisabled,n),type:"button",onClick:()=>i("dark"===o?"light":"dark"),disabled:!l,title:s,"aria-label":s,"aria-live":"polite"},r.createElement($,{className:(0,a.Z)(H.toggleIcon,H.lightToggleIcon)}),r.createElement(z,{className:(0,a.Z)(H.toggleIcon,H.darkToggleIcon)})))}const G=r.memo(j),Z={darkNavbarColorModeToggle:"darkNavbarColorModeToggle_X3D1"};function V(e){let{className:t}=e;const n=(0,E.L)().navbar.style,a=(0,E.L)().colorMode.disableSwitch,{colorMode:o,setColorMode:i}=(0,F.I)();return a?null:r.createElement(G,{className:t,buttonClassName:"dark"===n?Z.darkNavbarColorModeToggle:void 0,value:o,onChange:i})}var W=n(1327);function Y(){return r.createElement(W.Z,{className:"navbar__brand",imageClassName:"navbar__logo",titleClassName:"navbar__title text--truncate"})}function K(){const e=(0,O.e)();return r.createElement("button",{type:"button","aria-label":(0,u.I)({id:"theme.docs.sidebar.closeSidebarButtonAriaLabel",message:"Close navigation bar",description:"The ARIA label for close button of mobile sidebar"}),className:"clean-btn navbar-sidebar__close",onClick:()=>e.toggle()},r.createElement(_,{color:"var(--ifm-color-emphasis-600)"}))}function X(){return r.createElement("div",{className:"navbar-sidebar__brand"},r.createElement(Y,null),r.createElement(V,{className:"margin-right--md"}),r.createElement(K,null))}var q=n(9960),Q=n(4996),J=n(3919),ee=n(8022),te=n(9471);function ne(e){let{activeBasePath:t,activeBaseRegex:n,to:a,href:o,label:i,html:s,isDropdownLink:u,prependBaseUrlToHref:c,...d}=e;const f=(0,Q.Z)(a),p=(0,Q.Z)(t),m=(0,Q.Z)(o,{forcePrependBaseUrl:!0}),h=i&&o&&!(0,J.Z)(o),g=s?{dangerouslySetInnerHTML:{__html:s}}:{children:r.createElement(r.Fragment,null,i,h&&r.createElement(te.Z,u&&{width:12,height:12}))};return o?r.createElement(q.Z,(0,l.Z)({href:c?m:o},d,g)):r.createElement(q.Z,(0,l.Z)({to:f,isNavLink:!0},(t||n)&&{isActive:(e,t)=>n?(0,ee.F)(n,t.pathname):t.pathname.startsWith(p)},d,g))}function re(e){let{className:t,isDropdownItem:n=!1,...o}=e;const i=r.createElement(ne,(0,l.Z)({className:(0,a.Z)(n?"dropdown__link":"navbar__item navbar__link",t),isDropdownLink:n},o));return n?r.createElement("li",null,i):i}function ae(e){let{className:t,isDropdownItem:n,...o}=e;return r.createElement("li",{className:"menu__list-item"},r.createElement(ne,(0,l.Z)({className:(0,a.Z)("menu__link",t)},o)))}function oe(e){let{mobile:t=!1,position:n,...a}=e;const o=t?ae:re;return r.createElement(o,(0,l.Z)({},a,{activeClassName:a.activeClassName??(t?"menu__link--active":"navbar__link--active")}))}var ie=n(6043),le=n(8596),se=n(2263);function ue(e,t){return e.some((e=>function(e,t){return!!(0,le.Mg)(e.to,t)||!!(0,ee.F)(e.activeBaseRegex,t)||!(!e.activeBasePath||!t.startsWith(e.activeBasePath))}(e,t)))}function ce(e){let{items:t,position:n,className:o,onClick:i,...s}=e;const u=(0,r.useRef)(null),[c,d]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{const e=e=>{u.current&&!u.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("focusin",e),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("focusin",e)}}),[u]),r.createElement("div",{ref:u,className:(0,a.Z)("navbar__item","dropdown","dropdown--hoverable",{"dropdown--right":"right"===n,"dropdown--show":c})},r.createElement(ne,(0,l.Z)({"aria-haspopup":"true","aria-expanded":c,role:"button",href:s.to?void 0:"#",className:(0,a.Z)("navbar__link",o)},s,{onClick:s.to?void 0:e=>e.preventDefault(),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),d(!c))}}),s.children??s.label),r.createElement("ul",{className:"dropdown__menu"},t.map(((e,t)=>r.createElement(je,(0,l.Z)({isDropdownItem:!0,activeClassName:"dropdown__link--active"},e,{key:t}))))))}function de(e){let{items:t,className:n,position:o,onClick:i,...u}=e;const c=function(){const{siteConfig:{baseUrl:e}}=(0,se.Z)(),{pathname:t}=(0,s.TH)();return t.replace(e,"/")}(),d=ue(t,c),{collapsed:f,toggleCollapsed:p,setCollapsed:m}=(0,ie.u)({initialState:()=>!d});return(0,r.useEffect)((()=>{d&&m(!d)}),[c,d,m]),r.createElement("li",{className:(0,a.Z)("menu__list-item",{"menu__list-item--collapsed":f})},r.createElement(ne,(0,l.Z)({role:"button",className:(0,a.Z)("menu__link menu__link--sublist menu__link--sublist-caret",n)},u,{onClick:e=>{e.preventDefault(),p()}}),u.children??u.label),r.createElement(ie.z,{lazy:!0,as:"ul",className:"menu__list",collapsed:f},t.map(((e,t)=>r.createElement(je,(0,l.Z)({mobile:!0,isDropdownItem:!0,onClick:i,activeClassName:"menu__link--active"},e,{key:t}))))))}function fe(e){let{mobile:t=!1,...n}=e;const a=t?de:ce;return r.createElement(a,n)}var pe=n(4711);function me(e){let{width:t=20,height:n=20,...a}=e;return r.createElement("svg",(0,l.Z)({viewBox:"0 0 24 24",width:t,height:n,"aria-hidden":!0},a),r.createElement("path",{fill:"currentColor",d:"M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"}))}const he="iconLanguage_nlXk";function ge(){return r.createElement("svg",{width:"15",height:"15",className:"DocSearch-Control-Key-Icon"},r.createElement("path",{d:"M4.505 4.496h2M5.505 5.496v5M8.216 4.496l.055 5.993M10 7.5c.333.333.5.667.5 1v2M12.326 4.5v5.996M8.384 4.496c1.674 0 2.116 0 2.116 1.5s-.442 1.5-2.116 1.5M3.205 9.303c-.09.448-.277 1.21-1.241 1.203C1 10.5.5 9.513.5 8V7c0-1.57.5-2.5 1.464-2.494.964.006 1.134.598 1.24 1.342M12.553 10.5h1.953",strokeWidth:"1.2",stroke:"currentColor",fill:"none",strokeLinecap:"square"}))}var be=n(830),ve=["translations"];function ye(){return ye=Object.assign||function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=new Array(t);n=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var we="Ctrl";var Te=r.forwardRef((function(e,t){var n=e.translations,a=void 0===n?{}:n,o=_e(e,ve),i=a.buttonText,l=void 0===i?"Search":i,s=a.buttonAriaLabel,u=void 0===s?"Search":s,c=Ee((0,r.useState)(null),2),d=c[0],f=c[1];return(0,r.useEffect)((function(){"undefined"!=typeof navigator&&(/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)?f("\u2318"):f(we))}),[]),r.createElement("button",ye({type:"button",className:"DocSearch DocSearch-Button","aria-label":u},o,{ref:t}),r.createElement("span",{className:"DocSearch-Button-Container"},r.createElement(be.W,null),r.createElement("span",{className:"DocSearch-Button-Placeholder"},l)),r.createElement("span",{className:"DocSearch-Button-Keys"},null!==d&&r.createElement(r.Fragment,null,r.createElement("kbd",{className:"DocSearch-Button-Key"},d===we?r.createElement(ge,null):d),r.createElement("kbd",{className:"DocSearch-Button-Key"},"K"))))})),ke=n(5742),Ce=n(6177),Ae=n(239),Ie=n(3320);var Oe=n(3935);const Re={button:{buttonText:(0,u.I)({id:"theme.SearchBar.label",message:"Search",description:"The ARIA label and placeholder for search button"}),buttonAriaLabel:(0,u.I)({id:"theme.SearchBar.label",message:"Search",description:"The ARIA label and placeholder for search button"})},modal:{searchBox:{resetButtonTitle:(0,u.I)({id:"theme.SearchModal.searchBox.resetButtonTitle",message:"Clear the query",description:"The label and ARIA label for search box reset button"}),resetButtonAriaLabel:(0,u.I)({id:"theme.SearchModal.searchBox.resetButtonTitle",message:"Clear the query",description:"The label and ARIA label for search box reset button"}),cancelButtonText:(0,u.I)({id:"theme.SearchModal.searchBox.cancelButtonText",message:"Cancel",description:"The label and ARIA label for search box cancel button"}),cancelButtonAriaLabel:(0,u.I)({id:"theme.SearchModal.searchBox.cancelButtonText",message:"Cancel",description:"The label and ARIA label for search box cancel button"})},startScreen:{recentSearchesTitle:(0,u.I)({id:"theme.SearchModal.startScreen.recentSearchesTitle",message:"Recent",description:"The title for recent searches"}),noRecentSearchesText:(0,u.I)({id:"theme.SearchModal.startScreen.noRecentSearchesText",message:"No recent searches",description:"The text when no recent searches"}),saveRecentSearchButtonTitle:(0,u.I)({id:"theme.SearchModal.startScreen.saveRecentSearchButtonTitle",message:"Save this search",description:"The label for save recent search button"}),removeRecentSearchButtonTitle:(0,u.I)({id:"theme.SearchModal.startScreen.removeRecentSearchButtonTitle",message:"Remove this search from history",description:"The label for remove recent search button"}),favoriteSearchesTitle:(0,u.I)({id:"theme.SearchModal.startScreen.favoriteSearchesTitle",message:"Favorite",description:"The title for favorite searches"}),removeFavoriteSearchButtonTitle:(0,u.I)({id:"theme.SearchModal.startScreen.removeFavoriteSearchButtonTitle",message:"Remove this search from favorites",description:"The label for remove favorite search button"})},errorScreen:{titleText:(0,u.I)({id:"theme.SearchModal.errorScreen.titleText",message:"Unable to fetch results",description:"The title for error screen of search modal"}),helpText:(0,u.I)({id:"theme.SearchModal.errorScreen.helpText",message:"You might want to check your network connection.",description:"The help text for error screen of search modal"})},footer:{selectText:(0,u.I)({id:"theme.SearchModal.footer.selectText",message:"to select",description:"The explanatory text of the action for the enter key"}),selectKeyAriaLabel:(0,u.I)({id:"theme.SearchModal.footer.selectKeyAriaLabel",message:"Enter key",description:"The ARIA label for the Enter key button that makes the selection"}),navigateText:(0,u.I)({id:"theme.SearchModal.footer.navigateText",message:"to navigate",description:"The explanatory text of the action for the Arrow up and Arrow down key"}),navigateUpKeyAriaLabel:(0,u.I)({id:"theme.SearchModal.footer.navigateUpKeyAriaLabel",message:"Arrow up",description:"The ARIA label for the Arrow up key button that makes the navigation"}),navigateDownKeyAriaLabel:(0,u.I)({id:"theme.SearchModal.footer.navigateDownKeyAriaLabel",message:"Arrow down",description:"The ARIA label for the Arrow down key button that makes the navigation"}),closeText:(0,u.I)({id:"theme.SearchModal.footer.closeText",message:"to close",description:"The explanatory text of the action for Escape key"}),closeKeyAriaLabel:(0,u.I)({id:"theme.SearchModal.footer.closeKeyAriaLabel",message:"Escape key",description:"The ARIA label for the Escape key button that close the modal"}),searchByText:(0,u.I)({id:"theme.SearchModal.footer.searchByText",message:"Search by",description:"The text explain that the search is making by Algolia"})},noResultsScreen:{noResultsText:(0,u.I)({id:"theme.SearchModal.noResultsScreen.noResultsText",message:"No results for",description:"The text explains that there are no results for the following search"}),suggestedQueryText:(0,u.I)({id:"theme.SearchModal.noResultsScreen.suggestedQueryText",message:"Try searching for",description:"The text for the suggested query when no results are found for the following search"}),reportMissingResultsText:(0,u.I)({id:"theme.SearchModal.noResultsScreen.reportMissingResultsText",message:"Believe this query should return results?",description:"The text for the question where the user thinks there are missing results"}),reportMissingResultsLinkText:(0,u.I)({id:"theme.SearchModal.noResultsScreen.reportMissingResultsLinkText",message:"Let us know.",description:"The text for the link to report missing results"})}},placeholder:(0,u.I)({id:"theme.SearchModal.placeholder",message:"Search docs",description:"The placeholder of the input of the DocSearch pop-up modal"})};let Ne=null;function Le(e){let{hit:t,children:n}=e;return r.createElement(q.Z,{to:t.url},n)}function Pe(e){let{state:t,onClose:n}=e;const a=(0,Ce.M)();return r.createElement(q.Z,{to:a(t.query),onClick:n},r.createElement(u.Z,{id:"theme.SearchBar.seeAll",values:{count:t.context.nbHits}},"See all {count} results"))}function xe(e){let{contextualSearch:t,externalUrlRegex:a,...o}=e;const{siteMetadata:i}=(0,se.Z)(),u=(0,Ae.l)(),c=function(){const{locale:e,tags:t}=(0,Ie._q)();return[`language:${e}`,t.map((e=>`docusaurus_tag:${e}`))]}(),d=o.searchParameters?.facetFilters??[],f=t?function(e,t){const n=e=>"string"==typeof e?[e]:e;return[...n(e),...n(t)]}(c,d):d,p={...o.searchParameters,facetFilters:f},m=(0,s.k6)(),h=(0,r.useRef)(null),g=(0,r.useRef)(null),[b,v]=(0,r.useState)(!1),[y,E]=(0,r.useState)(void 0),S=(0,r.useCallback)((()=>Ne?Promise.resolve():Promise.all([n.e(426).then(n.bind(n,1426)),Promise.all([n.e(532),n.e(945)]).then(n.bind(n,6945)),Promise.all([n.e(532),n.e(894)]).then(n.bind(n,8894))]).then((e=>{let[{DocSearchModal:t}]=e;Ne=t}))),[]),_=(0,r.useCallback)((()=>{S().then((()=>{h.current=document.createElement("div"),document.body.insertBefore(h.current,document.body.firstChild),v(!0)}))}),[S,v]),w=(0,r.useCallback)((()=>{v(!1),h.current?.remove()}),[v]),T=(0,r.useCallback)((e=>{S().then((()=>{v(!0),E(e.key)}))}),[S,v,E]),k=(0,r.useRef)({navigate(e){let{itemUrl:t}=e;(0,ee.F)(a,t)?window.location.href=t:m.push(t)}}).current,C=(0,r.useRef)((e=>o.transformItems?o.transformItems(e):e.map((e=>({...e,url:u(e.url)}))))).current,A=(0,r.useMemo)((()=>e=>r.createElement(Pe,(0,l.Z)({},e,{onClose:w}))),[w]),I=(0,r.useCallback)((e=>(e.addAlgoliaAgent("docusaurus",i.docusaurusVersion),e)),[i.docusaurusVersion]);return function(e){var t=e.isOpen,n=e.onOpen,a=e.onClose,o=e.onInput,i=e.searchButtonRef;r.useEffect((function(){function e(e){var r;(27===e.keyCode&&t||"k"===(null===(r=e.key)||void 0===r?void 0:r.toLowerCase())&&(e.metaKey||e.ctrlKey)||!function(e){var t=e.target,n=t.tagName;return t.isContentEditable||"INPUT"===n||"SELECT"===n||"TEXTAREA"===n}(e)&&"/"===e.key&&!t)&&(e.preventDefault(),t?a():document.body.classList.contains("DocSearch--active")||document.body.classList.contains("DocSearch--active")||n()),i&&i.current===document.activeElement&&o&&/[a-zA-Z0-9]/.test(String.fromCharCode(e.keyCode))&&o(e)}return window.addEventListener("keydown",e),function(){window.removeEventListener("keydown",e)}}),[t,n,a,o,i])}({isOpen:b,onOpen:_,onClose:w,onInput:T,searchButtonRef:g}),r.createElement(r.Fragment,null,r.createElement(ke.Z,null,r.createElement("link",{rel:"preconnect",href:`https://${o.appId}-dsn.algolia.net`,crossOrigin:"anonymous"})),r.createElement(Te,{onTouchStart:S,onFocus:S,onMouseOver:S,onClick:_,ref:g,translations:Re.button}),b&&Ne&&h.current&&(0,Oe.createPortal)(r.createElement(Ne,(0,l.Z)({onClose:w,initialScrollY:window.scrollY,initialQuery:y,navigator:k,transformItems:C,hitComponent:Le,transformSearchClient:I},o.searchPagePath&&{resultsFooterComponent:A},o,{searchParameters:p,placeholder:Re.placeholder,translations:Re.modal})),h.current))}function De(){const{siteConfig:e}=(0,se.Z)();return r.createElement(xe,e.themeConfig.algolia)}const Me={searchBox:"searchBox_ZlJk"};function Ue(e){let{children:t,className:n}=e;return r.createElement("div",{className:(0,a.Z)(n,Me.searchBox)},t)}var Fe=n(143),Be=n(3438);var $e=n(373);const ze=e=>e.docs.find((t=>t.id===e.mainDocId));const He={default:oe,localeDropdown:function(e){let{mobile:t,dropdownItemsBefore:n,dropdownItemsAfter:a,...o}=e;const{i18n:{currentLocale:i,locales:c,localeConfigs:d}}=(0,se.Z)(),f=(0,pe.l)(),{search:p,hash:m}=(0,s.TH)(),h=[...n,...c.map((e=>{const n=`${`pathname://${f.createUrl({locale:e,fullyQualified:!1})}`}${p}${m}`;return{label:d[e].label,lang:d[e].htmlLang,to:n,target:"_self",autoAddBaseUrl:!1,className:e===i?t?"menu__link--active":"dropdown__link--active":""}})),...a],g=t?(0,u.I)({message:"Languages",id:"theme.navbar.mobileLanguageDropdown.label",description:"The label for the mobile language switcher dropdown"}):d[i].label;return r.createElement(fe,(0,l.Z)({},o,{mobile:t,label:r.createElement(r.Fragment,null,r.createElement(me,{className:he}),g),items:h}))},search:function(e){let{mobile:t,className:n}=e;return t?null:r.createElement(Ue,{className:n},r.createElement(De,null))},dropdown:fe,html:function(e){let{value:t,className:n,mobile:o=!1,isDropdownItem:i=!1}=e;const l=i?"li":"div";return r.createElement(l,{className:(0,a.Z)({navbar__item:!o&&!i,"menu__list-item":o},n),dangerouslySetInnerHTML:{__html:t}})},doc:function(e){let{docId:t,label:n,docsPluginId:a,...o}=e;const{activeDoc:i}=(0,Fe.Iw)(a),s=(0,Be.vY)(t,a);return null===s?null:r.createElement(oe,(0,l.Z)({exact:!0},o,{isActive:()=>i?.path===s.path||!!i?.sidebar&&i.sidebar===s.sidebar,label:n??s.id,to:s.path}))},docSidebar:function(e){let{sidebarId:t,label:n,docsPluginId:a,...o}=e;const{activeDoc:i}=(0,Fe.Iw)(a),s=(0,Be.oz)(t,a).link;if(!s)throw new Error(`DocSidebarNavbarItem: Sidebar with ID "${t}" doesn't have anything to be linked to.`);return r.createElement(oe,(0,l.Z)({exact:!0},o,{isActive:()=>i?.sidebar===t,label:n??s.label,to:s.path}))},docsVersion:function(e){let{label:t,to:n,docsPluginId:a,...o}=e;const i=(0,Be.lO)(a)[0],s=t??i.label,u=n??(e=>e.docs.find((t=>t.id===e.mainDocId)))(i).path;return r.createElement(oe,(0,l.Z)({},o,{label:s,to:u}))},docsVersionDropdown:function(e){let{mobile:t,docsPluginId:n,dropdownActiveClassDisabled:a,dropdownItemsBefore:o,dropdownItemsAfter:i,...c}=e;const{search:d,hash:f}=(0,s.TH)(),p=(0,Fe.Iw)(n),m=(0,Fe.gB)(n),{savePreferredVersionName:h}=(0,$e.J)(n),g=[...o,...m.map((e=>{const t=p.alternateDocVersions[e.name]??ze(e);return{label:e.label,to:`${t.path}${d}${f}`,isActive:()=>e===p.activeVersion,onClick:()=>h(e.name)}})),...i],b=(0,Be.lO)(n)[0],v=t&&g.length>1?(0,u.I)({id:"theme.navbar.mobileVersionsDropdown.label",message:"Versions",description:"The label for the navbar versions dropdown on mobile view"}):b.label,y=t&&g.length>1?void 0:ze(b).path;return g.length<=1?r.createElement(oe,(0,l.Z)({},c,{mobile:t,label:v,to:y,isActive:a?()=>!1:void 0})):r.createElement(fe,(0,l.Z)({},c,{mobile:t,label:v,to:y,items:g,isActive:a?()=>!1:void 0}))}};function je(e){let{type:t,...n}=e;const a=function(e,t){return e&&"default"!==e?e:"items"in t?"dropdown":"default"}(t,n),o=He[a];if(!o)throw new Error(`No NavbarItem component found for type "${t}".`);return r.createElement(o,n)}function Ge(){const e=(0,O.e)(),t=(0,E.L)().navbar.items;return r.createElement("ul",{className:"menu__list"},t.map(((t,n)=>r.createElement(je,(0,l.Z)({mobile:!0},t,{onClick:()=>e.toggle(),key:n})))))}function Ze(e){return r.createElement("button",(0,l.Z)({},e,{type:"button",className:"clean-btn navbar-sidebar__back"}),r.createElement(u.Z,{id:"theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel",description:"The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)"},"\u2190 Back to main menu"))}function Ve(){const e=0===(0,E.L)().navbar.items.length,t=M();return r.createElement(r.Fragment,null,!e&&r.createElement(Ze,{onClick:()=>t.hide()}),t.content)}function We(){const e=(0,O.e)();var t;return void 0===(t=e.shown)&&(t=!0),(0,r.useEffect)((()=>(document.body.style.overflow=t?"hidden":"visible",()=>{document.body.style.overflow="visible"})),[t]),e.shouldRender?r.createElement(U,{header:r.createElement(X,null),primaryMenu:r.createElement(Ge,null),secondaryMenu:r.createElement(Ve,null)}):null}const Ye={navbarHideable:"navbarHideable_m1mJ",navbarHidden:"navbarHidden_jGov"};function Ke(e){return r.createElement("div",(0,l.Z)({role:"presentation"},e,{className:(0,a.Z)("navbar-sidebar__backdrop",e.className)}))}function Xe(e){let{children:t}=e;const{navbar:{hideOnScroll:n,style:o}}=(0,E.L)(),i=(0,O.e)(),{navbarRef:l,isNavbarVisible:s}=function(e){const[t,n]=(0,r.useState)(e),a=(0,r.useRef)(!1),o=(0,r.useRef)(0),i=(0,r.useCallback)((e=>{null!==e&&(o.current=e.getBoundingClientRect().height)}),[]);return(0,R.RF)(((t,r)=>{let{scrollY:i}=t;if(!e)return;if(i=l?n(!1):i+u{if(!e)return;const r=t.location.hash;if(r?document.getElementById(r.substring(1)):void 0)return a.current=!0,void n(!1);n(!0)})),{navbarRef:i,isNavbarVisible:t}}(n);return r.createElement("nav",{ref:l,"aria-label":(0,u.I)({id:"theme.NavBar.navAriaLabel",message:"Main",description:"The ARIA label for the main navigation"}),className:(0,a.Z)("navbar","navbar--fixed-top",n&&[Ye.navbarHideable,!s&&Ye.navbarHidden],{"navbar--dark":"dark"===o,"navbar--primary":"primary"===o,"navbar-sidebar--show":i.shown})},t,r.createElement(Ke,{onClick:i.toggle}),r.createElement(We,null))}var qe=n(8780);const Qe={errorBoundaryError:"errorBoundaryError_a6uf"};function Je(e){return r.createElement("button",(0,l.Z)({type:"button"},e),r.createElement(u.Z,{id:"theme.ErrorPageContent.tryAgain",description:"The label of the button to try again rendering when the React error boundary captures an error"},"Try again"))}function et(e){let{error:t}=e;const n=(0,qe.getErrorCausalChain)(t).map((e=>e.message)).join("\n\nCause:\n");return r.createElement("p",{className:Qe.errorBoundaryError},n)}class tt extends r.Component{componentDidCatch(e,t){throw this.props.onError(e,t)}render(){return this.props.children}}const nt="right";function rt(e){let{width:t=30,height:n=30,className:a,...o}=e;return r.createElement("svg",(0,l.Z)({className:a,width:t,height:n,viewBox:"0 0 30 30","aria-hidden":"true"},o),r.createElement("path",{stroke:"currentColor",strokeLinecap:"round",strokeMiterlimit:"10",strokeWidth:"2",d:"M4 7h22M4 15h22M4 23h22"}))}function at(){const{toggle:e,shown:t}=(0,O.e)();return r.createElement("button",{onClick:e,"aria-label":(0,u.I)({id:"theme.docs.sidebar.toggleSidebarButtonAriaLabel",message:"Toggle navigation bar",description:"The ARIA label for hamburger menu button of mobile navigation"}),"aria-expanded":t,className:"navbar__toggle clean-btn",type:"button"},r.createElement(rt,null))}const ot={colorModeToggle:"colorModeToggle_DEke"};function it(e){let{items:t}=e;return r.createElement(r.Fragment,null,t.map(((e,t)=>r.createElement(tt,{key:t,onError:t=>new Error(`A theme navbar item failed to render.\nPlease double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config:\n${JSON.stringify(e,null,2)}`,{cause:t})},r.createElement(je,e)))))}function lt(e){let{left:t,right:n}=e;return r.createElement("div",{className:"navbar__inner"},r.createElement("div",{className:"navbar__items"},t),r.createElement("div",{className:"navbar__items navbar__items--right"},n))}function st(){const e=(0,O.e)(),t=(0,E.L)().navbar.items,[n,a]=function(e){function t(e){return"left"===(e.position??nt)}return[e.filter(t),e.filter((e=>!t(e)))]}(t),o=t.find((e=>"search"===e.type));return r.createElement(lt,{left:r.createElement(r.Fragment,null,!e.disabled&&r.createElement(at,null),r.createElement(Y,null),r.createElement(it,{items:n})),right:r.createElement(r.Fragment,null,r.createElement(it,{items:a}),r.createElement(V,{className:ot.colorModeToggle}),!o&&r.createElement(Ue,null,r.createElement(De,null)))})}function ut(){return r.createElement(Xe,null,r.createElement(st,null))}function ct(e){let{item:t}=e;const{to:n,href:a,label:o,prependBaseUrlToHref:i,...s}=t,u=(0,Q.Z)(n),c=(0,Q.Z)(a,{forcePrependBaseUrl:!0});return r.createElement(q.Z,(0,l.Z)({className:"footer__link-item"},a?{href:i?c:a}:{to:u},s),o,a&&!(0,J.Z)(a)&&r.createElement(te.Z,null))}function dt(e){let{item:t}=e;return t.html?r.createElement("li",{className:"footer__item",dangerouslySetInnerHTML:{__html:t.html}}):r.createElement("li",{key:t.href??t.to,className:"footer__item"},r.createElement(ct,{item:t}))}function ft(e){let{column:t}=e;return r.createElement("div",{className:"col footer__col"},r.createElement("div",{className:"footer__title"},t.title),r.createElement("ul",{className:"footer__items clean-list"},t.items.map(((e,t)=>r.createElement(dt,{key:t,item:e})))))}function pt(e){let{columns:t}=e;return r.createElement("div",{className:"row footer__links"},t.map(((e,t)=>r.createElement(ft,{key:t,column:e}))))}function mt(){return r.createElement("span",{className:"footer__link-separator"},"\xb7")}function ht(e){let{item:t}=e;return t.html?r.createElement("span",{className:"footer__link-item",dangerouslySetInnerHTML:{__html:t.html}}):r.createElement(ct,{item:t})}function gt(e){let{links:t}=e;return r.createElement("div",{className:"footer__links text--center"},r.createElement("div",{className:"footer__links"},t.map(((e,n)=>r.createElement(r.Fragment,{key:n},r.createElement(ht,{item:e}),t.length!==n+1&&r.createElement(mt,null))))))}function bt(e){let{links:t}=e;return function(e){return"title"in e[0]}(t)?r.createElement(pt,{columns:t}):r.createElement(gt,{links:t})}var vt=n(941);const yt={footerLogoLink:"footerLogoLink_BH7S"};function Et(e){let{logo:t}=e;const{withBaseUrl:n}=(0,Q.C)(),o={light:n(t.src),dark:n(t.srcDark??t.src)};return r.createElement(vt.Z,{className:(0,a.Z)("footer__logo",t.className),alt:t.alt,sources:o,width:t.width,height:t.height,style:t.style})}function St(e){let{logo:t}=e;return t.href?r.createElement(q.Z,{href:t.href,className:yt.footerLogoLink,target:t.target},r.createElement(Et,{logo:t})):r.createElement(Et,{logo:t})}function _t(e){let{copyright:t}=e;return r.createElement("div",{className:"footer__copyright",dangerouslySetInnerHTML:{__html:t}})}function wt(e){let{style:t,links:n,logo:o,copyright:i}=e;return r.createElement("footer",{className:(0,a.Z)("footer",{"footer--dark":"dark"===t})},r.createElement("div",{className:"container container-fluid"},n,(o||i)&&r.createElement("div",{className:"footer__bottom text--center"},o&&r.createElement("div",{className:"margin-bottom--sm"},o),i)))}function Tt(){const{footer:e}=(0,E.L)();if(!e)return null;const{copyright:t,links:n,logo:a,style:o}=e;return r.createElement(wt,{style:o,links:n&&n.length>0&&r.createElement(bt,{links:n}),logo:a&&r.createElement(St,{logo:a}),copyright:t&&r.createElement(_t,{copyright:t})})}const kt=r.memo(Tt),Ct=(0,N.Qc)([F.S,S.pl,R.OC,$e.L5,i.VC,function(e){let{children:t}=e;return r.createElement(L.n2,null,r.createElement(O.M,null,r.createElement(x,null,t)))}]);function At(e){let{children:t}=e;return r.createElement(Ct,null,t)}function It(e){let{error:t,tryAgain:n}=e;return r.createElement("main",{className:"container margin-vert--xl"},r.createElement("div",{className:"row"},r.createElement("div",{className:"col col--6 col--offset-3"},r.createElement("h1",{className:"hero__title"},r.createElement(u.Z,{id:"theme.ErrorPageContent.title",description:"The title of the fallback page when the page crashed"},"This page crashed.")),r.createElement("div",{className:"margin-vert--lg"},r.createElement(Je,{onClick:n,className:"button button--primary shadow--lw"})),r.createElement("hr",null),r.createElement("div",{className:"margin-vert--md"},r.createElement(et,{error:t})))))}const Ot={mainWrapper:"mainWrapper_z2l0"};function Rt(e){const{children:t,noFooter:n,wrapperClassName:l,title:s,description:u}=e;return(0,b.t)(),r.createElement(At,null,r.createElement(i.d,{title:s,description:u}),r.createElement(y,null),r.createElement(I,null),r.createElement(ut,null),r.createElement("div",{id:d,className:(0,a.Z)(g.k.wrapper.main,Ot.mainWrapper,l)},r.createElement(o.Z,{fallback:e=>r.createElement(It,e)},t)),!n&&r.createElement(kt,null))}},1327:(e,t,n)=>{"use strict";n.d(t,{Z:()=>d});var r=n(7462),a=n(7294),o=n(9960),i=n(4996),l=n(2263),s=n(6668),u=n(941);function c(e){let{logo:t,alt:n,imageClassName:r}=e;const o={light:(0,i.Z)(t.src),dark:(0,i.Z)(t.srcDark||t.src)},l=a.createElement(u.Z,{className:t.className,sources:o,height:t.height,width:t.width,alt:n,style:t.style});return r?a.createElement("div",{className:r},l):l}function d(e){const{siteConfig:{title:t}}=(0,l.Z)(),{navbar:{title:n,logo:u}}=(0,s.L)(),{imageClassName:d,titleClassName:f,...p}=e,m=(0,i.Z)(u?.href||"/"),h=n?"":t,g=u?.alt??h;return a.createElement(o.Z,(0,r.Z)({to:m},p,u?.target&&{target:u.target}),u&&a.createElement(c,{logo:u,alt:g,imageClassName:d}),null!=n&&a.createElement("b",{className:f},n))}},197:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(7294),a=n(5742);function o(e){let{locale:t,version:n,tag:o}=e;const i=t;return r.createElement(a.Z,null,t&&r.createElement("meta",{name:"docusaurus_locale",content:t}),n&&r.createElement("meta",{name:"docusaurus_version",content:n}),o&&r.createElement("meta",{name:"docusaurus_tag",content:o}),i&&r.createElement("meta",{name:"docsearch:language",content:i}),n&&r.createElement("meta",{name:"docsearch:version",content:n}),o&&r.createElement("meta",{name:"docsearch:docusaurus_tag",content:o}))}},941:(e,t,n)=>{"use strict";n.d(t,{Z:()=>u});var r=n(7462),a=n(7294),o=n(6010),i=n(2389),l=n(2949);const s={themedImage:"themedImage_ToTc","themedImage--light":"themedImage--light_HNdA","themedImage--dark":"themedImage--dark_i4oU"};function u(e){const t=(0,i.Z)(),{colorMode:n}=(0,l.I)(),{sources:u,className:c,alt:d,...f}=e,p=t?"dark"===n?["dark"]:["light"]:["light","dark"];return a.createElement(a.Fragment,null,p.map((e=>a.createElement("img",(0,r.Z)({key:e,src:u[e],alt:d,className:(0,o.Z)(s.themedImage,s[`themedImage--${e}`],c)},f)))))}},6043:(e,t,n)=>{"use strict";n.d(t,{u:()=>s,z:()=>g});var r=n(7462),a=n(7294),o=n(412),i=n(1442);const l="ease-in-out";function s(e){let{initialState:t}=e;const[n,r]=(0,a.useState)(t??!1),o=(0,a.useCallback)((()=>{r((e=>!e))}),[]);return{collapsed:n,setCollapsed:r,toggleCollapsed:o}}const u={display:"none",overflow:"hidden",height:"0px"},c={display:"block",overflow:"visible",height:"auto"};function d(e,t){const n=t?u:c;e.style.display=n.display,e.style.overflow=n.overflow,e.style.height=n.height}function f(e){let{collapsibleRef:t,collapsed:n,animation:r}=e;const o=(0,a.useRef)(!1);(0,a.useEffect)((()=>{const e=t.current;function a(){const t=e.scrollHeight,n=r?.duration??function(e){if((0,i.n)())return 1;const t=e/36;return Math.round(10*(4+15*t**.25+t/5))}(t);return{transition:`height ${n}ms ${r?.easing??l}`,height:`${t}px`}}function s(){const t=a();e.style.transition=t.transition,e.style.height=t.height}if(!o.current)return d(e,n),void(o.current=!0);return e.style.willChange="height",function(){const t=requestAnimationFrame((()=>{n?(s(),requestAnimationFrame((()=>{e.style.height=u.height,e.style.overflow=u.overflow}))):(e.style.display="block",requestAnimationFrame((()=>{s()})))}));return()=>cancelAnimationFrame(t)}()}),[t,n,r])}function p(e){if(!o.Z.canUseDOM)return e?u:c}function m(e){let{as:t="div",collapsed:n,children:r,animation:o,onCollapseTransitionEnd:i,className:l,disableSSRStyle:s}=e;const u=(0,a.useRef)(null);return f({collapsibleRef:u,collapsed:n,animation:o}),a.createElement(t,{ref:u,style:s?void 0:p(n),onTransitionEnd:e=>{"height"===e.propertyName&&(d(u.current,n),i?.(n))},className:l},r)}function h(e){let{collapsed:t,...n}=e;const[o,i]=(0,a.useState)(!t),[l,s]=(0,a.useState)(t);return(0,a.useLayoutEffect)((()=>{t||i(!0)}),[t]),(0,a.useLayoutEffect)((()=>{o&&s(t)}),[o,t]),o?a.createElement(m,(0,r.Z)({},n,{collapsed:l})):null}function g(e){let{lazy:t,...n}=e;const r=t?h:m;return a.createElement(r,n)}},9689:(e,t,n)=>{"use strict";n.d(t,{nT:()=>m,pl:()=>p});var r=n(7294),a=n(2389),o=n(12),i=n(902),l=n(6668);const s=(0,o.WA)("docusaurus.announcement.dismiss"),u=(0,o.WA)("docusaurus.announcement.id"),c=()=>"true"===s.get(),d=e=>s.set(String(e)),f=r.createContext(null);function p(e){let{children:t}=e;const n=function(){const{announcementBar:e}=(0,l.L)(),t=(0,a.Z)(),[n,o]=(0,r.useState)((()=>!!t&&c()));(0,r.useEffect)((()=>{o(c())}),[]);const i=(0,r.useCallback)((()=>{d(!0),o(!0)}),[]);return(0,r.useEffect)((()=>{if(!e)return;const{id:t}=e;let n=u.get();"annoucement-bar"===n&&(n="announcement-bar");const r=t!==n;u.set(t),r&&d(!1),!r&&c()||o(!1)}),[e]),(0,r.useMemo)((()=>({isActive:!!e&&!n,close:i})),[e,n,i])}();return r.createElement(f.Provider,{value:n},t)}function m(){const e=(0,r.useContext)(f);if(!e)throw new i.i6("AnnouncementBarProvider");return e}},2949:(e,t,n)=>{"use strict";n.d(t,{I:()=>g,S:()=>h});var r=n(7294),a=n(412),o=n(902),i=n(12),l=n(6668);const s=r.createContext(void 0),u="theme",c=(0,i.WA)(u),d={light:"light",dark:"dark"},f=e=>e===d.dark?d.dark:d.light,p=e=>a.Z.canUseDOM?f(document.documentElement.getAttribute("data-theme")):f(e),m=e=>{c.set(f(e))};function h(e){let{children:t}=e;const n=function(){const{colorMode:{defaultMode:e,disableSwitch:t,respectPrefersColorScheme:n}}=(0,l.L)(),[a,o]=(0,r.useState)(p(e));(0,r.useEffect)((()=>{t&&c.del()}),[t]);const i=(0,r.useCallback)((function(t,r){void 0===r&&(r={});const{persist:a=!0}=r;t?(o(t),a&&m(t)):(o(n?window.matchMedia("(prefers-color-scheme: dark)").matches?d.dark:d.light:e),c.del())}),[n,e]);(0,r.useEffect)((()=>{document.documentElement.setAttribute("data-theme",f(a))}),[a]),(0,r.useEffect)((()=>{if(t)return;const e=e=>{if(e.key!==u)return;const t=c.get();null!==t&&i(f(t))};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,i]);const s=(0,r.useRef)(!1);return(0,r.useEffect)((()=>{if(t&&!n)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>{window.matchMedia("print").matches||s.current?s.current=window.matchMedia("print").matches:i(null)};return e.addListener(r),()=>e.removeListener(r)}),[i,t,n]),(0,r.useMemo)((()=>({colorMode:a,setColorMode:i,get isDarkTheme(){return a===d.dark},setLightTheme(){i(d.light)},setDarkTheme(){i(d.dark)}})),[a,i])}();return r.createElement(s.Provider,{value:n},t)}function g(){const e=(0,r.useContext)(s);if(null==e)throw new o.i6("ColorModeProvider","Please see https://docusaurus.io/docs/api/themes/configuration#use-color-mode.");return e}},373:(e,t,n)=>{"use strict";n.d(t,{J:()=>v,L5:()=>g,Oh:()=>y});var r=n(7294),a=n(143),o=n(9935),i=n(6668),l=n(3438),s=n(902),u=n(12);const c=e=>`docs-preferred-version-${e}`,d={save:(e,t,n)=>{(0,u.WA)(c(e),{persistence:t}).set(n)},read:(e,t)=>(0,u.WA)(c(e),{persistence:t}).get(),clear:(e,t)=>{(0,u.WA)(c(e),{persistence:t}).del()}},f=e=>Object.fromEntries(e.map((e=>[e,{preferredVersionName:null}])));const p=r.createContext(null);function m(){const e=(0,a._r)(),t=(0,i.L)().docs.versionPersistence,n=(0,r.useMemo)((()=>Object.keys(e)),[e]),[o,l]=(0,r.useState)((()=>f(n)));(0,r.useEffect)((()=>{l(function(e){let{pluginIds:t,versionPersistence:n,allDocsData:r}=e;function a(e){const t=d.read(e,n);return r[e].versions.some((e=>e.name===t))?{preferredVersionName:t}:(d.clear(e,n),{preferredVersionName:null})}return Object.fromEntries(t.map((e=>[e,a(e)])))}({allDocsData:e,versionPersistence:t,pluginIds:n}))}),[e,t,n]);return[o,(0,r.useMemo)((()=>({savePreferredVersion:function(e,n){d.save(e,t,n),l((t=>({...t,[e]:{preferredVersionName:n}})))}})),[t])]}function h(e){let{children:t}=e;const n=m();return r.createElement(p.Provider,{value:n},t)}function g(e){let{children:t}=e;return l.cE?r.createElement(h,null,t):r.createElement(r.Fragment,null,t)}function b(){const e=(0,r.useContext)(p);if(!e)throw new s.i6("DocsPreferredVersionContextProvider");return e}function v(e){void 0===e&&(e=o.m);const t=(0,a.zh)(e),[n,i]=b(),{preferredVersionName:l}=n[e];return{preferredVersion:t.versions.find((e=>e.name===l))??null,savePreferredVersionName:(0,r.useCallback)((t=>{i.savePreferredVersion(e,t)}),[i,e])}}function y(){const e=(0,a._r)(),[t]=b();function n(n){const r=e[n],{preferredVersionName:a}=t[n];return r.versions.find((e=>e.name===a))??null}const r=Object.keys(e);return Object.fromEntries(r.map((e=>[e,n(e)])))}},1116:(e,t,n)=>{"use strict";n.d(t,{V:()=>s,b:()=>l});var r=n(7294),a=n(902);const o=Symbol("EmptyContext"),i=r.createContext(o);function l(e){let{children:t,name:n,items:a}=e;const o=(0,r.useMemo)((()=>n&&a?{name:n,items:a}:null),[n,a]);return r.createElement(i.Provider,{value:o},t)}function s(){const e=(0,r.useContext)(i);if(e===o)throw new a.i6("DocsSidebarProvider");return e}},3163:(e,t,n)=>{"use strict";n.d(t,{M:()=>d,e:()=>f});var r=n(7294),a=n(3102),o=n(7524),i=n(1980),l=n(6668),s=n(902);const u=r.createContext(void 0);function c(){const e=function(){const e=(0,a.HY)(),{items:t}=(0,l.L)().navbar;return 0===t.length&&!e.component}(),t=(0,o.i)(),n=!e&&"mobile"===t,[s,u]=(0,r.useState)(!1);(0,i.Rb)((()=>{if(s)return u(!1),!1}));const c=(0,r.useCallback)((()=>{u((e=>!e))}),[]);return(0,r.useEffect)((()=>{"desktop"===t&&u(!1)}),[t]),(0,r.useMemo)((()=>({disabled:e,shouldRender:n,toggle:c,shown:s})),[e,n,c,s])}function d(e){let{children:t}=e;const n=c();return r.createElement(u.Provider,{value:n},t)}function f(){const e=r.useContext(u);if(void 0===e)throw new s.i6("NavbarMobileSidebarProvider");return e}},3102:(e,t,n)=>{"use strict";n.d(t,{HY:()=>l,Zo:()=>s,n2:()=>i});var r=n(7294),a=n(902);const o=r.createContext(null);function i(e){let{children:t}=e;const n=(0,r.useState)({component:null,props:null});return r.createElement(o.Provider,{value:n},t)}function l(){const e=(0,r.useContext)(o);if(!e)throw new a.i6("NavbarSecondaryMenuContentProvider");return e[0]}function s(e){let{component:t,props:n}=e;const i=(0,r.useContext)(o);if(!i)throw new a.i6("NavbarSecondaryMenuContentProvider");const[,l]=i,s=(0,a.Ql)(n);return(0,r.useEffect)((()=>{l({component:t,props:s})}),[l,t,s]),(0,r.useEffect)((()=>()=>l({component:null,props:null})),[l]),null}},9727:(e,t,n)=>{"use strict";n.d(t,{h:()=>a,t:()=>o});var r=n(7294);const a="navigation-with-keyboard";function o(){(0,r.useEffect)((()=>{function e(e){"keydown"===e.type&&"Tab"===e.key&&document.body.classList.add(a),"mousedown"===e.type&&document.body.classList.remove(a)}return document.addEventListener("keydown",e),document.addEventListener("mousedown",e),()=>{document.body.classList.remove(a),document.removeEventListener("keydown",e),document.removeEventListener("mousedown",e)}}),[])}},6177:(e,t,n)=>{"use strict";n.d(t,{K:()=>l,M:()=>s});var r=n(7294),a=n(2263),o=n(1980);const i="q";function l(){return(0,o.Nc)(i)}function s(){const{siteConfig:{baseUrl:e,themeConfig:t}}=(0,a.Z)(),{algolia:{searchPagePath:n}}=t;return(0,r.useCallback)((t=>`${e}${n}?${i}=${encodeURIComponent(t)}`),[e,n])}},7524:(e,t,n)=>{"use strict";n.d(t,{i:()=>u});var r=n(7294),a=n(412);const o={desktop:"desktop",mobile:"mobile",ssr:"ssr"},i=996;function l(){return a.Z.canUseDOM?window.innerWidth>i?o.desktop:o.mobile:o.ssr}const s=!1;function u(){const[e,t]=(0,r.useState)((()=>s?"ssr":l()));return(0,r.useEffect)((()=>{function e(){t(l())}const n=s?window.setTimeout(e,1e3):void 0;return window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e),clearTimeout(n)}}),[]),e}},5281:(e,t,n)=>{"use strict";n.d(t,{k:()=>r});const r={page:{blogListPage:"blog-list-page",blogPostPage:"blog-post-page",blogTagsListPage:"blog-tags-list-page",blogTagPostListPage:"blog-tags-post-list-page",docsDocPage:"docs-doc-page",docsTagsListPage:"docs-tags-list-page",docsTagDocListPage:"docs-tags-doc-list-page",mdxPage:"mdx-page"},wrapper:{main:"main-wrapper",blogPages:"blog-wrapper",docsPages:"docs-wrapper",mdxPages:"mdx-wrapper"},common:{editThisPage:"theme-edit-this-page",lastUpdated:"theme-last-updated",backToTopButton:"theme-back-to-top-button",codeBlock:"theme-code-block",admonition:"theme-admonition",admonitionType:e=>`theme-admonition-${e}`},layout:{},docs:{docVersionBanner:"theme-doc-version-banner",docVersionBadge:"theme-doc-version-badge",docBreadcrumbs:"theme-doc-breadcrumbs",docMarkdown:"theme-doc-markdown",docTocMobile:"theme-doc-toc-mobile",docTocDesktop:"theme-doc-toc-desktop",docFooter:"theme-doc-footer",docFooterTagsRow:"theme-doc-footer-tags-row",docFooterEditMetaRow:"theme-doc-footer-edit-meta-row",docSidebarContainer:"theme-doc-sidebar-container",docSidebarMenu:"theme-doc-sidebar-menu",docSidebarItemCategory:"theme-doc-sidebar-item-category",docSidebarItemLink:"theme-doc-sidebar-item-link",docSidebarItemCategoryLevel:e=>`theme-doc-sidebar-item-category-level-${e}`,docSidebarItemLinkLevel:e=>`theme-doc-sidebar-item-link-level-${e}`},blog:{}}},1442:(e,t,n)=>{"use strict";function r(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}n.d(t,{n:()=>r})},3438:(e,t,n)=>{"use strict";n.d(t,{Wl:()=>f,_F:()=>h,cE:()=>d,hI:()=>S,lO:()=>v,oz:()=>y,s1:()=>b,vY:()=>E});var r=n(7294),a=n(6550),o=n(8790),i=n(143),l=n(373),s=n(1116),u=n(7392),c=n(8596);const d=!!i._r;function f(e){if(e.href)return e.href;for(const t of e.items){if("link"===t.type)return t.href;if("category"===t.type){const e=f(t);if(e)return e}}}const p=(e,t)=>void 0!==e&&(0,c.Mg)(e,t),m=(e,t)=>e.some((e=>h(e,t)));function h(e,t){return"link"===e.type?p(e.href,t):"category"===e.type&&(p(e.href,t)||m(e.items,t))}function g(e){let{sidebarItems:t,pathname:n,onlyCategories:r=!1}=e;const a=[];return function e(t){for(const o of t)if("category"===o.type&&((0,c.Mg)(o.href,n)||e(o.items))||"link"===o.type&&(0,c.Mg)(o.href,n)){return r&&"category"!==o.type||a.unshift(o),!0}return!1}(t),a}function b(){const e=(0,s.V)(),{pathname:t}=(0,a.TH)(),n=(0,i.gA)()?.pluginData.breadcrumbs;return!1!==n&&e?g({sidebarItems:e.items,pathname:t}):null}function v(e){const{activeVersion:t}=(0,i.Iw)(e),{preferredVersion:n}=(0,l.J)(e),a=(0,i.yW)(e);return(0,r.useMemo)((()=>(0,u.j)([t,n,a].filter(Boolean))),[t,n,a])}function y(e,t){const n=v(t);return(0,r.useMemo)((()=>{const t=n.flatMap((e=>e.sidebars?Object.entries(e.sidebars):[])),r=t.find((t=>t[0]===e));if(!r)throw new Error(`Can't find any sidebar with id "${e}" in version${n.length>1?"s":""} ${n.map((e=>e.name)).join(", ")}".\nAvailable sidebar ids are:\n- ${t.map((e=>e[0])).join("\n- ")}`);return r[1]}),[e,n])}function E(e,t){const n=v(t);return(0,r.useMemo)((()=>{const t=n.flatMap((e=>e.docs)),r=t.find((t=>t.id===e));if(!r){if(n.flatMap((e=>e.draftIds)).includes(e))return null;throw new Error(`Couldn't find any doc with id "${e}" in version${n.length>1?"s":""} "${n.map((e=>e.name)).join(", ")}".\nAvailable doc ids are:\n- ${(0,u.j)(t.map((e=>e.id))).join("\n- ")}`)}return r}),[e,n])}function S(e){let{route:t,versionMetadata:n}=e;const r=(0,a.TH)(),i=t.routes,l=i.find((e=>(0,a.LX)(r.pathname,e)));if(!l)return null;const s=l.sidebar,u=s?n.docsSidebars[s]:void 0;return{docElement:(0,o.H)(i),sidebarName:s,sidebarItems:u}}},2128:(e,t,n)=>{"use strict";n.d(t,{p:()=>a});var r=n(2263);function a(e){const{siteConfig:t}=(0,r.Z)(),{title:n,titleDelimiter:a}=t;return e?.trim().length?`${e.trim()} ${a} ${n}`:n}},1980:(e,t,n)=>{"use strict";n.d(t,{Nc:()=>u,Rb:()=>l,_X:()=>s});var r=n(7294),a=n(6550),o=n(1688),i=n(902);function l(e){!function(e){const t=(0,a.k6)(),n=(0,i.zX)(e);(0,r.useEffect)((()=>t.block(((e,t)=>n(e,t)))),[t,n])}(((t,n)=>{if("POP"===n)return e(t,n)}))}function s(e){return function(e){const t=(0,a.k6)();return(0,o.useSyncExternalStore)(t.listen,(()=>e(t)),(()=>e(t)))}((t=>null===e?null:new URLSearchParams(t.location.search).get(e)))}function u(e){const t=s(e)??"",n=function(){const e=(0,a.k6)();return(0,r.useCallback)(((t,n,r)=>{const a=new URLSearchParams(e.location.search);n?a.set(t,n):a.delete(t),(r?.push?e.push:e.replace)({search:a.toString()})}),[e])}();return[t,(0,r.useCallback)(((t,r)=>{n(e,t,r)}),[n,e])]}},7392:(e,t,n)=>{"use strict";function r(e,t){return void 0===t&&(t=(e,t)=>e===t),e.filter(((n,r)=>e.findIndex((e=>t(e,n)))!==r))}function a(e){return Array.from(new Set(e))}n.d(t,{j:()=>a,l:()=>r})},833:(e,t,n)=>{"use strict";n.d(t,{FG:()=>f,d:()=>c,VC:()=>p});var r=n(7294),a=n(6010),o=n(5742),i=n(226);function l(){const e=r.useContext(i._);if(!e)throw new Error("Unexpected: no Docusaurus route context found");return e}var s=n(4996),u=n(2128);function c(e){let{title:t,description:n,keywords:a,image:i,children:l}=e;const c=(0,u.p)(t),{withBaseUrl:d}=(0,s.C)(),f=i?d(i,{absolute:!0}):void 0;return r.createElement(o.Z,null,t&&r.createElement("title",null,c),t&&r.createElement("meta",{property:"og:title",content:c}),n&&r.createElement("meta",{name:"description",content:n}),n&&r.createElement("meta",{property:"og:description",content:n}),a&&r.createElement("meta",{name:"keywords",content:Array.isArray(a)?a.join(","):a}),f&&r.createElement("meta",{property:"og:image",content:f}),f&&r.createElement("meta",{name:"twitter:image",content:f}),l)}const d=r.createContext(void 0);function f(e){let{className:t,children:n}=e;const i=r.useContext(d),l=(0,a.Z)(i,t);return r.createElement(d.Provider,{value:l},r.createElement(o.Z,null,r.createElement("html",{className:l})),n)}function p(e){let{children:t}=e;const n=l(),o=`plugin-${n.plugin.name.replace(/docusaurus-(?:plugin|theme)-(?:content-)?/gi,"")}`;const i=`plugin-id-${n.plugin.id}`;return r.createElement(f,{className:(0,a.Z)(o,i)},t)}},902:(e,t,n)=>{"use strict";n.d(t,{D9:()=>i,Qc:()=>u,Ql:()=>s,i6:()=>l,zX:()=>o});var r=n(7294);const a=n(412).Z.canUseDOM?r.useLayoutEffect:r.useEffect;function o(e){const t=(0,r.useRef)(e);return a((()=>{t.current=e}),[e]),(0,r.useCallback)((function(){return t.current(...arguments)}),[])}function i(e){const t=(0,r.useRef)();return a((()=>{t.current=e})),t.current}class l extends Error{constructor(e,t){super(),this.name="ReactContextError",this.message=`Hook ${this.stack?.split("\n")[1]?.match(/at (?:\w+\.)?(?\w+)/)?.groups.name??""} is called outside the <${e}>. ${t??""}`}}function s(e){const t=Object.entries(e);return t.sort(((e,t)=>e[0].localeCompare(t[0]))),(0,r.useMemo)((()=>e),t.flat())}function u(e){return t=>{let{children:n}=t;return r.createElement(r.Fragment,null,e.reduceRight(((e,t)=>r.createElement(t,null,e)),n))}}},8022:(e,t,n)=>{"use strict";function r(e,t){return void 0!==e&&void 0!==t&&new RegExp(e,"gi").test(t)}n.d(t,{F:()=>r})},8596:(e,t,n)=>{"use strict";n.d(t,{Mg:()=>i,Ns:()=>l});var r=n(7294),a=n(723),o=n(2263);function i(e,t){const n=e=>(!e||e.endsWith("/")?e:`${e}/`)?.toLowerCase();return n(e)===n(t)}function l(){const{baseUrl:e}=(0,o.Z)().siteConfig;return(0,r.useMemo)((()=>function(e){let{baseUrl:t,routes:n}=e;function r(e){return e.path===t&&!0===e.exact}function a(e){return e.path===t&&!e.exact}return function e(t){if(0===t.length)return;return t.find(r)||e(t.filter(a).flatMap((e=>e.routes??[])))}(n)}({routes:a.Z,baseUrl:e})),[e])}},2466:(e,t,n)=>{"use strict";n.d(t,{Ct:()=>p,OC:()=>s,RF:()=>d,o5:()=>f});var r=n(7294),a=n(412),o=n(2389),i=n(902);const l=r.createContext(void 0);function s(e){let{children:t}=e;const n=function(){const e=(0,r.useRef)(!0);return(0,r.useMemo)((()=>({scrollEventsEnabledRef:e,enableScrollEvents:()=>{e.current=!0},disableScrollEvents:()=>{e.current=!1}})),[])}();return r.createElement(l.Provider,{value:n},t)}function u(){const e=(0,r.useContext)(l);if(null==e)throw new i.i6("ScrollControllerProvider");return e}const c=()=>a.Z.canUseDOM?{scrollX:window.pageXOffset,scrollY:window.pageYOffset}:null;function d(e,t){void 0===t&&(t=[]);const{scrollEventsEnabledRef:n}=u(),a=(0,r.useRef)(c()),o=(0,i.zX)(e);(0,r.useEffect)((()=>{const e=()=>{if(!n.current)return;const e=c();o(e,a.current),a.current=e},t={passive:!0};return e(),window.addEventListener("scroll",e,t),()=>window.removeEventListener("scroll",e,t)}),[o,n,...t])}function f(){const e=u(),t=function(){const e=(0,r.useRef)({elem:null,top:0}),t=(0,r.useCallback)((t=>{e.current={elem:t,top:t.getBoundingClientRect().top}}),[]),n=(0,r.useCallback)((()=>{const{current:{elem:t,top:n}}=e;if(!t)return{restored:!1};const r=t.getBoundingClientRect().top-n;return r&&window.scrollBy({left:0,top:r}),e.current={elem:null,top:0},{restored:0!==r}}),[]);return(0,r.useMemo)((()=>({save:t,restore:n})),[n,t])}(),n=(0,r.useRef)(void 0),a=(0,r.useCallback)((r=>{t.save(r),e.disableScrollEvents(),n.current=()=>{const{restored:r}=t.restore();if(n.current=void 0,r){const t=()=>{e.enableScrollEvents(),window.removeEventListener("scroll",t)};window.addEventListener("scroll",t)}else e.enableScrollEvents()}}),[e,t]);return(0,r.useLayoutEffect)((()=>{queueMicrotask((()=>n.current?.()))})),{blockElementScrollPositionUntilNextRender:a}}function p(){const e=(0,r.useRef)(null),t=(0,o.Z)()&&"smooth"===getComputedStyle(document.documentElement).scrollBehavior;return{startScroll:n=>{e.current=t?function(e){return window.scrollTo({top:e,behavior:"smooth"}),()=>{}}(n):function(e){let t=null;const n=document.documentElement.scrollTop>e;return function r(){const a=document.documentElement.scrollTop;(n&&a>e||!n&&at&&cancelAnimationFrame(t)}(n)},cancelScroll:()=>e.current?.()}}},3320:(e,t,n)=>{"use strict";n.d(t,{HX:()=>i,_q:()=>s,os:()=>l});var r=n(143),a=n(2263),o=n(373);const i="default";function l(e,t){return`docs-${e}-${t}`}function s(){const{i18n:e}=(0,a.Z)(),t=(0,r._r)(),n=(0,r.WS)(),s=(0,o.Oh)();const u=[i,...Object.keys(t).map((function(e){const r=n?.activePlugin.pluginId===e?n.activeVersion:void 0,a=s[e],o=t[e].versions.find((e=>e.isLast));return l(e,(r??a??o).name)}))];return{locale:e.currentLocale,tags:u}}},12:(e,t,n)=>{"use strict";n.d(t,{Nk:()=>d,WA:()=>c,_f:()=>f});var r=n(7294),a=n(1688);const o="localStorage";function i(e){let{key:t,oldValue:n,newValue:r,storage:a}=e;if(n===r)return;const o=document.createEvent("StorageEvent");o.initStorageEvent("storage",!1,!1,t,n,r,window.location.href,a),window.dispatchEvent(o)}function l(e){if(void 0===e&&(e=o),"undefined"==typeof window)throw new Error("Browser storage is not available on Node.js/Docusaurus SSR process.");if("none"===e)return null;try{return window[e]}catch(n){return t=n,s||(console.warn("Docusaurus browser storage is not available.\nPossible reasons: running Docusaurus in an iframe, in an incognito browser session, or using too strict browser privacy settings.",t),s=!0),null}var t}let s=!1;const u={get:()=>null,set:()=>{},del:()=>{},listen:()=>()=>{}};function c(e,t){if("undefined"==typeof window)return function(e){function t(){throw new Error(`Illegal storage API usage for storage key "${e}".\nDocusaurus storage APIs are not supposed to be called on the server-rendering process.\nPlease only call storage APIs in effects and event handlers.`)}return{get:t,set:t,del:t,listen:t}}(e);const n=l(t?.persistence);return null===n?u:{get:()=>{try{return n.getItem(e)}catch(t){return console.error(`Docusaurus storage error, can't get key=${e}`,t),null}},set:t=>{try{const r=n.getItem(e);n.setItem(e,t),i({key:e,oldValue:r,newValue:t,storage:n})}catch(r){console.error(`Docusaurus storage error, can't set ${e}=${t}`,r)}},del:()=>{try{const t=n.getItem(e);n.removeItem(e),i({key:e,oldValue:t,newValue:null,storage:n})}catch(t){console.error(`Docusaurus storage error, can't delete key=${e}`,t)}},listen:t=>{try{const r=r=>{r.storageArea===n&&r.key===e&&t(r)};return window.addEventListener("storage",r),()=>window.removeEventListener("storage",r)}catch(r){return console.error(`Docusaurus storage error, can't listen for changes of key=${e}`,r),()=>{}}}}}function d(e,t){const n=(0,r.useRef)((()=>null===e?u:c(e,t))).current(),o=(0,r.useCallback)((e=>"undefined"==typeof window?()=>{}:n.listen(e)),[n]);return[(0,a.useSyncExternalStore)(o,(()=>"undefined"==typeof window?null:n.get()),(()=>null)),n]}function f(e){void 0===e&&(e=o);const t=l(e);if(!t)return[];const n=[];for(let r=0;r{"use strict";n.d(t,{l:()=>i});var r=n(2263),a=n(6550),o=n(8780);function i(){const{siteConfig:{baseUrl:e,url:t,trailingSlash:n},i18n:{defaultLocale:i,currentLocale:l}}=(0,r.Z)(),{pathname:s}=(0,a.TH)(),u=(0,o.applyTrailingSlash)(s,{trailingSlash:n,baseUrl:e}),c=l===i?e:e.replace(`/${l}/`,"/"),d=u.replace(e,"");return{createUrl:function(e){let{locale:n,fullyQualified:r}=e;return`${r?t:""}${function(e){return e===i?`${c}`:`${c}${e}/`}(n)}${d}`}}}},5936:(e,t,n)=>{"use strict";n.d(t,{S:()=>i});var r=n(7294),a=n(6550),o=n(902);function i(e){const t=(0,a.TH)(),n=(0,o.D9)(t),i=(0,o.zX)(e);(0,r.useEffect)((()=>{n&&t!==n&&i({location:t,previousLocation:n})}),[i,t,n])}},6668:(e,t,n)=>{"use strict";n.d(t,{L:()=>a});var r=n(2263);function a(){return(0,r.Z)().siteConfig.themeConfig}},6278:(e,t,n)=>{"use strict";n.d(t,{L:()=>a});var r=n(2263);function a(){const{siteConfig:{themeConfig:e}}=(0,r.Z)();return e}},239:(e,t,n)=>{"use strict";n.d(t,{l:()=>l});var r=n(7294),a=n(8022),o=n(4996),i=n(6278);function l(){const{withBaseUrl:e}=(0,o.C)(),{algolia:{externalUrlRegex:t,replaceSearchResultPathname:n}}=(0,i.L)();return(0,r.useCallback)((r=>{const o=new URL(r);if((0,a.F)(t,o.href))return r;const i=`${o.pathname+o.hash}`;return e(function(e,t){return t?e.replaceAll(new RegExp(t.from,"g"),t.to):e}(i,n))}),[e,t,n])}},8802:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){const{trailingSlash:n,baseUrl:r}=t;if(e.startsWith("#"))return e;if(void 0===n)return e;const[a]=e.split(/[#?]/),o="/"===a||a===r?a:(i=a,n?function(e){return e.endsWith("/")?e:`${e}/`}(i):function(e){return e.endsWith("/")?e.slice(0,-1):e}(i));var i;return e.replace(a,o)}},4143:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getErrorCausalChain=void 0,t.getErrorCausalChain=function e(t){return t.cause?[t,...e(t.cause)]:[t]}},8780:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getErrorCausalChain=t.applyTrailingSlash=t.blogPostContainerID=void 0,t.blogPostContainerID="__blog-post-container";var a=n(8802);Object.defineProperty(t,"applyTrailingSlash",{enumerable:!0,get:function(){return r(a).default}});var o=n(4143);Object.defineProperty(t,"getErrorCausalChain",{enumerable:!0,get:function(){return o.getErrorCausalChain}})},8522:()=>{!function(e){var t="\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b",n={pattern:/(^(["']?)\w+\2)[ \t]+\S.*/,lookbehind:!0,alias:"punctuation",inside:null},r={bash:n,environment:{pattern:RegExp("\\$"+t),alias:"constant"},variable:[{pattern:/\$?\(\([\s\S]+?\)\)/,greedy:!0,inside:{variable:[{pattern:/(^\$\(\([\s\S]+)\)\)/,lookbehind:!0},/^\$\(\(/],number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,operator:/--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,greedy:!0,inside:{variable:/^\$\(|^`|\)$|`$/}},{pattern:/\$\{[^}]+\}/,greedy:!0,inside:{operator:/:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,punctuation:/[\[\]]/,environment:{pattern:RegExp("(\\{)"+t),lookbehind:!0,alias:"constant"}}},/\$(?:\w+|[#?*!@$])/],entity:/\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/};e.languages.bash={shebang:{pattern:/^#!\s*\/.*/,alias:"important"},comment:{pattern:/(^|[^"{\\$])#.*/,lookbehind:!0},"function-name":[{pattern:/(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,lookbehind:!0,alias:"function"},{pattern:/\b[\w-]+(?=\s*\(\s*\)\s*\{)/,alias:"function"}],"for-or-select":{pattern:/(\b(?:for|select)\s+)\w+(?=\s+in\s)/,alias:"variable",lookbehind:!0},"assign-left":{pattern:/(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,inside:{environment:{pattern:RegExp("(^|[\\s;|&]|[<>]\\()"+t),lookbehind:!0,alias:"constant"}},alias:"variable",lookbehind:!0},string:[{pattern:/((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,lookbehind:!0,greedy:!0,inside:r},{pattern:/((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,lookbehind:!0,greedy:!0,inside:{bash:n}},{pattern:/(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,lookbehind:!0,greedy:!0,inside:r},{pattern:/(^|[^$\\])'[^']*'/,lookbehind:!0,greedy:!0},{pattern:/\$'(?:[^'\\]|\\[\s\S])*'/,greedy:!0,inside:{entity:r.entity}}],variable:r.variable,function:{pattern:/(^|[\n;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,lookbehind:!0},keyword:{pattern:/(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,lookbehind:!0},builtin:{pattern:/(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,lookbehind:!0,alias:"class-name"},boolean:{pattern:/(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,lookbehind:!0},"file-descriptor":{pattern:/\B&\d\b/,alias:"important"},operator:{pattern:/\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,inside:{"file-descriptor":{pattern:/^\d/,alias:"important"}}},punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,number:{pattern:/(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,lookbehind:!0}},n.inside=e.languages.bash;for(var a=["comment","function-name","for-or-select","assign-left","string","environment","function","keyword","builtin","boolean","file-descriptor","operator","punctuation","number"],o=r.variable[1].inside,i=0;i{Prism.languages.qmake={comment:/#.*/,variable:/(?:(?:^|\n)[a-z_A-Z]\w+(?=\s*(?:=|\+=|-=|\*=|~=))\b|\${2}[a-z_A-Z]\w+\b(?!\()|\${2}{[a-z_A-Z]\w+}|\b(?:QT|TEMPLATE|CONFIG|DEFINES|SOURCES|HEADERS|INCLUDEPATH|LIBS|QMAKE_CXXFLAGS)\b)/,boolean:/\b(?:true|false)\b/,operator:/(=|\+=|-=|\*=|~=)/,number:/\b\d+(?:\.\d+)*\b/,function:/(?:\b[a-z_]\w*(?=\s*\()\b|\${2}[a-z_]\w+(?=\s*\()\b)/i}},9482:(e,t,n)=>{"use strict";n.d(t,{Z:()=>a});const r=(0,n(7294).createContext)(void 0);r.displayName="RootFolderContext";const a=r},6010:(e,t,n)=>{"use strict";function r(e){var t,n,a="";if("string"==typeof e||"number"==typeof e)a+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;ta});const a=function(){for(var e,t,n=0,a="";n{"use strict";n.d(t,{lX:()=>E,q_:()=>C,ob:()=>p,PP:()=>I,Ep:()=>f});var r=n(7462);function a(e){return"/"===e.charAt(0)}function o(e,t){for(var n=t,r=n+1,a=e.length;r=0;f--){var p=i[f];"."===p?o(i,f):".."===p?(o(i,f),d++):d&&(o(i,f),d--)}if(!u)for(;d--;d)i.unshift("..");!u||""===i[0]||i[0]&&a(i[0])||i.unshift("");var m=i.join("/");return n&&"/"!==m.substr(-1)&&(m+="/"),m};var l=n(8776);function s(e){return"/"===e.charAt(0)?e:"/"+e}function u(e){return"/"===e.charAt(0)?e.substr(1):e}function c(e,t){return function(e,t){return 0===e.toLowerCase().indexOf(t.toLowerCase())&&-1!=="/?#".indexOf(e.charAt(t.length))}(e,t)?e.substr(t.length):e}function d(e){return"/"===e.charAt(e.length-1)?e.slice(0,-1):e}function f(e){var t=e.pathname,n=e.search,r=e.hash,a=t||"/";return n&&"?"!==n&&(a+="?"===n.charAt(0)?n:"?"+n),r&&"#"!==r&&(a+="#"===r.charAt(0)?r:"#"+r),a}function p(e,t,n,a){var o;"string"==typeof e?(o=function(e){var t=e||"/",n="",r="",a=t.indexOf("#");-1!==a&&(r=t.substr(a),t=t.substr(0,a));var o=t.indexOf("?");return-1!==o&&(n=t.substr(o),t=t.substr(0,o)),{pathname:t,search:"?"===n?"":n,hash:"#"===r?"":r}}(e),o.state=t):(void 0===(o=(0,r.Z)({},e)).pathname&&(o.pathname=""),o.search?"?"!==o.search.charAt(0)&&(o.search="?"+o.search):o.search="",o.hash?"#"!==o.hash.charAt(0)&&(o.hash="#"+o.hash):o.hash="",void 0!==t&&void 0===o.state&&(o.state=t));try{o.pathname=decodeURI(o.pathname)}catch(l){throw l instanceof URIError?new URIError('Pathname "'+o.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):l}return n&&(o.key=n),a?o.pathname?"/"!==o.pathname.charAt(0)&&(o.pathname=i(o.pathname,a.pathname)):o.pathname=a.pathname:o.pathname||(o.pathname="/"),o}function m(){var e=null;var t=[];return{setPrompt:function(t){return e=t,function(){e===t&&(e=null)}},confirmTransitionTo:function(t,n,r,a){if(null!=e){var o="function"==typeof e?e(t,n):e;"string"==typeof o?"function"==typeof r?r(o,a):a(!0):a(!1!==o)}else a(!0)},appendListener:function(e){var n=!0;function r(){n&&e.apply(void 0,arguments)}return t.push(r),function(){n=!1,t=t.filter((function(e){return e!==r}))}},notifyListeners:function(){for(var e=arguments.length,n=new Array(e),r=0;rt?n.splice(t,n.length-t,a):n.push(a),d({action:r,location:a,index:t,entries:n})}}))},replace:function(e,t){var r="REPLACE",a=p(e,t,h(),E.location);c.confirmTransitionTo(a,r,n,(function(e){e&&(E.entries[E.index]=a,d({action:r,location:a}))}))},go:y,goBack:function(){y(-1)},goForward:function(){y(1)},canGo:function(e){var t=E.index+e;return t>=0&&t{"use strict";var r=n(9864),a={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},o={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},i={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},l={};function s(e){return r.isMemo(e)?i:l[e.$$typeof]||a}l[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},l[r.Memo]=i;var u=Object.defineProperty,c=Object.getOwnPropertyNames,d=Object.getOwnPropertySymbols,f=Object.getOwnPropertyDescriptor,p=Object.getPrototypeOf,m=Object.prototype;e.exports=function e(t,n,r){if("string"!=typeof n){if(m){var a=p(n);a&&a!==m&&e(t,a,r)}var i=c(n);d&&(i=i.concat(d(n)));for(var l=s(t),h=s(n),g=0;g{"use strict";e.exports=function(e,t,n,r,a,o,i,l){if(!e){var s;if(void 0===t)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,r,a,o,i,l],c=0;(s=new Error(t.replace(/%s/g,(function(){return u[c++]})))).name="Invariant Violation"}throw s.framesToPop=1,s}}},5826:e=>{e.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},2497:(e,t,n)=>{"use strict";n.r(t)},8213:(e,t,n)=>{"use strict";n.r(t)},4865:function(e,t,n){var r,a;r=function(){var e,t,n={version:"0.2.0"},r=n.settings={minimum:.08,easing:"ease",positionUsing:"",speed:200,trickle:!0,trickleRate:.02,trickleSpeed:800,showSpinner:!0,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",template:'
'};function a(e,t,n){return en?n:e}function o(e){return 100*(-1+e)}function i(e,t,n){var a;return(a="translate3d"===r.positionUsing?{transform:"translate3d("+o(e)+"%,0,0)"}:"translate"===r.positionUsing?{transform:"translate("+o(e)+"%,0)"}:{"margin-left":o(e)+"%"}).transition="all "+t+"ms "+n,a}n.configure=function(e){var t,n;for(t in e)void 0!==(n=e[t])&&e.hasOwnProperty(t)&&(r[t]=n);return this},n.status=null,n.set=function(e){var t=n.isStarted();e=a(e,r.minimum,1),n.status=1===e?null:e;var o=n.render(!t),u=o.querySelector(r.barSelector),c=r.speed,d=r.easing;return o.offsetWidth,l((function(t){""===r.positionUsing&&(r.positionUsing=n.getPositioningCSS()),s(u,i(e,c,d)),1===e?(s(o,{transition:"none",opacity:1}),o.offsetWidth,setTimeout((function(){s(o,{transition:"all "+c+"ms linear",opacity:0}),setTimeout((function(){n.remove(),t()}),c)}),c)):setTimeout(t,c)})),this},n.isStarted=function(){return"number"==typeof n.status},n.start=function(){n.status||n.set(0);var e=function(){setTimeout((function(){n.status&&(n.trickle(),e())}),r.trickleSpeed)};return r.trickle&&e(),this},n.done=function(e){return e||n.status?n.inc(.3+.5*Math.random()).set(1):this},n.inc=function(e){var t=n.status;return t?("number"!=typeof e&&(e=(1-t)*a(Math.random()*t,.1,.95)),t=a(t+e,0,.994),n.set(t)):n.start()},n.trickle=function(){return n.inc(Math.random()*r.trickleRate)},e=0,t=0,n.promise=function(r){return r&&"resolved"!==r.state()?(0===t&&n.start(),e++,t++,r.always((function(){0==--t?(e=0,n.done()):n.set((e-t)/e)})),this):this},n.render=function(e){if(n.isRendered())return document.getElementById("nprogress");c(document.documentElement,"nprogress-busy");var t=document.createElement("div");t.id="nprogress",t.innerHTML=r.template;var a,i=t.querySelector(r.barSelector),l=e?"-100":o(n.status||0),u=document.querySelector(r.parent);return s(i,{transition:"all 0 linear",transform:"translate3d("+l+"%,0,0)"}),r.showSpinner||(a=t.querySelector(r.spinnerSelector))&&p(a),u!=document.body&&c(u,"nprogress-custom-parent"),u.appendChild(t),t},n.remove=function(){d(document.documentElement,"nprogress-busy"),d(document.querySelector(r.parent),"nprogress-custom-parent");var e=document.getElementById("nprogress");e&&p(e)},n.isRendered=function(){return!!document.getElementById("nprogress")},n.getPositioningCSS=function(){var e=document.body.style,t="WebkitTransform"in e?"Webkit":"MozTransform"in e?"Moz":"msTransform"in e?"ms":"OTransform"in e?"O":"";return t+"Perspective"in e?"translate3d":t+"Transform"in e?"translate":"margin"};var l=function(){var e=[];function t(){var n=e.shift();n&&n(t)}return function(n){e.push(n),1==e.length&&t()}}(),s=function(){var e=["Webkit","O","Moz","ms"],t={};function n(e){return e.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,(function(e,t){return t.toUpperCase()}))}function r(t){var n=document.body.style;if(t in n)return t;for(var r,a=e.length,o=t.charAt(0).toUpperCase()+t.slice(1);a--;)if((r=e[a]+o)in n)return r;return t}function a(e){return e=n(e),t[e]||(t[e]=r(e))}function o(e,t,n){t=a(t),e.style[t]=n}return function(e,t){var n,r,a=arguments;if(2==a.length)for(n in t)void 0!==(r=t[n])&&t.hasOwnProperty(n)&&o(e,n,r);else o(e,a[1],a[2])}}();function u(e,t){return("string"==typeof e?e:f(e)).indexOf(" "+t+" ")>=0}function c(e,t){var n=f(e),r=n+t;u(n,t)||(e.className=r.substring(1))}function d(e,t){var n,r=f(e);u(e,t)&&(n=r.replace(" "+t+" "," "),e.className=n.substring(1,n.length-1))}function f(e){return(" "+(e.className||"")+" ").replace(/\s+/gi," ")}function p(e){e&&e.parentNode&&e.parentNode.removeChild(e)}return n},void 0===(a="function"==typeof r?r.call(t,n,t,e):r)||(e.exports=a)},7418:e=>{"use strict";var t=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(a){return!1}}()?Object.assign:function(e,a){for(var o,i,l=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(e),s=1;s{var r=n(5826);e.exports=p,e.exports.parse=o,e.exports.compile=function(e,t){return l(o(e,t),t)},e.exports.tokensToFunction=l,e.exports.tokensToRegExp=f;var a=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function o(e,t){for(var n,r=[],o=0,i=0,l="",c=t&&t.delimiter||"/";null!=(n=a.exec(e));){var d=n[0],f=n[1],p=n.index;if(l+=e.slice(i,p),i=p+d.length,f)l+=f[1];else{var m=e[i],h=n[2],g=n[3],b=n[4],v=n[5],y=n[6],E=n[7];l&&(r.push(l),l="");var S=null!=h&&null!=m&&m!==h,_="+"===y||"*"===y,w="?"===y||"*"===y,T=n[2]||c,k=b||v;r.push({name:g||o++,prefix:h||"",delimiter:T,optional:w,repeat:_,partial:S,asterisk:!!E,pattern:k?u(k):E?".*":"[^"+s(T)+"]+?"})}}return i{"use strict";n.d(t,{Z:()=>o});var r=function(){var e=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,t=0,n={},r={util:{encode:function e(t){return t instanceof a?new a(t.type,e(t.content),t.alias):Array.isArray(t)?t.map(e):t.replace(/&/g,"&").replace(/=d.reach);w+=_.value.length,_=_.next){var T=_.value;if(t.length>e.length)return;if(!(T instanceof a)){var k,C=1;if(v){if(!(k=o(S,w,e,b))||k.index>=e.length)break;var A=k.index,I=k.index+k[0].length,O=w;for(O+=_.value.length;A>=O;)O+=(_=_.next).value.length;if(w=O-=_.value.length,_.value instanceof a)continue;for(var R=_;R!==t.tail&&(Od.reach&&(d.reach=x);var D=_.prev;if(L&&(D=s(t,D,L),w+=L.length),u(t,D,C),_=s(t,D,new a(f,g?r.tokenize(N,g):N,y,N)),P&&s(t,_,P),C>1){var M={cause:f+","+m,reach:x};i(e,t,n,_.prev,w,M),d&&M.reach>d.reach&&(d.reach=M.reach)}}}}}}function l(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0}function s(e,t,n){var r=t.next,a={value:n,prev:t,next:r};return t.next=a,r.prev=a,e.length++,a}function u(e,t,n){for(var r=t.next,a=0;a"+o.content+""},r}(),a=r;r.default=r,a.languages.markup={comment:{pattern://,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern://i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]},a.languages.markup.tag.inside["attr-value"].inside.entity=a.languages.markup.entity,a.languages.markup.doctype.inside["internal-subset"].inside=a.languages.markup,a.hooks.add("wrap",(function(e){"entity"===e.type&&(e.attributes.title=e.content.replace(/&/,"&"))})),Object.defineProperty(a.languages.markup.tag,"addInlined",{value:function(e,t){var n={};n["language-"+t]={pattern:/(^$)/i,lookbehind:!0,inside:a.languages[t]},n.cdata=/^$/i;var r={"included-cdata":{pattern://i,inside:n}};r["language-"+t]={pattern:/[\s\S]+/,inside:a.languages[t]};var o={};o[e]={pattern:RegExp(/(<__[^>]*>)(?:))*\]\]>|(?!)/.source.replace(/__/g,(function(){return e})),"i"),lookbehind:!0,greedy:!0,inside:r},a.languages.insertBefore("markup","cdata",o)}}),Object.defineProperty(a.languages.markup.tag,"addAttribute",{value:function(e,t){a.languages.markup.tag.inside["special-attr"].push({pattern:RegExp(/(^|["'\s])/.source+"(?:"+e+")"+/\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,"i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[t,"language-"+t],inside:a.languages[t]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}}),a.languages.html=a.languages.markup,a.languages.mathml=a.languages.markup,a.languages.svg=a.languages.markup,a.languages.xml=a.languages.extend("markup",{}),a.languages.ssml=a.languages.xml,a.languages.atom=a.languages.xml,a.languages.rss=a.languages.xml,function(e){var t="\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b",n={pattern:/(^(["']?)\w+\2)[ \t]+\S.*/,lookbehind:!0,alias:"punctuation",inside:null},r={bash:n,environment:{pattern:RegExp("\\$"+t),alias:"constant"},variable:[{pattern:/\$?\(\([\s\S]+?\)\)/,greedy:!0,inside:{variable:[{pattern:/(^\$\(\([\s\S]+)\)\)/,lookbehind:!0},/^\$\(\(/],number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,operator:/--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,greedy:!0,inside:{variable:/^\$\(|^`|\)$|`$/}},{pattern:/\$\{[^}]+\}/,greedy:!0,inside:{operator:/:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,punctuation:/[\[\]]/,environment:{pattern:RegExp("(\\{)"+t),lookbehind:!0,alias:"constant"}}},/\$(?:\w+|[#?*!@$])/],entity:/\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/};e.languages.bash={shebang:{pattern:/^#!\s*\/.*/,alias:"important"},comment:{pattern:/(^|[^"{\\$])#.*/,lookbehind:!0},"function-name":[{pattern:/(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,lookbehind:!0,alias:"function"},{pattern:/\b[\w-]+(?=\s*\(\s*\)\s*\{)/,alias:"function"}],"for-or-select":{pattern:/(\b(?:for|select)\s+)\w+(?=\s+in\s)/,alias:"variable",lookbehind:!0},"assign-left":{pattern:/(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,inside:{environment:{pattern:RegExp("(^|[\\s;|&]|[<>]\\()"+t),lookbehind:!0,alias:"constant"}},alias:"variable",lookbehind:!0},string:[{pattern:/((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,lookbehind:!0,greedy:!0,inside:r},{pattern:/((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,lookbehind:!0,greedy:!0,inside:{bash:n}},{pattern:/(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,lookbehind:!0,greedy:!0,inside:r},{pattern:/(^|[^$\\])'[^']*'/,lookbehind:!0,greedy:!0},{pattern:/\$'(?:[^'\\]|\\[\s\S])*'/,greedy:!0,inside:{entity:r.entity}}],environment:{pattern:RegExp("\\$?"+t),alias:"constant"},variable:r.variable,function:{pattern:/(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,lookbehind:!0},keyword:{pattern:/(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,lookbehind:!0},builtin:{pattern:/(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,lookbehind:!0,alias:"class-name"},boolean:{pattern:/(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,lookbehind:!0},"file-descriptor":{pattern:/\B&\d\b/,alias:"important"},operator:{pattern:/\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,inside:{"file-descriptor":{pattern:/^\d/,alias:"important"}}},punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,number:{pattern:/(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,lookbehind:!0}},n.inside=e.languages.bash;for(var a=["comment","function-name","for-or-select","assign-left","string","environment","function","keyword","builtin","boolean","file-descriptor","operator","punctuation","number"],o=r.variable[1].inside,i=0;i]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/},a.languages.c=a.languages.extend("clike",{comment:{pattern:/\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},string:{pattern:/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},"class-name":{pattern:/(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,lookbehind:!0},keyword:/\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,function:/\b[a-z_]\w*(?=\s*\()/i,number:/(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/}),a.languages.insertBefore("c","string",{char:{pattern:/'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,greedy:!0}}),a.languages.insertBefore("c","string",{macro:{pattern:/(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,greedy:!0,alias:"property",inside:{string:[{pattern:/^(#\s*include\s*)<[^>]+>/,lookbehind:!0},a.languages.c.string],char:a.languages.c.char,comment:a.languages.c.comment,"macro-name":[{pattern:/(^#\s*define\s+)\w+\b(?!\()/i,lookbehind:!0},{pattern:/(^#\s*define\s+)\w+\b(?=\()/i,lookbehind:!0,alias:"function"}],directive:{pattern:/^(#\s*)[a-z]+/,lookbehind:!0,alias:"keyword"},"directive-hash":/^#/,punctuation:/##|\\(?=[\r\n])/,expression:{pattern:/\S[\s\S]*/,inside:a.languages.c}}}}),a.languages.insertBefore("c","function",{constant:/\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/}),delete a.languages.c.boolean,function(e){var t=/\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,n=/\b(?!)\w+(?:\s*\.\s*\w+)*\b/.source.replace(//g,(function(){return t.source}));e.languages.cpp=e.languages.extend("c",{"class-name":[{pattern:RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!)\w+/.source.replace(//g,(function(){return t.source}))),lookbehind:!0},/\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/],keyword:t,number:{pattern:/(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,greedy:!0},operator:/>>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,boolean:/\b(?:false|true)\b/}),e.languages.insertBefore("cpp","string",{module:{pattern:RegExp(/(\b(?:import|module)\s+)/.source+"(?:"+/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source+"|"+/(?:\s*:\s*)?|:\s*/.source.replace(//g,(function(){return n}))+")"),lookbehind:!0,greedy:!0,inside:{string:/^[<"][\s\S]+/,operator:/:/,punctuation:/\./}},"raw-string":{pattern:/R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,alias:"string",greedy:!0}}),e.languages.insertBefore("cpp","keyword",{"generic-function":{pattern:/\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,inside:{function:/^\w+/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:e.languages.cpp}}}}),e.languages.insertBefore("cpp","operator",{"double-colon":{pattern:/::/,alias:"punctuation"}}),e.languages.insertBefore("cpp","class-name",{"base-clause":{pattern:/(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,lookbehind:!0,greedy:!0,inside:e.languages.extend("cpp",{})}}),e.languages.insertBefore("inside","double-colon",{"class-name":/\b[a-z_]\w*\b(?!\s*::)/i},e.languages.cpp["base-clause"])}(a),function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:"selector"},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp("\\burl\\((?:"+t.source+"|"+/(?:[^\\\r\n()"']|\\[\s\S])*/.source+")\\)","i"),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp("^"+t.source+"$"),alias:"url"}}},selector:{pattern:RegExp("(^|[{}\\s])[^{}\\s](?:[^{};\"'\\s]|\\s+(?![\\s{])|"+t.source+")*(?=\\s*\\{)"),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var n=e.languages.markup;n&&(n.tag.addInlined("style","css"),n.tag.addAttribute("style","css"))}(a),function(e){var t,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;e.languages.css.selector={pattern:e.languages.css.selector.pattern,lookbehind:!0,inside:t={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-\w]+/,id:/#[-\w]+/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)(?:(?!\s)[-*\w\xA0-\uFFFF])*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)(?:(?!\s)[-\w\xA0-\uFFFF])+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)(?:(?!\s)[-\w\xA0-\uFFFF])+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],combinator:/>|\+|~|\|\|/,punctuation:/[(),]/}},e.languages.css.atrule.inside["selector-function-argument"].inside=t,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*/i,lookbehind:!0}});var r={pattern:/(\b\d+)(?:%|[a-z]+(?![\w-]))/,lookbehind:!0},a={pattern:/(^|[^\w.-])-?(?:\d+(?:\.\d+)?|\.\d+)/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#[\da-f]{3,8}\b/i,alias:"color"},color:[{pattern:/(^|[^\w-])(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)(?![\w-])/i,lookbehind:!0},{pattern:/\b(?:hsl|rgb)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:hsl|rgb)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,inside:{unit:r,number:a,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:r,number:a})}(a),a.languages.javascript=a.languages.extend("clike",{"class-name":[a.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(/(^|[^\w$])/.source+"(?:"+/NaN|Infinity/.source+"|"+/0[bB][01]+(?:_[01]+)*n?/.source+"|"+/0[oO][0-7]+(?:_[0-7]+)*n?/.source+"|"+/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source+"|"+/\d+(?:_\d+)*n/.source+"|"+/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source+")"+/(?![\w$])/.source),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),a.languages.javascript["class-name"][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,a.languages.insertBefore("javascript","keyword",{regex:{pattern:/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:a.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:a.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:a.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:a.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:a.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),a.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:a.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:"property"}}),a.languages.insertBefore("javascript","operator",{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:"property"}}),a.languages.markup&&(a.languages.markup.tag.addInlined("script","javascript"),a.languages.markup.tag.addAttribute(/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,"javascript")),a.languages.js=a.languages.javascript,function(e){var t=/#(?!\{).+/,n={pattern:/#\{[^}]+\}/,alias:"variable"};e.languages.coffeescript=e.languages.extend("javascript",{comment:t,string:[{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,inside:{interpolation:n}}],keyword:/\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,"class-member":{pattern:/@(?!\d)\w+/,alias:"variable"}}),e.languages.insertBefore("coffeescript","comment",{"multiline-comment":{pattern:/###[\s\S]+?###/,alias:"comment"},"block-regex":{pattern:/\/{3}[\s\S]*?\/{3}/,alias:"regex",inside:{comment:t,interpolation:n}}}),e.languages.insertBefore("coffeescript","string",{"inline-javascript":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,inside:{delimiter:{pattern:/^`|`$/,alias:"punctuation"},script:{pattern:/[\s\S]+/,alias:"language-javascript",inside:e.languages.javascript}}},"multiline-string":[{pattern:/'''[\s\S]*?'''/,greedy:!0,alias:"string"},{pattern:/"""[\s\S]*?"""/,greedy:!0,alias:"string",inside:{interpolation:n}}]}),e.languages.insertBefore("coffeescript","keyword",{property:/(?!\d)\w+(?=\s*:(?!:))/}),delete e.languages.coffeescript["template-string"],e.languages.coffee=e.languages.coffeescript}(a),function(e){var t=/[*&][^\s[\]{},]+/,n=/!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/,r="(?:"+n.source+"(?:[ \t]+"+t.source+")?|"+t.source+"(?:[ \t]+"+n.source+")?)",a=/(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-])(?:[ \t]*(?:(?![#:])|:))*/.source.replace(//g,(function(){return/[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source})),o=/"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;function i(e,t){t=(t||"").replace(/m/g,"")+"m";var n=/([:\-,[{]\s*(?:\s<>[ \t]+)?)(?:<>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source.replace(/<>/g,(function(){return r})).replace(/<>/g,(function(){return e}));return RegExp(n,t)}e.languages.yaml={scalar:{pattern:RegExp(/([\-:]\s*(?:\s<>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source.replace(/<>/g,(function(){return r}))),lookbehind:!0,alias:"string"},comment:/#.*/,key:{pattern:RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<>[ \t]+)?)<>(?=\s*:\s)/.source.replace(/<>/g,(function(){return r})).replace(/<>/g,(function(){return"(?:"+a+"|"+o+")"}))),lookbehind:!0,greedy:!0,alias:"atrule"},directive:{pattern:/(^[ \t]*)%.+/m,lookbehind:!0,alias:"important"},datetime:{pattern:i(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?))?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),lookbehind:!0,alias:"number"},boolean:{pattern:i(/false|true/.source,"i"),lookbehind:!0,alias:"important"},null:{pattern:i(/null|~/.source,"i"),lookbehind:!0,alias:"important"},string:{pattern:i(o),lookbehind:!0,greedy:!0},number:{pattern:i(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source,"i"),lookbehind:!0},tag:n,important:t,punctuation:/---|[:[\]{}\-,|>?]|\.\.\./},e.languages.yml=e.languages.yaml}(a),function(e){var t=/(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;function n(e){return e=e.replace(//g,(function(){return t})),RegExp(/((?:^|[^\\])(?:\\{2})*)/.source+"(?:"+e+")")}var r=/(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source,a=/\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g,(function(){return r})),o=/\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;e.languages.markdown=e.languages.extend("markup",{}),e.languages.insertBefore("markdown","prolog",{"front-matter-block":{pattern:/(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"front-matter":{pattern:/\S+(?:\s+\S+)*/,alias:["yaml","language-yaml"],inside:e.languages.yaml}}},blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:"punctuation"},table:{pattern:RegExp("^"+a+o+"(?:"+a+")*","m"),inside:{"table-data-rows":{pattern:RegExp("^("+a+o+")(?:"+a+")*$"),lookbehind:!0,inside:{"table-data":{pattern:RegExp(r),inside:e.languages.markdown},punctuation:/\|/}},"table-line":{pattern:RegExp("^("+a+")"+o+"$"),lookbehind:!0,inside:{punctuation:/\||:?-{3,}:?/}},"table-header-row":{pattern:RegExp("^"+a+"$"),inside:{"table-header":{pattern:RegExp(r),alias:"important",inside:e.languages.markdown},punctuation:/\|/}}}},code:[{pattern:/((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,lookbehind:!0,alias:"keyword"},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:"url"},bold:{pattern:n(/\b__(?:(?!_)|_(?:(?!_))+_)+__\b|\*\*(?:(?!\*)|\*(?:(?!\*))+\*)+\*\*/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[\s\S]+(?=..$)/,lookbehind:!0,inside:{}},punctuation:/\*\*|__/}},italic:{pattern:n(/\b_(?:(?!_)|__(?:(?!_))+__)+_\b|\*(?:(?!\*)|\*\*(?:(?!\*))+\*\*)+\*/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^.)[\s\S]+(?=.$)/,lookbehind:!0,inside:{}},punctuation:/[*_]/}},strike:{pattern:n(/(~~?)(?:(?!~))+\2/.source),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^~~?)[\s\S]+(?=\1$)/,lookbehind:!0,inside:{}},punctuation:/~~?/}},"code-snippet":{pattern:/(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,lookbehind:!0,greedy:!0,alias:["code","keyword"]},url:{pattern:n(/!?\[(?:(?!\]))+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\]))+\])/.source),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ \t]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,lookbehind:!0}}}}),["url","bold","italic","strike"].forEach((function(t){["url","bold","italic","strike","code-snippet"].forEach((function(n){t!==n&&(e.languages.markdown[t].inside.content.inside[n]=e.languages.markdown[n])}))})),e.hooks.add("after-tokenize",(function(e){"markdown"!==e.language&&"md"!==e.language||function e(t){if(t&&"string"!=typeof t)for(var n=0,r=t.length;n",quot:'"'},s=String.fromCodePoint||String.fromCharCode;e.languages.md=e.languages.markdown}(a),a.languages.graphql={comment:/#.*/,description:{pattern:/(?:"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*")(?=\s*[a-z_])/i,greedy:!0,alias:"string",inside:{"language-markdown":{pattern:/(^"(?:"")?)(?!\1)[\s\S]+(?=\1$)/,lookbehind:!0,inside:a.languages.markdown}}},string:{pattern:/"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*"/,greedy:!0},number:/(?:\B-|\b)\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,boolean:/\b(?:false|true)\b/,variable:/\$[a-z_]\w*/i,directive:{pattern:/@[a-z_]\w*/i,alias:"function"},"attr-name":{pattern:/\b[a-z_]\w*(?=\s*(?:\((?:[^()"]|"(?:\\.|[^\\"\r\n])*")*\))?:)/i,greedy:!0},"atom-input":{pattern:/\b[A-Z]\w*Input\b/,alias:"class-name"},scalar:/\b(?:Boolean|Float|ID|Int|String)\b/,constant:/\b[A-Z][A-Z_\d]*\b/,"class-name":{pattern:/(\b(?:enum|implements|interface|on|scalar|type|union)\s+|&\s*|:\s*|\[)[A-Z_]\w*/,lookbehind:!0},fragment:{pattern:/(\bfragment\s+|\.{3}\s*(?!on\b))[a-zA-Z_]\w*/,lookbehind:!0,alias:"function"},"definition-mutation":{pattern:/(\bmutation\s+)[a-zA-Z_]\w*/,lookbehind:!0,alias:"function"},"definition-query":{pattern:/(\bquery\s+)[a-zA-Z_]\w*/,lookbehind:!0,alias:"function"},keyword:/\b(?:directive|enum|extend|fragment|implements|input|interface|mutation|on|query|repeatable|scalar|schema|subscription|type|union)\b/,operator:/[!=|&]|\.{3}/,"property-query":/\w+(?=\s*\()/,object:/\w+(?=\s*\{)/,punctuation:/[!(){}\[\]:=,]/,property:/\w+/},a.hooks.add("after-tokenize",(function(e){if("graphql"===e.language)for(var t=e.tokens.filter((function(e){return"string"!=typeof e&&"comment"!==e.type&&"scalar"!==e.type})),n=0;n0)){var l=f(/^\{$/,/^\}$/);if(-1===l)continue;for(var s=n;s=0&&p(u,"variable-input")}}}}function c(e){return t[n+e]}function d(e,t){t=t||0;for(var n=0;n?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,punctuation:/[;[\]()`,.]/},function(e){var t=e.languages.javascript["template-string"],n=t.pattern.source,r=t.inside.interpolation,a=r.inside["interpolation-punctuation"],o=r.pattern.source;function i(t,r){if(e.languages[t])return{pattern:RegExp("((?:"+r+")\\s*)"+n),lookbehind:!0,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},"embedded-code":{pattern:/[\s\S]+/,alias:t}}}}function l(e,t){return"___"+t.toUpperCase()+"_"+e+"___"}function s(t,n,r){var a={code:t,grammar:n,language:r};return e.hooks.run("before-tokenize",a),a.tokens=e.tokenize(a.code,a.grammar),e.hooks.run("after-tokenize",a),a.tokens}function u(t){var n={};n["interpolation-punctuation"]=a;var o=e.tokenize(t,n);if(3===o.length){var i=[1,1];i.push.apply(i,s(o[1],e.languages.javascript,"javascript")),o.splice.apply(o,i)}return new e.Token("interpolation",o,r.alias,t)}function c(t,n,r){var a=e.tokenize(t,{interpolation:{pattern:RegExp(o),lookbehind:!0}}),i=0,c={},d=s(a.map((function(e){if("string"==typeof e)return e;for(var n,a=e.content;-1!==t.indexOf(n=l(i++,r)););return c[n]=a,n})).join(""),n,r),f=Object.keys(c);return i=0,function e(t){for(var n=0;n=f.length)return;var r=t[n];if("string"==typeof r||"string"==typeof r.content){var a=f[i],o="string"==typeof r?r:r.content,l=o.indexOf(a);if(-1!==l){++i;var s=o.substring(0,l),d=u(c[a]),p=o.substring(l+a.length),m=[];if(s&&m.push(s),m.push(d),p){var h=[p];e(h),m.push.apply(m,h)}"string"==typeof r?(t.splice.apply(t,[n,1].concat(m)),n+=m.length-1):r.content=m}}else{var g=r.content;Array.isArray(g)?e(g):e([g])}}}(d),new e.Token(r,d,"language-"+r,t)}e.languages.javascript["template-string"]=[i("css",/\b(?:styled(?:\([^)]*\))?(?:\s*\.\s*\w+(?:\([^)]*\))*)*|css(?:\s*\.\s*(?:global|resolve))?|createGlobalStyle|keyframes)/.source),i("html",/\bhtml|\.\s*(?:inner|outer)HTML\s*\+?=/.source),i("svg",/\bsvg/.source),i("markdown",/\b(?:markdown|md)/.source),i("graphql",/\b(?:gql|graphql(?:\s*\.\s*experimental)?)/.source),i("sql",/\bsql/.source),t].filter(Boolean);var d={javascript:!0,js:!0,typescript:!0,ts:!0,jsx:!0,tsx:!0};function f(e){return"string"==typeof e?e:Array.isArray(e)?e.map(f).join(""):f(e.content)}e.hooks.add("after-tokenize",(function(t){t.language in d&&function t(n){for(var r=0,a=n.length;r]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),e.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete e.languages.typescript.parameter,delete e.languages.typescript["literal-property"];var t=e.languages.extend("typescript",{});delete t["class-name"],e.languages.typescript["class-name"].inside=t,e.languages.insertBefore("typescript","function",{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:"operator"},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:t}}}}),e.languages.ts=e.languages.typescript}(a),function(e){function t(e,t){return RegExp(e.replace(//g,(function(){return/(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/.source})),t)}e.languages.insertBefore("javascript","function-variable",{"method-variable":{pattern:RegExp("(\\.\\s*)"+e.languages.javascript["function-variable"].pattern.source),lookbehind:!0,alias:["function-variable","method","function","property-access"]}}),e.languages.insertBefore("javascript","function",{method:{pattern:RegExp("(\\.\\s*)"+e.languages.javascript.function.source),lookbehind:!0,alias:["function","property-access"]}}),e.languages.insertBefore("javascript","constant",{"known-class-name":[{pattern:/\b(?:(?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)?Array|ArrayBuffer|BigInt|Boolean|DataView|Date|Error|Function|Intl|JSON|(?:Weak)?(?:Map|Set)|Math|Number|Object|Promise|Proxy|Reflect|RegExp|String|Symbol|WebAssembly)\b/,alias:"class-name"},{pattern:/\b(?:[A-Z]\w*)Error\b/,alias:"class-name"}]}),e.languages.insertBefore("javascript","keyword",{imports:{pattern:t(/(\bimport\b\s*)(?:(?:\s*,\s*(?:\*\s*as\s+|\{[^{}]*\}))?|\*\s*as\s+|\{[^{}]*\})(?=\s*\bfrom\b)/.source),lookbehind:!0,inside:e.languages.javascript},exports:{pattern:t(/(\bexport\b\s*)(?:\*(?:\s*as\s+)?(?=\s*\bfrom\b)|\{[^{}]*\})/.source),lookbehind:!0,inside:e.languages.javascript}}),e.languages.javascript.keyword.unshift({pattern:/\b(?:as|default|export|from|import)\b/,alias:"module"},{pattern:/\b(?:await|break|catch|continue|do|else|finally|for|if|return|switch|throw|try|while|yield)\b/,alias:"control-flow"},{pattern:/\bnull\b/,alias:["null","nil"]},{pattern:/\bundefined\b/,alias:"nil"}),e.languages.insertBefore("javascript","operator",{spread:{pattern:/\.{3}/,alias:"operator"},arrow:{pattern:/=>/,alias:"operator"}}),e.languages.insertBefore("javascript","punctuation",{"property-access":{pattern:t(/(\.\s*)#?/.source),lookbehind:!0},"maybe-class-name":{pattern:/(^|[^$\w\xA0-\uFFFF])[A-Z][$\w\xA0-\uFFFF]+/,lookbehind:!0},dom:{pattern:/\b(?:document|(?:local|session)Storage|location|navigator|performance|window)\b/,alias:"variable"},console:{pattern:/\bconsole(?=\s*\.)/,alias:"class-name"}});for(var n=["function","function-variable","method","method-variable","property-access"],r=0;r*\.{3}(?:[^{}]|)*\})/.source;function o(e,t){return e=e.replace(//g,(function(){return n})).replace(//g,(function(){return r})).replace(//g,(function(){return a})),RegExp(e,t)}a=o(a).source,e.languages.jsx=e.languages.extend("markup",t),e.languages.jsx.tag.pattern=o(/<\/?(?:[\w.:-]+(?:+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|))?|))**\/?)?>/.source),e.languages.jsx.tag.inside.tag.pattern=/^<\/?[^\s>\/]*/,e.languages.jsx.tag.inside["attr-value"].pattern=/=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/,e.languages.jsx.tag.inside.tag.inside["class-name"]=/^[A-Z]\w*(?:\.[A-Z]\w*)*$/,e.languages.jsx.tag.inside.comment=t.comment,e.languages.insertBefore("inside","attr-name",{spread:{pattern:o(//.source),inside:e.languages.jsx}},e.languages.jsx.tag),e.languages.insertBefore("inside","special-attr",{script:{pattern:o(/=/.source),alias:"language-javascript",inside:{"script-punctuation":{pattern:/^=(?=\{)/,alias:"punctuation"},rest:e.languages.jsx}}},e.languages.jsx.tag);var i=function(e){return e?"string"==typeof e?e:"string"==typeof e.content?e.content:e.content.map(i).join(""):""},l=function(t){for(var n=[],r=0;r0&&n[n.length-1].tagName===i(a.content[0].content[1])&&n.pop():"/>"===a.content[a.content.length-1].content||n.push({tagName:i(a.content[0].content[1]),openedBraces:0}):n.length>0&&"punctuation"===a.type&&"{"===a.content?n[n.length-1].openedBraces++:n.length>0&&n[n.length-1].openedBraces>0&&"punctuation"===a.type&&"}"===a.content?n[n.length-1].openedBraces--:o=!0),(o||"string"==typeof a)&&n.length>0&&0===n[n.length-1].openedBraces){var s=i(a);r0&&("string"==typeof t[r-1]||"plain-text"===t[r-1].type)&&(s=i(t[r-1])+s,t.splice(r-1,1),r--),t[r]=new e.Token("plain-text",s,null,s)}a.content&&"string"!=typeof a.content&&l(a.content)}};e.hooks.add("after-tokenize",(function(e){"jsx"!==e.language&&"tsx"!==e.language||l(e.tokens)}))}(a),function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach((function(n){var r=t[n],a=[];/^\w+$/.test(n)||a.push(/\w+/.exec(n)[0]),"diff"===n&&a.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:a,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}})),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(a),a.languages.git={comment:/^#.*/m,deleted:/^[-\u2013].*/m,inserted:/^\+.*/m,string:/("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,command:{pattern:/^.*\$ git .*$/m,inside:{parameter:/\s--?\w+/}},coord:/^@@.*@@$/m,"commit-sha1":/^commit \w{40}$/m},a.languages.go=a.languages.extend("clike",{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,boolean:/\b(?:_|false|iota|nil|true)\b/,number:[/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i],operator:/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,builtin:/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/}),a.languages.insertBefore("go","string",{char:{pattern:/'(?:\\.|[^'\\\r\n]){0,10}'/,greedy:!0}}),delete a.languages.go["class-name"],function(e){function t(e,t){return"___"+e.toUpperCase()+t+"___"}Object.defineProperties(e.languages["markup-templating"]={},{buildPlaceholders:{value:function(n,r,a,o){if(n.language===r){var i=n.tokenStack=[];n.code=n.code.replace(a,(function(e){if("function"==typeof o&&!o(e))return e;for(var a,l=i.length;-1!==n.code.indexOf(a=t(r,l));)++l;return i[l]=e,a})),n.grammar=e.languages.markup}}},tokenizePlaceholders:{value:function(n,r){if(n.language===r&&n.tokenStack){n.grammar=e.languages[r];var a=0,o=Object.keys(n.tokenStack);!function i(l){for(var s=0;s=o.length);s++){var u=l[s];if("string"==typeof u||u.content&&"string"==typeof u.content){var c=o[a],d=n.tokenStack[c],f="string"==typeof u?u:u.content,p=t(r,c),m=f.indexOf(p);if(m>-1){++a;var h=f.substring(0,m),g=new e.Token(r,e.tokenize(d,n.grammar),"language-"+r,d),b=f.substring(m+p.length),v=[];h&&v.push.apply(v,i([h])),v.push(g),b&&v.push.apply(v,i([b])),"string"==typeof u?l.splice.apply(l,[s,1].concat(v)):u.content=v}}else u.content&&i(u.content)}return l}(n.tokens)}}}})}(a),function(e){e.languages.handlebars={comment:/\{\{![\s\S]*?\}\}/,delimiter:{pattern:/^\{\{\{?|\}\}\}?$/,alias:"punctuation"},string:/(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][+-]?\d+)?/,boolean:/\b(?:false|true)\b/,block:{pattern:/^(\s*(?:~\s*)?)[#\/]\S+?(?=\s*(?:~\s*)?$|\s)/,lookbehind:!0,alias:"keyword"},brackets:{pattern:/\[[^\]]+\]/,inside:{punctuation:/\[|\]/,variable:/[\s\S]+/}},punctuation:/[!"#%&':()*+,.\/;<=>@\[\\\]^`{|}~]/,variable:/[^!"#%&'()*+,\/;<=>@\[\\\]^`{|}~\s]+/},e.hooks.add("before-tokenize",(function(t){e.languages["markup-templating"].buildPlaceholders(t,"handlebars",/\{\{\{[\s\S]+?\}\}\}|\{\{[\s\S]+?\}\}/g)})),e.hooks.add("after-tokenize",(function(t){e.languages["markup-templating"].tokenizePlaceholders(t,"handlebars")})),e.languages.hbs=e.languages.handlebars}(a),a.languages.json={property:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,lookbehind:!0,greedy:!0},comment:{pattern:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},number:/-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:"keyword"}},a.languages.webmanifest=a.languages.json,a.languages.less=a.languages.extend("css",{comment:[/\/\*[\s\S]*?\*\//,{pattern:/(^|[^\\])\/\/.*/,lookbehind:!0}],atrule:{pattern:/@[\w-](?:\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};\s]|\s+(?!\s))*?(?=\s*\{)/,inside:{punctuation:/[:()]/}},selector:{pattern:/(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};@\s]|\s+(?!\s))*?(?=\s*\{)/,inside:{variable:/@+[\w-]+/}},property:/(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/,operator:/[+\-*\/]/}),a.languages.insertBefore("less","property",{variable:[{pattern:/@[\w-]+\s*:/,inside:{punctuation:/:/}},/@@?[\w-]+/],"mixin-usage":{pattern:/([{;]\s*)[.#](?!\d)[\w-].*?(?=[(;])/,lookbehind:!0,alias:"function"}}),a.languages.makefile={comment:{pattern:/(^|[^\\])#(?:\\(?:\r\n|[\s\S])|[^\\\r\n])*/,lookbehind:!0},string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"builtin-target":{pattern:/\.[A-Z][^:#=\s]+(?=\s*:(?!=))/,alias:"builtin"},target:{pattern:/^(?:[^:=\s]|[ \t]+(?![\s:]))+(?=\s*:(?!=))/m,alias:"symbol",inside:{variable:/\$+(?:(?!\$)[^(){}:#=\s]+|(?=[({]))/}},variable:/\$+(?:(?!\$)[^(){}:#=\s]+|\([@*%<^+?][DF]\)|(?=[({]))/,keyword:/-include\b|\b(?:define|else|endef|endif|export|ifn?def|ifn?eq|include|override|private|sinclude|undefine|unexport|vpath)\b/,function:{pattern:/(\()(?:abspath|addsuffix|and|basename|call|dir|error|eval|file|filter(?:-out)?|findstring|firstword|flavor|foreach|guile|if|info|join|lastword|load|notdir|or|origin|patsubst|realpath|shell|sort|strip|subst|suffix|value|warning|wildcard|word(?:list|s)?)(?=[ \t])/,lookbehind:!0},operator:/(?:::|[?:+!])?=|[|@]/,punctuation:/[:;(){}]/},a.languages.objectivec=a.languages.extend("c",{string:{pattern:/@?"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},keyword:/\b(?:asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|in|inline|int|long|register|return|self|short|signed|sizeof|static|struct|super|switch|typedef|typeof|union|unsigned|void|volatile|while)\b|(?:@interface|@end|@implementation|@protocol|@class|@public|@protected|@private|@property|@try|@catch|@finally|@throw|@synthesize|@dynamic|@selector)\b/,operator:/-[->]?|\+\+?|!=?|<>?=?|==?|&&?|\|\|?|[~^%?*\/@]/}),delete a.languages.objectivec["class-name"],a.languages.objc=a.languages.objectivec,a.languages.ocaml={comment:{pattern:/\(\*[\s\S]*?\*\)/,greedy:!0},char:{pattern:/'(?:[^\\\r\n']|\\(?:.|[ox]?[0-9a-f]{1,3}))'/i,greedy:!0},string:[{pattern:/"(?:\\(?:[\s\S]|\r\n)|[^\\\r\n"])*"/,greedy:!0},{pattern:/\{([a-z_]*)\|[\s\S]*?\|\1\}/,greedy:!0}],number:[/\b(?:0b[01][01_]*|0o[0-7][0-7_]*)\b/i,/\b0x[a-f0-9][a-f0-9_]*(?:\.[a-f0-9_]*)?(?:p[+-]?\d[\d_]*)?(?!\w)/i,/\b\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?\d[\d_]*)?(?!\w)/i],directive:{pattern:/\B#\w+/,alias:"property"},label:{pattern:/\B~\w+/,alias:"property"},"type-variable":{pattern:/\B'\w+/,alias:"function"},variant:{pattern:/`\w+/,alias:"symbol"},keyword:/\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|nonrec|object|of|open|private|rec|sig|struct|then|to|try|type|val|value|virtual|when|where|while|with)\b/,boolean:/\b(?:false|true)\b/,"operator-like-punctuation":{pattern:/\[[<>|]|[>|]\]|\{<|>\}/,alias:"punctuation"},operator:/\.[.~]|:[=>]|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,punctuation:/;;|::|[(){}\[\].,:;#]|\b_\b/},a.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0,greedy:!0},"string-interpolation":{pattern:/(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,lookbehind:!0,inside:{"format-spec":{pattern:/(:)[^:(){}]+(?=\}$)/,lookbehind:!0},"conversion-option":{pattern:/![sra](?=[:}]$)/,alias:"punctuation"},rest:null}},string:/[\s\S]+/}},"triple-quoted-string":{pattern:/(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,greedy:!0,alias:"string"},string:{pattern:/(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,greedy:!0},function:{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)\w+/i,lookbehind:!0},decorator:{pattern:/(^[\t ]*)@\w+(?:\.\w+)*/m,lookbehind:!0,alias:["annotation","punctuation"],inside:{punctuation:/\./}},keyword:/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,builtin:/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,boolean:/\b(?:False|None|True)\b/,number:/\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,operator:/[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,punctuation:/[{}[\];(),.:]/},a.languages.python["string-interpolation"].inside.interpolation.inside.rest=a.languages.python,a.languages.py=a.languages.python,a.languages.reason=a.languages.extend("clike",{string:{pattern:/"(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/,greedy:!0},"class-name":/\b[A-Z]\w*/,keyword:/\b(?:and|as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|method|module|mutable|new|nonrec|object|of|open|or|private|rec|sig|struct|switch|then|to|try|type|val|virtual|when|while|with)\b/,operator:/\.{3}|:[:=]|\|>|->|=(?:==?|>)?|<=?|>=?|[|^?'#!~`]|[+\-*\/]\.?|\b(?:asr|land|lor|lsl|lsr|lxor|mod)\b/}),a.languages.insertBefore("reason","class-name",{char:{pattern:/'(?:\\x[\da-f]{2}|\\o[0-3][0-7][0-7]|\\\d{3}|\\.|[^'\\\r\n])'/,greedy:!0},constructor:/\b[A-Z]\w*\b(?!\s*\.)/,label:{pattern:/\b[a-z]\w*(?=::)/,alias:"symbol"}}),delete a.languages.reason.function,function(e){e.languages.sass=e.languages.extend("css",{comment:{pattern:/^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t].+)*/m,lookbehind:!0,greedy:!0}}),e.languages.insertBefore("sass","atrule",{"atrule-line":{pattern:/^(?:[ \t]*)[@+=].+/m,greedy:!0,inside:{atrule:/(?:@[\w-]+|[+=])/}}}),delete e.languages.sass.atrule;var t=/\$[-\w]+|#\{\$[-\w]+\}/,n=[/[+*\/%]|[=!]=|<=?|>=?|\b(?:and|not|or)\b/,{pattern:/(\s)-(?=\s)/,lookbehind:!0}];e.languages.insertBefore("sass","property",{"variable-line":{pattern:/^[ \t]*\$.+/m,greedy:!0,inside:{punctuation:/:/,variable:t,operator:n}},"property-line":{pattern:/^[ \t]*(?:[^:\s]+ *:.*|:[^:\s].*)/m,greedy:!0,inside:{property:[/[^:\s]+(?=\s*:)/,{pattern:/(:)[^:\s]+/,lookbehind:!0}],punctuation:/:/,variable:t,operator:n,important:e.languages.sass.important}}}),delete e.languages.sass.property,delete e.languages.sass.important,e.languages.insertBefore("sass","punctuation",{selector:{pattern:/^([ \t]*)\S(?:,[^,\r\n]+|[^,\r\n]*)(?:,[^,\r\n]+)*(?:,(?:\r?\n|\r)\1[ \t]+\S(?:,[^,\r\n]+|[^,\r\n]*)(?:,[^,\r\n]+)*)*/m,lookbehind:!0,greedy:!0}})}(a),a.languages.scss=a.languages.extend("css",{comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},atrule:{pattern:/@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,inside:{rule:/@[\w-]+/}},url:/(?:[-a-z]+-)?url(?=\()/i,selector:{pattern:/(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,inside:{parent:{pattern:/&/,alias:"important"},placeholder:/%[-\w]+/,variable:/\$[-\w]+|#\{\$[-\w]+\}/}},property:{pattern:/(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,inside:{variable:/\$[-\w]+|#\{\$[-\w]+\}/}}}),a.languages.insertBefore("scss","atrule",{keyword:[/@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,{pattern:/( )(?:from|through)(?= )/,lookbehind:!0}]}),a.languages.insertBefore("scss","important",{variable:/\$[-\w]+|#\{\$[-\w]+\}/}),a.languages.insertBefore("scss","function",{"module-modifier":{pattern:/\b(?:as|hide|show|with)\b/i,alias:"keyword"},placeholder:{pattern:/%[-\w]+/,alias:"selector"},statement:{pattern:/\B!(?:default|optional)\b/i,alias:"keyword"},boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:"keyword"},operator:{pattern:/(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,lookbehind:!0}}),a.languages.scss.atrule.inside.rest=a.languages.scss,function(e){var t={pattern:/(\b\d+)(?:%|[a-z]+)/,lookbehind:!0},n={pattern:/(^|[^\w.-])-?(?:\d+(?:\.\d+)?|\.\d+)/,lookbehind:!0},r={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},url:{pattern:/\burl\((["']?).*?\1\)/i,greedy:!0},string:{pattern:/("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,greedy:!0},interpolation:null,func:null,important:/\B!(?:important|optional)\b/i,keyword:{pattern:/(^|\s+)(?:(?:else|for|if|return|unless)(?=\s|$)|@[\w-]+)/,lookbehind:!0},hexcode:/#[\da-f]{3,6}/i,color:[/\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i,{pattern:/\b(?:hsl|rgb)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:hsl|rgb)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,inside:{unit:t,number:n,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:t,boolean:/\b(?:false|true)\b/,operator:[/~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.{2,3}|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/],number:n,punctuation:/[{}()\[\];:,]/};r.interpolation={pattern:/\{[^\r\n}:]+\}/,alias:"variable",inside:{delimiter:{pattern:/^\{|\}$/,alias:"punctuation"},rest:r}},r.func={pattern:/[\w-]+\([^)]*\).*/,inside:{function:/^[^(]+/,rest:r}},e.languages.stylus={"atrule-declaration":{pattern:/(^[ \t]*)@.+/m,lookbehind:!0,inside:{atrule:/^@[\w-]+/,rest:r}},"variable-declaration":{pattern:/(^[ \t]*)[\w$-]+\s*.?=[ \t]*(?:\{[^{}]*\}|\S.*|$)/m,lookbehind:!0,inside:{variable:/^\S+/,rest:r}},statement:{pattern:/(^[ \t]*)(?:else|for|if|return|unless)[ \t].+/m,lookbehind:!0,inside:{keyword:/^\S+/,rest:r}},"property-declaration":{pattern:/((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)(?!\s)[^{\r\n]*(?:;|[^{\r\n,]$(?!(?:\r?\n|\r)(?:\{|\2[ \t])))/m,lookbehind:!0,inside:{property:{pattern:/^[^\s:]+/,inside:{interpolation:r.interpolation}},rest:r}},selector:{pattern:/(^[ \t]*)(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\)|(?![\w-]))|\{[^}\r\n]+\})+)(?:(?:\r?\n|\r)(?:\1(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\)|(?![\w-]))|\{[^}\r\n]+\})+)))*(?:,$|\{|(?=(?:\r?\n|\r)(?:\{|\1[ \t])))/m,lookbehind:!0,inside:{interpolation:r.interpolation,comment:r.comment,punctuation:/[{},]/}},func:r.func,string:r.string,comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0,greedy:!0},interpolation:r.interpolation,punctuation:/[{}()\[\];:.]/}}(a),function(e){var t=e.util.clone(e.languages.typescript);e.languages.tsx=e.languages.extend("jsx",t),delete e.languages.tsx.parameter,delete e.languages.tsx["literal-property"];var n=e.languages.tsx.tag;n.pattern=RegExp(/(^|[^\w$]|(?=<\/))/.source+"(?:"+n.pattern.source+")",n.pattern.flags),n.lookbehind=!0}(a),a.languages.wasm={comment:[/\(;[\s\S]*?;\)/,{pattern:/;;.*/,greedy:!0}],string:{pattern:/"(?:\\[\s\S]|[^"\\])*"/,greedy:!0},keyword:[{pattern:/\b(?:align|offset)=/,inside:{operator:/=/}},{pattern:/\b(?:(?:f32|f64|i32|i64)(?:\.(?:abs|add|and|ceil|clz|const|convert_[su]\/i(?:32|64)|copysign|ctz|demote\/f64|div(?:_[su])?|eqz?|extend_[su]\/i32|floor|ge(?:_[su])?|gt(?:_[su])?|le(?:_[su])?|load(?:(?:8|16|32)_[su])?|lt(?:_[su])?|max|min|mul|neg?|nearest|or|popcnt|promote\/f32|reinterpret\/[fi](?:32|64)|rem_[su]|rot[lr]|shl|shr_[su]|sqrt|store(?:8|16|32)?|sub|trunc(?:_[su]\/f(?:32|64))?|wrap\/i64|xor))?|memory\.(?:grow|size))\b/,inside:{punctuation:/\./}},/\b(?:anyfunc|block|br(?:_if|_table)?|call(?:_indirect)?|data|drop|elem|else|end|export|func|get_(?:global|local)|global|if|import|local|loop|memory|module|mut|nop|offset|param|result|return|select|set_(?:global|local)|start|table|tee_local|then|type|unreachable)\b/],variable:/\$[\w!#$%&'*+\-./:<=>?@\\^`|~]+/,number:/[+-]?\b(?:\d(?:_?\d)*(?:\.\d(?:_?\d)*)?(?:[eE][+-]?\d(?:_?\d)*)?|0x[\da-fA-F](?:_?[\da-fA-F])*(?:\.[\da-fA-F](?:_?[\da-fA-D])*)?(?:[pP][+-]?\d(?:_?\d)*)?)\b|\binf\b|\bnan(?::0x[\da-fA-F](?:_?[\da-fA-D])*)?\b/,punctuation:/[()]/};const o=a},4225:()=>{Prism.languages.cmake={comment:/#.*/,string:{pattern:/"(?:[^\\"]|\\.)*"/,greedy:!0,inside:{interpolation:{pattern:/\$\{(?:[^{}$]|\$\{[^{}$]*\})*\}/,inside:{punctuation:/\$\{|\}/,variable:/\w+/}}}},variable:/\b(?:CMAKE_\w+|\w+_(?:(?:BINARY|SOURCE)_DIR|DESCRIPTION|HOMEPAGE_URL|ROOT|VERSION(?:_MAJOR|_MINOR|_PATCH|_TWEAK)?)|(?:ANDROID|APPLE|BORLAND|BUILD_SHARED_LIBS|CACHE|CPACK_(?:ABSOLUTE_DESTINATION_FILES|COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY|ERROR_ON_ABSOLUTE_INSTALL_DESTINATION|INCLUDE_TOPLEVEL_DIRECTORY|INSTALL_DEFAULT_DIRECTORY_PERMISSIONS|INSTALL_SCRIPT|PACKAGING_INSTALL_PREFIX|SET_DESTDIR|WARN_ON_ABSOLUTE_INSTALL_DESTINATION)|CTEST_(?:BINARY_DIRECTORY|BUILD_COMMAND|BUILD_NAME|BZR_COMMAND|BZR_UPDATE_OPTIONS|CHANGE_ID|CHECKOUT_COMMAND|CONFIGURATION_TYPE|CONFIGURE_COMMAND|COVERAGE_COMMAND|COVERAGE_EXTRA_FLAGS|CURL_OPTIONS|CUSTOM_(?:COVERAGE_EXCLUDE|ERROR_EXCEPTION|ERROR_MATCH|ERROR_POST_CONTEXT|ERROR_PRE_CONTEXT|MAXIMUM_FAILED_TEST_OUTPUT_SIZE|MAXIMUM_NUMBER_OF_(?:ERRORS|WARNINGS)|MAXIMUM_PASSED_TEST_OUTPUT_SIZE|MEMCHECK_IGNORE|POST_MEMCHECK|POST_TEST|PRE_MEMCHECK|PRE_TEST|TESTS_IGNORE|WARNING_EXCEPTION|WARNING_MATCH)|CVS_CHECKOUT|CVS_COMMAND|CVS_UPDATE_OPTIONS|DROP_LOCATION|DROP_METHOD|DROP_SITE|DROP_SITE_CDASH|DROP_SITE_PASSWORD|DROP_SITE_USER|EXTRA_COVERAGE_GLOB|GIT_COMMAND|GIT_INIT_SUBMODULES|GIT_UPDATE_CUSTOM|GIT_UPDATE_OPTIONS|HG_COMMAND|HG_UPDATE_OPTIONS|LABELS_FOR_SUBPROJECTS|MEMORYCHECK_(?:COMMAND|COMMAND_OPTIONS|SANITIZER_OPTIONS|SUPPRESSIONS_FILE|TYPE)|NIGHTLY_START_TIME|P4_CLIENT|P4_COMMAND|P4_OPTIONS|P4_UPDATE_OPTIONS|RUN_CURRENT_SCRIPT|SCP_COMMAND|SITE|SOURCE_DIRECTORY|SUBMIT_URL|SVN_COMMAND|SVN_OPTIONS|SVN_UPDATE_OPTIONS|TEST_LOAD|TEST_TIMEOUT|TRIGGER_SITE|UPDATE_COMMAND|UPDATE_OPTIONS|UPDATE_VERSION_ONLY|USE_LAUNCHERS)|CYGWIN|ENV|EXECUTABLE_OUTPUT_PATH|GHS-MULTI|IOS|LIBRARY_OUTPUT_PATH|MINGW|MSVC(?:10|11|12|14|60|70|71|80|90|_IDE|_TOOLSET_VERSION|_VERSION)?|MSYS|PROJECT_NAME|UNIX|WIN32|WINCE|WINDOWS_PHONE|WINDOWS_STORE|XCODE))\b/,property:/\b(?:cxx_\w+|(?:ARCHIVE_OUTPUT_(?:DIRECTORY|NAME)|COMPILE_DEFINITIONS|COMPILE_PDB_NAME|COMPILE_PDB_OUTPUT_DIRECTORY|EXCLUDE_FROM_DEFAULT_BUILD|IMPORTED_(?:IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_LANGUAGES|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|NO_SONAME|OBJECTS|SONAME)|INTERPROCEDURAL_OPTIMIZATION|LIBRARY_OUTPUT_DIRECTORY|LIBRARY_OUTPUT_NAME|LINK_FLAGS|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|MAP_IMPORTED_CONFIG|OSX_ARCHITECTURES|OUTPUT_NAME|PDB_NAME|PDB_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_NAME|STATIC_LIBRARY_FLAGS|VS_CSHARP|VS_DOTNET_REFERENCEPROP|VS_DOTNET_REFERENCE|VS_GLOBAL_SECTION_POST|VS_GLOBAL_SECTION_PRE|VS_GLOBAL|XCODE_ATTRIBUTE)_\w+|\w+_(?:CLANG_TIDY|COMPILER_LAUNCHER|CPPCHECK|CPPLINT|INCLUDE_WHAT_YOU_USE|OUTPUT_NAME|POSTFIX|VISIBILITY_PRESET)|ABSTRACT|ADDITIONAL_MAKE_CLEAN_FILES|ADVANCED|ALIASED_TARGET|ALLOW_DUPLICATE_CUSTOM_TARGETS|ANDROID_(?:ANT_ADDITIONAL_OPTIONS|API|API_MIN|ARCH|ASSETS_DIRECTORIES|GUI|JAR_DEPENDENCIES|NATIVE_LIB_DEPENDENCIES|NATIVE_LIB_DIRECTORIES|PROCESS_MAX|PROGUARD|PROGUARD_CONFIG_PATH|SECURE_PROPS_PATH|SKIP_ANT_STEP|STL_TYPE)|ARCHIVE_OUTPUT_DIRECTORY|ATTACHED_FILES|ATTACHED_FILES_ON_FAIL|AUTOGEN_(?:BUILD_DIR|ORIGIN_DEPENDS|PARALLEL|SOURCE_GROUP|TARGETS_FOLDER|TARGET_DEPENDS)|AUTOMOC|AUTOMOC_(?:COMPILER_PREDEFINES|DEPEND_FILTERS|EXECUTABLE|MACRO_NAMES|MOC_OPTIONS|SOURCE_GROUP|TARGETS_FOLDER)|AUTORCC|AUTORCC_EXECUTABLE|AUTORCC_OPTIONS|AUTORCC_SOURCE_GROUP|AUTOUIC|AUTOUIC_EXECUTABLE|AUTOUIC_OPTIONS|AUTOUIC_SEARCH_PATHS|BINARY_DIR|BUILDSYSTEM_TARGETS|BUILD_RPATH|BUILD_RPATH_USE_ORIGIN|BUILD_WITH_INSTALL_NAME_DIR|BUILD_WITH_INSTALL_RPATH|BUNDLE|BUNDLE_EXTENSION|CACHE_VARIABLES|CLEAN_NO_CUSTOM|COMMON_LANGUAGE_RUNTIME|COMPATIBLE_INTERFACE_(?:BOOL|NUMBER_MAX|NUMBER_MIN|STRING)|COMPILE_(?:DEFINITIONS|FEATURES|FLAGS|OPTIONS|PDB_NAME|PDB_OUTPUT_DIRECTORY)|COST|CPACK_DESKTOP_SHORTCUTS|CPACK_NEVER_OVERWRITE|CPACK_PERMANENT|CPACK_STARTUP_SHORTCUTS|CPACK_START_MENU_SHORTCUTS|CPACK_WIX_ACL|CROSSCOMPILING_EMULATOR|CUDA_EXTENSIONS|CUDA_PTX_COMPILATION|CUDA_RESOLVE_DEVICE_SYMBOLS|CUDA_SEPARABLE_COMPILATION|CUDA_STANDARD|CUDA_STANDARD_REQUIRED|CXX_EXTENSIONS|CXX_STANDARD|CXX_STANDARD_REQUIRED|C_EXTENSIONS|C_STANDARD|C_STANDARD_REQUIRED|DEBUG_CONFIGURATIONS|DEFINE_SYMBOL|DEFINITIONS|DEPENDS|DEPLOYMENT_ADDITIONAL_FILES|DEPLOYMENT_REMOTE_DIRECTORY|DISABLED|DISABLED_FEATURES|ECLIPSE_EXTRA_CPROJECT_CONTENTS|ECLIPSE_EXTRA_NATURES|ENABLED_FEATURES|ENABLED_LANGUAGES|ENABLE_EXPORTS|ENVIRONMENT|EXCLUDE_FROM_ALL|EXCLUDE_FROM_DEFAULT_BUILD|EXPORT_NAME|EXPORT_PROPERTIES|EXTERNAL_OBJECT|EchoString|FAIL_REGULAR_EXPRESSION|FIND_LIBRARY_USE_LIB32_PATHS|FIND_LIBRARY_USE_LIB64_PATHS|FIND_LIBRARY_USE_LIBX32_PATHS|FIND_LIBRARY_USE_OPENBSD_VERSIONING|FIXTURES_CLEANUP|FIXTURES_REQUIRED|FIXTURES_SETUP|FOLDER|FRAMEWORK|Fortran_FORMAT|Fortran_MODULE_DIRECTORY|GENERATED|GENERATOR_FILE_NAME|GENERATOR_IS_MULTI_CONFIG|GHS_INTEGRITY_APP|GHS_NO_SOURCE_GROUP_FILE|GLOBAL_DEPENDS_DEBUG_MODE|GLOBAL_DEPENDS_NO_CYCLES|GNUtoMS|HAS_CXX|HEADER_FILE_ONLY|HELPSTRING|IMPLICIT_DEPENDS_INCLUDE_TRANSFORM|IMPORTED|IMPORTED_(?:COMMON_LANGUAGE_RUNTIME|CONFIGURATIONS|GLOBAL|IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_(?:LANGUAGES|LIBRARIES|MULTIPLICITY)|LOCATION|NO_SONAME|OBJECTS|SONAME)|IMPORT_PREFIX|IMPORT_SUFFIX|INCLUDE_DIRECTORIES|INCLUDE_REGULAR_EXPRESSION|INSTALL_NAME_DIR|INSTALL_RPATH|INSTALL_RPATH_USE_LINK_PATH|INTERFACE_(?:AUTOUIC_OPTIONS|COMPILE_DEFINITIONS|COMPILE_FEATURES|COMPILE_OPTIONS|INCLUDE_DIRECTORIES|LINK_DEPENDS|LINK_DIRECTORIES|LINK_LIBRARIES|LINK_OPTIONS|POSITION_INDEPENDENT_CODE|SOURCES|SYSTEM_INCLUDE_DIRECTORIES)|INTERPROCEDURAL_OPTIMIZATION|IN_TRY_COMPILE|IOS_INSTALL_COMBINED|JOB_POOLS|JOB_POOL_COMPILE|JOB_POOL_LINK|KEEP_EXTENSION|LABELS|LANGUAGE|LIBRARY_OUTPUT_DIRECTORY|LINKER_LANGUAGE|LINK_(?:DEPENDS|DEPENDS_NO_SHARED|DIRECTORIES|FLAGS|INTERFACE_LIBRARIES|INTERFACE_MULTIPLICITY|LIBRARIES|OPTIONS|SEARCH_END_STATIC|SEARCH_START_STATIC|WHAT_YOU_USE)|LISTFILE_STACK|LOCATION|MACOSX_BUNDLE|MACOSX_BUNDLE_INFO_PLIST|MACOSX_FRAMEWORK_INFO_PLIST|MACOSX_PACKAGE_LOCATION|MACOSX_RPATH|MACROS|MANUALLY_ADDED_DEPENDENCIES|MEASUREMENT|MODIFIED|NAME|NO_SONAME|NO_SYSTEM_FROM_IMPORTED|OBJECT_DEPENDS|OBJECT_OUTPUTS|OSX_ARCHITECTURES|OUTPUT_NAME|PACKAGES_FOUND|PACKAGES_NOT_FOUND|PARENT_DIRECTORY|PASS_REGULAR_EXPRESSION|PDB_NAME|PDB_OUTPUT_DIRECTORY|POSITION_INDEPENDENT_CODE|POST_INSTALL_SCRIPT|PREDEFINED_TARGETS_FOLDER|PREFIX|PRE_INSTALL_SCRIPT|PRIVATE_HEADER|PROCESSORS|PROCESSOR_AFFINITY|PROJECT_LABEL|PUBLIC_HEADER|REPORT_UNDEFINED_PROPERTIES|REQUIRED_FILES|RESOURCE|RESOURCE_LOCK|RULE_LAUNCH_COMPILE|RULE_LAUNCH_CUSTOM|RULE_LAUNCH_LINK|RULE_MESSAGES|RUNTIME_OUTPUT_DIRECTORY|RUN_SERIAL|SKIP_AUTOGEN|SKIP_AUTOMOC|SKIP_AUTORCC|SKIP_AUTOUIC|SKIP_BUILD_RPATH|SKIP_RETURN_CODE|SOURCES|SOURCE_DIR|SOVERSION|STATIC_LIBRARY_FLAGS|STATIC_LIBRARY_OPTIONS|STRINGS|SUBDIRECTORIES|SUFFIX|SYMBOLIC|TARGET_ARCHIVES_MAY_BE_SHARED_LIBS|TARGET_MESSAGES|TARGET_SUPPORTS_SHARED_LIBS|TESTS|TEST_INCLUDE_FILE|TEST_INCLUDE_FILES|TIMEOUT|TIMEOUT_AFTER_MATCH|TYPE|USE_FOLDERS|VALUE|VARIABLES|VERSION|VISIBILITY_INLINES_HIDDEN|VS_(?:CONFIGURATION_TYPE|COPY_TO_OUT_DIR|DEBUGGER_(?:COMMAND|COMMAND_ARGUMENTS|ENVIRONMENT|WORKING_DIRECTORY)|DEPLOYMENT_CONTENT|DEPLOYMENT_LOCATION|DOTNET_REFERENCES|DOTNET_REFERENCES_COPY_LOCAL|INCLUDE_IN_VSIX|IOT_STARTUP_TASK|KEYWORD|RESOURCE_GENERATOR|SCC_AUXPATH|SCC_LOCALPATH|SCC_PROJECTNAME|SCC_PROVIDER|SDK_REFERENCES|SHADER_(?:DISABLE_OPTIMIZATIONS|ENABLE_DEBUG|ENTRYPOINT|FLAGS|MODEL|OBJECT_FILE_NAME|OUTPUT_HEADER_FILE|TYPE|VARIABLE_NAME)|STARTUP_PROJECT|TOOL_OVERRIDE|USER_PROPS|WINRT_COMPONENT|WINRT_EXTENSIONS|WINRT_REFERENCES|XAML_TYPE)|WILL_FAIL|WIN32_EXECUTABLE|WINDOWS_EXPORT_ALL_SYMBOLS|WORKING_DIRECTORY|WRAP_EXCLUDE|XCODE_(?:EMIT_EFFECTIVE_PLATFORM_NAME|EXPLICIT_FILE_TYPE|FILE_ATTRIBUTES|LAST_KNOWN_FILE_TYPE|PRODUCT_TYPE|SCHEME_(?:ADDRESS_SANITIZER|ADDRESS_SANITIZER_USE_AFTER_RETURN|ARGUMENTS|DISABLE_MAIN_THREAD_CHECKER|DYNAMIC_LIBRARY_LOADS|DYNAMIC_LINKER_API_USAGE|ENVIRONMENT|EXECUTABLE|GUARD_MALLOC|MAIN_THREAD_CHECKER_STOP|MALLOC_GUARD_EDGES|MALLOC_SCRIBBLE|MALLOC_STACK|THREAD_SANITIZER(?:_STOP)?|UNDEFINED_BEHAVIOUR_SANITIZER(?:_STOP)?|ZOMBIE_OBJECTS))|XCTEST)\b/,keyword:/\b(?:add_compile_definitions|add_compile_options|add_custom_command|add_custom_target|add_definitions|add_dependencies|add_executable|add_library|add_link_options|add_subdirectory|add_test|aux_source_directory|break|build_command|build_name|cmake_host_system_information|cmake_minimum_required|cmake_parse_arguments|cmake_policy|configure_file|continue|create_test_sourcelist|ctest_build|ctest_configure|ctest_coverage|ctest_empty_binary_directory|ctest_memcheck|ctest_read_custom_files|ctest_run_script|ctest_sleep|ctest_start|ctest_submit|ctest_test|ctest_update|ctest_upload|define_property|else|elseif|enable_language|enable_testing|endforeach|endfunction|endif|endmacro|endwhile|exec_program|execute_process|export|export_library_dependencies|file|find_file|find_library|find_package|find_path|find_program|fltk_wrap_ui|foreach|function|get_cmake_property|get_directory_property|get_filename_component|get_property|get_source_file_property|get_target_property|get_test_property|if|include|include_directories|include_external_msproject|include_guard|include_regular_expression|install|install_files|install_programs|install_targets|link_directories|link_libraries|list|load_cache|load_command|macro|make_directory|mark_as_advanced|math|message|option|output_required_files|project|qt_wrap_cpp|qt_wrap_ui|remove|remove_definitions|return|separate_arguments|set|set_directory_properties|set_property|set_source_files_properties|set_target_properties|set_tests_properties|site_name|source_group|string|subdir_depends|subdirs|target_compile_definitions|target_compile_features|target_compile_options|target_include_directories|target_link_directories|target_link_libraries|target_link_options|target_sources|try_compile|try_run|unset|use_mangled_mesa|utility_source|variable_requires|variable_watch|while|write_file)(?=\s*\()\b/,boolean:/\b(?:FALSE|OFF|ON|TRUE)\b/,namespace:/\b(?:INTERFACE|PRIVATE|PROPERTIES|PUBLIC|SHARED|STATIC|TARGET_OBJECTS)\b/,operator:/\b(?:AND|DEFINED|EQUAL|GREATER|LESS|MATCHES|NOT|OR|STREQUAL|STRGREATER|STRLESS|VERSION_EQUAL|VERSION_GREATER|VERSION_LESS)\b/,inserted:{pattern:/\b\w+::\w+\b/,alias:"class-name"},number:/\b\d+(?:\.\d+)*\b/,function:/\b[a-z_]\w*(?=\s*\()\b/i,punctuation:/[()>}]|\$[<{]/}},6862:()=>{!function(e){var t=e.languages.powershell={comment:[{pattern:/(^|[^`])<#[\s\S]*?#>/,lookbehind:!0},{pattern:/(^|[^`])#.*/,lookbehind:!0}],string:[{pattern:/"(?:`[\s\S]|[^`"])*"/,greedy:!0,inside:null},{pattern:/'(?:[^']|'')*'/,greedy:!0}],namespace:/\[[a-z](?:\[(?:\[[^\]]*\]|[^\[\]])*\]|[^\[\]])*\]/i,boolean:/\$(?:false|true)\b/i,variable:/\$\w+\b/,function:[/\b(?:Add|Approve|Assert|Backup|Block|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|ForEach|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Sort|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Tee|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Where|Write)-[a-z]+\b/i,/\b(?:ac|cat|chdir|clc|cli|clp|clv|compare|copy|cp|cpi|cpp|cvpa|dbp|del|diff|dir|ebp|echo|epal|epcsv|epsn|erase|fc|fl|ft|fw|gal|gbp|gc|gci|gcs|gdr|gi|gl|gm|gp|gps|group|gsv|gu|gv|gwmi|iex|ii|ipal|ipcsv|ipsn|irm|iwmi|iwr|kill|lp|ls|measure|mi|mount|move|mp|mv|nal|ndr|ni|nv|ogv|popd|ps|pushd|pwd|rbp|rd|rdr|ren|ri|rm|rmdir|rni|rnp|rp|rv|rvpa|rwmi|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls|sort|sp|spps|spsv|start|sv|swmi|tee|trcm|type|write)\b/i],keyword:/\b(?:Begin|Break|Catch|Class|Continue|Data|Define|Do|DynamicParam|Else|ElseIf|End|Exit|Filter|Finally|For|ForEach|From|Function|If|InlineScript|Parallel|Param|Process|Return|Sequence|Switch|Throw|Trap|Try|Until|Using|Var|While|Workflow)\b/i,operator:{pattern:/(^|\W)(?:!|-(?:b?(?:and|x?or)|as|(?:Not)?(?:Contains|In|Like|Match)|eq|ge|gt|is(?:Not)?|Join|le|lt|ne|not|Replace|sh[lr])\b|-[-=]?|\+[+=]?|[*\/%]=?)/i,lookbehind:!0},punctuation:/[|{}[\];(),.]/};t.string[0].inside={function:{pattern:/(^|[^`])\$\((?:\$\([^\r\n()]*\)|(?!\$\()[^\r\n)])*\)/,lookbehind:!0,inside:t},boolean:t.boolean,variable:t.variable}}(Prism)},2295:(e,t,n)=>{var r={"./prism-cmake":4225,"./prism-powershell":6862};function a(e){var t=o(e);return n(t)}function o(e){if(!n.o(r,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return r[e]}a.keys=function(){return Object.keys(r)},a.resolve=o,e.exports=a,a.id=2295},2703:(e,t,n)=>{"use strict";var r=n(414);function a(){}function o(){}o.resetWarningCache=a,e.exports=function(){function e(e,t,n,a,o,i){if(i!==r){var l=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw l.name="Invariant Violation",l}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:o,resetWarningCache:a};return n.PropTypes=n,n}},5697:(e,t,n)=>{e.exports=n(2703)()},414:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},4448:(e,t,n)=>{"use strict";var r=n(7294),a=n(7418),o=n(3840);function i(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n