text: (window.webpackJsonp=window.webpackJsonp||[]).push([[324],{696:function(e,t,r){"use strict";r.r(t);var a=r(42),o=Object(a.a)({},(function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[r("h1",{attrs:{id:"postgresql-example"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#postgresql-example"}},[e._v("#")]),e._v(" PostgreSQL Example "),r("seo")],1),e._v(" "),r("p",[r("a",{attrs:{href:"https://github.com/oatpp/example-postgresql",target:"_blank",rel:"noopener noreferrer"}},[e._v("Github Repository"),r("OutboundLink")],1)]),e._v(" "),r("p",[e._v('A complete example of a "CRUD" service (UserService) built with Oat++ and using oatpp ORM with PostgreSQL.')]),e._v(" "),r("p",[e._v("In this example:")]),e._v(" "),r("ul",[r("li",[e._v("How to create CRUD endpoints.")]),e._v(" "),r("li",[e._v("How to use "),r("RouterLink",{attrs:{to:"/docs/components/orm/"}},[e._v("oatpp ORM")]),e._v(" - PostgreSQL example.")],1),e._v(" "),r("li",[e._v("How to document API with Swagger-UI and OpenApi 3.0.0.")])]),e._v(" "),r("h2",{attrs:{id:"overview"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#overview"}},[e._v("#")]),e._v(" Overview")]),e._v(" "),r("p",[e._v("This project is using the following oatpp modules:")]),e._v(" "),r("ul",[r("li",[r("a",{attrs:{href:"https://github.com/oatpp/oatpp",target:"_blank",rel:"noopener noreferrer"}},[e._v("oatpp"),r("OutboundLink")],1)]),e._v(" "),r("li",[r("a",{attrs:{href:"https://github.com/oatpp/oatpp-swagger",target:"_blank",rel:"noopener noreferrer"}},[e._v("oatpp-swagger"),r("OutboundLink")],1)]),e._v(" "),r("li",[r("a",{attrs:{href:"https://github.com/oatpp/oatpp-postgresql",target:"_blank",rel:"noopener noreferrer"}},[e._v("oatpp-postgresql"),r("OutboundLink")],1)])]),e._v(" "),r("h3",{attrs:{id:"project-layout"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#project-layout"}},[e._v("#")]),e._v(" Project layout")]),e._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[e._v("|- CMakeLists.txt                        // projects CMakeLists.txt\n|- src/\n|    |\n|    |- controller/                      // Folder containing Controller where all endpoints are declared\n|    |- db/                              // Folder containing the database client\n|    |- dto/                             // DTOs are declared here\n|    |- service/                         // Service business logic classes (UserService)\n|    |- ServiceComponent.hpp             // Service configuration (port, ObjectMapper, Database)\n|    |- SwaggerComponent.hpp             // Configuration for swagger-ui\n|    |- AppComponent.hpp                 // Service configuration is loaded here\n|    |- DatabaseComponent.hpp            // Database config\n|    |- App.cpp                          // main() is here\n|    \n|- test/                                 // test folder\n|- utility/install-oatpp-modules.sh      // utility script to install required oatpp-modules.\n|- resources/config.json                 // configuration file with configuration profiles\n|- Dockerfile                            // Dockerfile\n|- docker-compose.yaml                   // Docker-compose with this service and postgresql\n")])])]),r("hr"),e._v(" "),r("h2",{attrs:{id:"build-and-run"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#build-and-run"}},[e._v("#")]),e._v(" Build and Run")]),e._v(" "),r("h3",{attrs:{id:"using-cmake"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#using-cmake"}},[e._v("#")]),e._v(" Using CMake")]),e._v(" "),r("p",[r("strong",[e._v("Requires")])]),e._v(" "),r("ul",[r("li",[r("p",[e._v("This example also requires the PostgreSQL package installed.")]),e._v(" "),r("ul",[r("li",[e._v("On Alpine "),r("code",[e._v("$ apk add postgresql-dev")])]),e._v(" "),r("li",[e._v("On Ubuntu "),r("code",[e._v("$ apt-get install postgresql-server-dev-all")])])]),e._v(" "),r("p",[e._v("For more info see "),r("a",{attrs:{href:"https://github.com/oatpp/oatpp-postgresql/blob/master/README.md",target:"_blank",rel:"noopener noreferrer"}},[e._v("oatpp-postgresql/README.md"),r("OutboundLink")],1)])]),e._v(" "),r("li",[r("p",[r("code",[e._v("oatpp")]),e._v(", "),r("code",[e._v("oatpp-swagger")]),e._v(" and "),r("code",[e._v("oatpp-postgresql")]),e._v(" modules installed. You may run "),r("code",[e._v("utility/install-oatpp-modules.sh")]),e._v("\nscript to install required oatpp modules.")])])]),e._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[e._v("$ mkdir build && cd build\n$ cmake ..\n$ make \n$ ./example-postgresql-exe  # - run application.\n")])])]),r("p",[r("em",[e._v("PostgreSQL is expected running as for "),r("code",[e._v("dev")]),e._v(" config profile")])]),e._v(" "),r("h3",{attrs:{id:"in-docker"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#in-docker"}},[e._v("#")]),e._v(" In Docker")]),e._v(" "),r("h4",{attrs:{id:"dockerfile"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#dockerfile"}},[e._v("#")]),e._v(" Dockerfile")]),e._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[e._v("$ docker build -t example-postgresql .\n$ docker run -p 8000:8000 -e CONFIG_PROFILE='dev' -t example-postgresql\n")])])]),r("h4",{attrs:{id:"docker-compose"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#docker-compose"}},[e._v("#")]),e._v(" docker-compose")]),e._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[e._v("$ docker-compose up\n")])])]),r("p",[r("em",[e._v("docker-compose will run service with "),r("code",[e._v("local-docker")]),e._v(" config profile")])]),e._v(" "),r("h3",{attrs:{id:"after-run"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#after-run"}},[e._v("#")]),e._v(" After run")]),e._v(" "),r("p",[e._v("Go to "),r("a",{attrs:{href:"http://localhost:8000/swagger/ui",target:"_blank",rel:"noopener noreferrer"}},[e._v("http://localhost:8000/swagger/ui"),r("OutboundLink")],1),e._v(" to try endpoints.")])])}),[],!1,null,null,null);t.default=o.exports}}]);