Coder Social home page Coder Social logo

ezhangle / example-postgresql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oatpp/example-postgresql

0.0 2.0 0.0 30 KB

Example of a production grade entity service with Swagger-UI and configuration profiles. Storing information in PostgreSQL.

Home Page: https://oatpp.io/

License: Apache License 2.0

CMake 11.21% Dockerfile 0.56% C++ 88.23%

example-postgresql's Introduction

example-postgresql Build Status

Example of a production grade entity service storing information in PostgreSQL. With Swagger-UI and configuration profiles.
Libpq is used to communicate with PostgreSQL database.
Dockerfile and docker-compose.yaml files included.

More about oat++:

Overview

This project is using oatpp and oatpp-swagger modules.

Project layout


|- CMakeLists.txt               // project loader script. load and build dependencies 
|- main/                        // main project directory
|    |
|    |- CMakeLists.txt          // project's CMakeLists.txt
|    |- src/                    // source folder
|    |- test/                   // test folder
|    |- resources/
|         |
|         |- config.json        // configuration file with configuration profiles
|
|- Dockerfile                   // Dockerfile
|- docker-compose.yaml          // Docker-compose with this service and postgresql

- src/
    |
    |- controller/              // Folder containing Controller where all endpoints are declared
    |- db/                      // Database class is here 
    |- dto/                     // DTOs are declared here
    |- ServiceComponent.hpp     // Service configuration (port, ObjectMapper, Database)
    |- SwaggerComponent.hpp     // Configuration for swagger-ui
    |- AppComponent.hpp         // Service configuration is loaded here
    |- Logger.hpp               // Application Logger
    |- App.cpp                  // main() is here
    

Build and Run

Using CMake

Requires libpq installed. To install libpq:

$ mkdir build && cd build
$ cmake ..
$ make run        ## Download, build, and install all dependencies. Run project

PostgreSQL is expected running as for dev config profile

In Docker

Dockerfile

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

docker-compose

$ 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.

Install PostgreSQL Client From Sources

  • Download sources from https://www.postgresql.org/ftp/source/

    $ wget https://ftp.postgresql.org/pub/source/v11.1/postgresql-11.1.tar.gz
    
  • Untar

    $ tar -xvzf postgresql-11.1.tar.gz
    
  • CD to postgresql-11.1, configure, make:

    $ cd postgresql-11.1
    $ ./configure
    $ make
    
  • Install PostgreSQL client-only
    For this particular example we don't need full PostgreSQL installation.

    $ make -C src/include install 
    $ make -C src/interfaces install
    

For more information see PostgreSQL installation guide

example-postgresql's People

Contributors

lganzzzo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.