The goal of the ORM C++ is to provide a decent Object-Relational Mapping library for C++ community.
π Base on native reflection from modern C++(C++20)
β
100% test coverage with unit tests and integration tests
ποΈ Support for multiple databases
βοΈ Support for multiple compilers
β οΈ No macros (currently few π)
π As low as possible runtime overhead
πΆ Easy to use
π As few dependencies as possible
#include <optional>
#include "orm-cxx/orm.hpp"
struct ObjectModel
{
// INTEGER - if field is optional it will not be marked as NOT NULL
std::optional<int> field1;
// TEXT NOT NULL
std::string field2;
// defining id_columns is optional
inline static const std::vector<std::string> id_columns = {"field1", "field2"};
// other way to define id column - will be over writen by using id_columns
// int id;
// defining table_name is optional, adding it will overwrite default table name
inline static const std::string table_name = "object_model";
// defining columns_names is optional, adding it will overwrite default columns names
// not all columns have to be defined, others will get default names
inline static const std::map<std::string, std::string> columns_names = {{"field1", "some_field1_name"},
{"field2", "some_field2_name"}};
};
int main()
{
// connect with standard connection string
orm::Database database;
database.connect("sqlite3://test.db");
// drop table if exists
database.deleteTable<ObjectModel>();
// create table in database
database.createTable<ObjectModel>();
// create objects and insert them into table
std::vector<ObjectModel> objects{{1, "test"}, {std::nullopt, "text"}};
database.insert(objects);
// define select query with builder pattern
orm::Query<ObjectModel> query;
query.limit(10).offset(5);
// execute query
auto queriedObjects = database.select(query);
return 0;
}
- Add config to git submodules (execute in project root):
mkdir externals
cd externals
git submodule add https://github.com/wsekta/orm-cxx.git
- Link with library:
set(BUILD_CONFIG_CXX_TESTS OFF)
set(BUILD_ORM_CXX_EXAMPLE OFF)
add_subdirectory(externals/orm-cxx)
add_executable(main Main.cpp)
target_link_libraries(main orm-cxx)
- GTest (
BUILD_ORM_CXX_TESTS=OFF
CMake flag to disable) - faker-cxx (
BUILD_ORM_CXX_TESTS=OFF
CMake flag to disable) - reflect-cpp
- SOCI
Feel free to join ORM C++ development! π
Please check CONTRIBUTING guide.