项目作者: oatpp

项目描述 :
A complete example of a "CRUD" service (UserService) built with Oat++ and using oatpp ORM with PostgreSQL.
高级语言: C++
项目地址: git://github.com/oatpp/example-postgresql.git
创建时间: 2019-02-13T10:28:08Z
项目社区:https://github.com/oatpp/example-postgresql

开源协议:Apache License 2.0

下载


example-postgresql Build Status

A complete example of a “CRUD” service (UserService) built with Oat++ and using oatpp ORM with PostgreSQL.

In this example:

  • How to create CRUD endpoints.
  • How to use oatpp ORM - PostgreSQL example.
  • How to document API with Swagger-UI and OpenApi 3.0.0.

More about Oat++:

Overview

This project is using the following oatpp modules:

Project layout

  1. |- CMakeLists.txt // projects CMakeLists.txt
  2. |- src/
  3. | |
  4. | |- controller/ // Folder containing Controller where all endpoints are declared
  5. | |- db/ // Folder containing the database client
  6. | |- dto/ // DTOs are declared here
  7. | |- service/ // Service business logic classes (UserService)
  8. | |- ServiceComponent.hpp // Service configuration (port, ObjectMapper, Database)
  9. | |- SwaggerComponent.hpp // Configuration for swagger-ui
  10. | |- AppComponent.hpp // Service configuration is loaded here
  11. | |- DatabaseComponent.hpp // Database config
  12. | |- App.cpp // main() is here
  13. |
  14. |- test/ // test folder
  15. |- utility/install-oatpp-modules.sh // utility script to install required oatpp-modules.
  16. |- resources/config.json // configuration file with configuration profiles
  17. |- Dockerfile // Dockerfile
  18. |- docker-compose.yaml // Docker-compose with this service and postgresql

Build and Run

Using CMake

Requires

  • This example also requires the PostgreSQL package installed.

    • On Alpine $ apk add postgresql-dev
    • On Ubuntu $ apt-get install postgresql-server-dev-all

      For more info see oatpp-postgresql/README.md

  • oatpp, oatpp-swagger and oatpp-postgresql modules installed. You may run utility/install-oatpp-modules.sh
    script to install required oatpp modules.
  1. $ mkdir build && cd build
  2. $ cmake ..
  3. $ make
  4. $ ./example-postgresql-exe # - run application.

PostgreSQL is expected running as for dev config profile

In Docker

Dockerfile

  1. $ docker build -t example-postgresql .
  2. $ docker run -p 8000:8000 -e CONFIG_PROFILE='dev' -t example-postgresql

docker-compose

  1. $ docker-compose up

docker-compose will run service with local-docker config profile

After run

Go to http://localhost:8000/swagger/ui to try endpoints.