Coder Social home page Coder Social logo

soci-wrapper's Introduction

Work In Progress

Contents

Synopsis

The yet another ORM library built on top of SOCI whithin the idea to give a simple interface by implementing a DSL for C++ for working with SQL databases.

Features

  • Mapping C++ data structure onto DB structures
  • Creation and deletion of tables by using the predefined structs in C++
  • Querying and insertion (by one entity) data from tables and map the results onto C++ data struct

Dependencies

  • SOCI lib. as a submodule
  • Boost Libraries >= 1.70.0 as sys. dependency
    • Boost Preprocessor
    • Boost Proto
  • gcov, lcov, genhtml, doxygen are optional and serve the documentation/coverage purposes

Here is the high-level design:

Building

soci-wrapper is a header-only. To use it just add the necessary #include line to your source code, such as the following:

#include "soci-wrapper.hpp"

How To build container and execute tests

There is a script added to serve the purpose. The run.sh script is located in the root folder of the project. The following options are availavle:

  • clear - cleans the build directory
  • compile_container - compiles the docker container w/ the tag soci_wrapper
  • compile_debug - compiles the library in Debug mode with the tests

For the full chain execution from the scratch just invoke the following command:

./run.sh --clear --compile_container --compile_debug 

Usage: run.sh [options]

Options:
    --clear                          Clear build dir
    --compile_container              Compile the docker container
    --compile_debug                  Compile in debug mode w/ tests

How To include into cmake

Adding the library as a submodule

git submodule add https://github.com/osydunenko/soci-wrapper.git 3rdParty/soci-wrapper

Then add a connetion to the library as a subdirectory into your CMakeLists.txt

add_subdirectory(3rdParty/soci-wrapper)

And finally link to the target-executable

target_link_libraries(
    ...
    PRIVATE
        ...
        soci_wrapper::soci_wrapper
        ...
)

How To make doxygen

For the api docu generation you need to execute a target by using your generator passed to cmake.

The target is "excluded from all" (requires a standalone execution) and is called as doc

The following command shows the docu generation as a reference:

make doc

As a result, you may find the dir doc created in the ${CMAKE_CURRENT_SOURCE_DIR} and listed the docu.

How To generate the code coverage report

For this purposes you need to have installed some binaries of lvoc, gcov and genhtml

The following dependencies are taken from the CMakeLists.txt as a reference

find_program(GCOV_PATH gcov)
find_program(LCOV_PATH lcov)
find_program(GENHTML_PATH genhtml)

So, to have the coverage results use the following set of commands

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DSW_BUILD_TESTS=ON -DSW_CPPTEST_COVERAGE=ON ../
make -j 4
make test
make coverage

As a result, you may find the dir coverage created in the ${CMAKE_CURRENT_SOURCE_DIR} and listed the coverage report.

Usage

More examples are available as UTs and located here...

C++ structure definition and declare the struct as a persisted type

#include "soci-wrapper.hpp"

namespace sw = soci_wrapper;

struct person
{
    int id;
    std::string name;
    std::string surname;

    bool operator==(const person &rhs) const
    {
        return id == rhs.id &&
            name == rhs.name &&
            surname == rhs.surname;
    }
};

DECLARE_PERSISTENT_OBJECT(person,
    id,
    name,
    surname
);

Make a connection to the Database.

You may also use a session pool insted of a dedicated connection. Please see here... as a reference.

session = sw::session::connect("tst_object.db");

Create a table as it was specified and declared as a persisted object

sw::ddl<person>::create_table(*session);

Insertion-Querying into DB and map the data then to C++ structure

person prsn {
    .id = 20,
    .name = "name 20",
    .surname = "surname 20"
};

sw::dml::persist(*session, prsn); // storing the data

prsn = sw::dql::query_from<person>()
    .where(sw::fields_query<person>::id == 20)
    .object(*session); // querying the data by using id

soci-wrapper's People

Contributors

osydunenko avatar

Stargazers

Serhii Olendarenko avatar

Watchers

 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.