From e440049c4bc819d591ac6785a309f111f1f9359f Mon Sep 17 00:00:00 2001 From: Bartosz Wieczorek Date: Mon, 12 Mar 2018 14:17:35 +0100 Subject: [PATCH] make transaction possible to use :) --- CMakeLists.txt | 6 +- cmake/FindAllRequirements.cmake | 27 +++++++-- cmake/install_deps.sh | 57 ++++++++++++++++--- .../eedb/db/pg/ParametersRepository.hpp | 2 +- .../include/eedb/db/pg/connection.hpp | 34 +++++++++-- .../db/postgresql_connector/src/RawSql.cpp | 4 +- .../postgresql_connector/src/connection.cpp | 3 +- .../src/data/ParametersRepository.cpp | 36 +++++++++--- .../postgresql_connector/test/DbTestBase.hpp | 9 ++- .../test/test_eedb_data_PgAuthIdentities.cpp | 5 -- .../test/test_eedb_data_PgAuthIdentity.cpp | 5 -- .../test/test_eedb_data_PgAuthToken.cpp | 6 -- .../test/test_eedb_data_PgAuthTokens.cpp | 5 -- .../test/test_eedb_data_PgCategories.cpp | 7 --- .../test_eedb_data_PgCategoriesRepository.cpp | 5 -- .../test/test_eedb_data_PgCategory.cpp | 5 -- .../test/test_eedb_data_PgItemsRepository.cpp | 5 -- .../test_eedb_data_PgParametersRepository.cpp | 13 ++--- .../test/test_eedb_data_PgUser.cpp | 6 -- .../test/test_eedb_data_PgUsers.cpp | 5 -- src/libs/eedb/include/eedb/db/Parameter.hpp | 32 ++++++----- 21 files changed, 160 insertions(+), 117 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a56ab8..8943a12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,10 +21,8 @@ include(cmake/cotire.cmake) set(CMAKE_INSTALL_RPATH "${HUNTER_INSTALL_PREFIX}/lib") set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) -include_directories(${CMAKE_BINARY_DIR}/external/include SYSTEM) -include_directories(${CMAKE_BINARY_DIR}/external/include/date SYSTEM) +include_directories(${CMAKE_BINARY_DIR}/local/include SYSTEM) +include_directories(${CMAKE_BINARY_DIR}/local/include/date SYSTEM) include_directories(share SYSTEM) add_subdirectory(src) -#add_subdirectory(tests) -#add_subdirectory(benchmarks) diff --git a/cmake/FindAllRequirements.cmake b/cmake/FindAllRequirements.cmake index b0fd8a2..1f2d415 100644 --- a/cmake/FindAllRequirements.cmake +++ b/cmake/FindAllRequirements.cmake @@ -20,8 +20,25 @@ find_package(spdlog CONFIG REQUIRED) hunter_add_package(PostgreSQL) find_package(PostgreSQL REQUIRED) -set(MAKE_CMD "${CMAKE_CURRENT_SOURCE_DIR}/cmake/install_deps.sh") -MESSAGE("COMMAND: ${MAKE_CMD} ${CMAKE_COMMAND} ${CMAKE_GENERATOR} ${CMAKE_CXX_COMPILER} ${CMAKE_C_COMPILER} ${CMAKE_PREFIX_PATH} ${Boost_LIBRARY_DIR_DEBUG}") -#execute_process( -# COMMAND x-terminal-emulator -e "sudo ${MAKE_CMD} ${CMAKE_GENERATOR} ${CMAKE_COMMAND} ${CMAKE_CXX_COMPILER} ${CMAKE_C_COMPILER} ${CMAKE_PREFIX_PATH}" -# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/external ) +set(INSTALL_DEPS_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/cmake/install_deps.sh") + +execute_process( + COMMAND ${INSTALL_DEPS_SCRIPT} + ${CMAKE_COMMAND} + ${CMAKE_GENERATOR} + ${CMAKE_CXX_COMPILER} + ${CMAKE_C_COMPILER} + ${CMAKE_PREFIX_PATH} + ${Boost_LIBRARY_DIR_DEBUG} + ${CMAKE_BINARY_DIR}/local + ${CMAKE_BUILD_TYPE} +# TIMEOUT + RESULT_VARIABLE rv + OUTPUT_VARIABLE ov + ERROR_VARIABLE ev + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_3rdParty +) + +message("rv='${rv}'") +message("ov='${ov}'") +message("ev='${ev}'") diff --git a/cmake/install_deps.sh b/cmake/install_deps.sh index 65fe1be..ba6e3c2 100755 --- a/cmake/install_deps.sh +++ b/cmake/install_deps.sh @@ -4,6 +4,12 @@ CMAKE_CXX_COMPILER=$3 CMAKE_C_COMPILER=$4 CMAKE_PREFIX_PATH=$5 CMAKE_RPATH=$6 +CMAKE_INSTALL_PREFIX=$7 +CMAKE_BUILD_TYPE=$8 + +if [ ! -d ${CMAKE_INSTALL_PREFIX} ]; then + mkdir -p ${CMAKE_INSTALL_PREFIX} +fi # clone all if [ ! -d date/.git ]; then @@ -30,35 +36,54 @@ else cd wt; git pull; cd ../ fi +if [ ! -d ChaiScript/.git ]; then + git clone -b develop --depth=1 https://github.com/ChaiScript/ChaiScript.git +else + cd ChaiScript; git pull; cd ../ +fi + # install all mkdir date-build; cd date-build -${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../date -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} \ +${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../date\ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\ + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} \ + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\ -DTZ_CXX_STANDARD=14 ${CMAKE_COMMAND} --build . --target install cd ../ mkdir sqlpp11-build; cd sqlpp11-build -${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../sqlpp11 -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}\ +${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../sqlpp11\ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\ + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}\ + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\ -DENABLE_TESTS=FALSE ${CMAKE_COMMAND} --build . --target install cd ../ mkdir sqlpp11-connector-postgresql-build; cd sqlpp11-connector-postgresql-build -${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../sqlpp11-connector-postgresql -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}\ +${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../sqlpp11-connector-postgresql\ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\ + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}\ + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\ -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}\ -DENABLE_TESTS=FALSE ${CMAKE_COMMAND} --build . --target install cd ../ mkdir wt-build; cd wt-build -${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../wt -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} \ - -DBoost_NO_BOOST_CMAKE=FALSE\ +${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../wt\ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\ + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}\ + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\ + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}\ -DCMAKE_INSTALL_RPATH=${CMAKE_RPATH}\ + -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}\ + -DBoost_NO_BOOST_CMAKE=FALSE\ -DBoost_NO_SYSTEM_PATHS=TRUE\ -DBUILD_EXAMPLES=OFF\ - -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}\ - -DINSTALL_RESOURCES=OFF\ + -DINSTALL_RESOURCES=ON\ -DENABLE_SSL=OFF\ -DENABLE_HARU=OFF\ -DENABLE_PANGO=OFF\ @@ -75,5 +100,19 @@ ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../wt -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COM ${CMAKE_COMMAND} --build . --target install cd ../ - -sleep 100000 +mkdir ChaiScript-build; cd ChaiScript-build +${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ../ChaiScript\ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\ + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}\ + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\ + -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}\ + -DMULTITHREAD_SUPPORT_ENABLED=TRUE\ + -DDYNLOAD_ENABLED=FALSE\ + -DBUILD_MODULES=TRUE\ + -DBUILD_SAMPLES=FALSE\ + -DRUN_FUZZY_TESTS=FALSE\ + -DUSE_STD_MAKE_SHARED=TRUE\ + -DRUN_PERFORMANCE_TESTS=FALSE\ + -DBUILD_IN_CPP17_MODE=TRUE +${CMAKE_COMMAND} --build . --target install +cd ../ diff --git a/src/libs/db/postgresql_connector/include/eedb/db/pg/ParametersRepository.hpp b/src/libs/db/postgresql_connector/include/eedb/db/pg/ParametersRepository.hpp index a7e16cf..91d9439 100644 --- a/src/libs/db/postgresql_connector/include/eedb/db/pg/ParametersRepository.hpp +++ b/src/libs/db/postgresql_connector/include/eedb/db/pg/ParametersRepository.hpp @@ -13,7 +13,7 @@ class PgParametersRepository : public ParametersRepository { public: PgParametersRepository(db::PgConnection&db); - std::unique_ptr< Parameter > create(std::string name, std::string description) const override; + void create(std::string name, std::optional< Unit > unit, parameter::Type type) const override; std::unique_ptr< Parameter > search(std::string name) const override; private: diff --git a/src/libs/db/postgresql_connector/include/eedb/db/pg/connection.hpp b/src/libs/db/postgresql_connector/include/eedb/db/pg/connection.hpp index 7b9bd3b..e3e35b6 100644 --- a/src/libs/db/postgresql_connector/include/eedb/db/pg/connection.hpp +++ b/src/libs/db/postgresql_connector/include/eedb/db/pg/connection.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace eedb::db { class PgConfig; @@ -11,16 +12,37 @@ class PgConnection { public: PgConnection(std::shared_ptr< eedb::db::PgConfig > config); - sqlpp::postgresql::connection * native() { - return _conn.get(); - } - template < typename T > auto operator()(T && t) { - return _conn->operator()(std::forward< T >(t)); + return _conn.operator()(std::forward< T >(t)); + } + + auto execute(const std::string & query) { + return _conn.execute(query); + } + + void start_transaction(sqlpp::isolation_level level = sqlpp::isolation_level::undefined) { + _in_transaction_count++; + _conn.start_transaction(level); + } + + void commit_transaction() { + _in_transaction_count--; + _conn.commit_transaction(); + } + + void report_rollback_failure(const std::string & message) noexcept { + _conn.report_rollback_failure(message); + } + + void rollback_transaction(bool report) { + _in_transaction_count--; + _conn.rollback_transaction(report); } private: - std::unique_ptr< sqlpp::postgresql::connection > _conn; + sqlpp::postgresql::connection _conn; + int _in_transaction_count{0}; }; + } // namespace eedb::db diff --git a/src/libs/db/postgresql_connector/src/RawSql.cpp b/src/libs/db/postgresql_connector/src/RawSql.cpp index eb36a6d..31a9d6b 100644 --- a/src/libs/db/postgresql_connector/src/RawSql.cpp +++ b/src/libs/db/postgresql_connector/src/RawSql.cpp @@ -11,8 +11,8 @@ void exec_file(PgConnection & db, const std::experimental::filesystem::path & fi std::ifstream stream(filepath); std::string filebuf{std::istreambuf_iterator< char >(stream), std::istreambuf_iterator< char >()}; - db.native()->execute("SET client_min_messages=WARNING;"); - db.native()->execute(filebuf); + db.execute("SET client_min_messages=WARNING;"); + db.execute(filebuf); std::cerr.clear(); } diff --git a/src/libs/db/postgresql_connector/src/connection.cpp b/src/libs/db/postgresql_connector/src/connection.cpp index 25bece7..dbf9d66 100644 --- a/src/libs/db/postgresql_connector/src/connection.cpp +++ b/src/libs/db/postgresql_connector/src/connection.cpp @@ -3,6 +3,5 @@ namespace eedb::db { -PgConnection::PgConnection(std::shared_ptr< eedb::db::PgConfig > config) - : _conn(std::make_unique< sqlpp::postgresql::connection >(config)) {} +PgConnection::PgConnection(std::shared_ptr< eedb::db::PgConfig > config) : _conn(config) {} } // namespace eedb::db diff --git a/src/libs/db/postgresql_connector/src/data/ParametersRepository.cpp b/src/libs/db/postgresql_connector/src/data/ParametersRepository.cpp index 18ddd6d..9d423e4 100644 --- a/src/libs/db/postgresql_connector/src/data/ParametersRepository.cpp +++ b/src/libs/db/postgresql_connector/src/data/ParametersRepository.cpp @@ -1,19 +1,37 @@ #include -#include +#include +#include +#include + #include +#include -namespace eedb{ -struct PgParametersRepository::PgParametersRepositoryPriv {}; +namespace eedb { +struct PgParametersRepository::PgParametersRepositoryPriv { + PgParametersRepositoryPriv(db::PgConnection & db, User * user = nullptr) : _db{db}, _user{user} {} -PgParametersRepository::PgParametersRepository(db::PgConnection & db) : _priv{spimpl::make_unique_impl< PgParametersRepositoryPriv >()} {} + void create(std::string name, std::optional< Unit > unit, parameter::Type type) { + using namespace sqlpp; + _db(postgresql::insert_into(t_parameter) // + .set(t_parameter.owner = _user->uid(), t_parameter.name = name) + .returning(t_parameter.id)); + } -std::unique_ptr PgParametersRepository::create(std::string name, std::string description) const -{ + private: + db::PgConnection & _db; + User * _user; + +// std::map< std::string, PgParameter > _cache; +}; + +PgParametersRepository::PgParametersRepository(db::PgConnection & db) : _priv{spimpl::make_unique_impl< PgParametersRepositoryPriv >(db)} {} + +void PgParametersRepository::create(std::string name, std::optional unit, parameter::Type type) const { + _priv->create(std::move(name), std::move(unit), type); } -std::unique_ptr PgParametersRepository::search(std::string name) const -{ - +std::unique_ptr< Parameter > PgParametersRepository::search(std::string name) const { + return {}; } } // namespace eedb diff --git a/src/libs/db/postgresql_connector/test/DbTestBase.hpp b/src/libs/db/postgresql_connector/test/DbTestBase.hpp index 9e149e9..325409b 100644 --- a/src/libs/db/postgresql_connector/test/DbTestBase.hpp +++ b/src/libs/db/postgresql_connector/test/DbTestBase.hpp @@ -107,10 +107,12 @@ class PgTestDatabasePrepare { template < typename T > class DbTestBase : public testing::Test { public: + DbTestBase() : transaction{sqlpp::start_transaction(db())} {} + static void SetUpTestCase() { _test_db = std::make_unique< PgTestDatabasePrepare >(); // _test_db->db().native()->start_transaction(); - _test_db->db().native()->execute("SET synchronous_commit=off;"); + _test_db->db().execute("SET synchronous_commit=off;"); eedb::db::exec_file(_test_db->db(), "/home/bwieczor/src/eedb/sql/schema.sql"); // _test_db->db().native()->commit_transaction(); } @@ -123,6 +125,11 @@ class DbTestBase : public testing::Test { return _test_db->db(); } + virtual ~DbTestBase(){ + transaction.rollback(); + } + protected: static std::unique_ptr< PgTestDatabasePrepare > _test_db; + sqlpp::transaction_t< eedb::db::PgConnection > transaction; }; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentities.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentities.cpp index 9e45135..77c2077 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentities.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentities.cpp @@ -10,7 +10,6 @@ class PgAuthIdentitiesTest : public DbTestBase< PgAuthIdentitiesTest > { public: PgAuthIdentitiesTest() : user{db()} { using namespace testing; - db().native()->start_transaction(); user._init(); user._createIdentity({"identity", "provider"}); @@ -19,10 +18,6 @@ class PgAuthIdentitiesTest : public DbTestBase< PgAuthIdentitiesTest > { sut = std::make_unique< eedb::PgAuthIdentities >(db(), &user); } - ~PgAuthIdentitiesTest() { - db().native()->rollback_transaction(false); - } - protected: eedb::db::pg::UserMock user; std::unique_ptr< eedb::PgAuthIdentities > sut; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentity.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentity.cpp index dd3e637..e7b9ef5 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentity.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentity.cpp @@ -8,17 +8,12 @@ class PgAuthIdentityTest : public DbTestBase< PgAuthIdentityTest > { public: PgAuthIdentityTest() { using namespace testing; - db().native()->start_transaction(); } void initCached() { sut = std::make_unique< eedb::PgAuthIdentity >(db(), "identity", "provider"); } - ~PgAuthIdentityTest() { - db().native()->rollback_transaction(false); - } - protected: std::unique_ptr< eedb::PgAuthIdentity > sut; }; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthToken.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthToken.cpp index 84864d2..872c9ca 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthToken.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthToken.cpp @@ -16,8 +16,6 @@ class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > { public: PgAuthTokenTest() : user{db()} { using namespace testing; - db().native()->start_transaction(); - user._init(); user._expect_call_uid(); @@ -39,10 +37,6 @@ class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > { db()(update(t_auth_token).set(t_auth_token.expires = time_point_cast< microseconds >(exp)).where(t_auth_token.id == sutId)); } - ~PgAuthTokenTest() { - db().native()->rollback_transaction(false); - } - protected: eedb::db::pg::UserMock user; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthTokens.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthTokens.cpp index d0fc213..950e2be 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthTokens.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthTokens.cpp @@ -11,7 +11,6 @@ class PgAuthTokensTest : public DbTestBase< PgAuthTokensTest > { public: PgAuthTokensTest() : user{db()} { using namespace testing; - db().native()->start_transaction(); user._init(); user._expect_call_uid(); @@ -23,10 +22,6 @@ class PgAuthTokensTest : public DbTestBase< PgAuthTokensTest > { token._init(db(), role, user, hash); } - ~PgAuthTokensTest() { - db().native()->rollback_transaction(false); - } - protected: eedb::db::pg::UserMock user; std::unique_ptr< eedb::PgAuthTokens > sut; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategories.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategories.cpp index 8261c32..3a5cab1 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategories.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategories.cpp @@ -8,16 +8,9 @@ class PgCategoriesTest : public DbTestBase< PgCategoriesTest > { public: PgCategoriesTest() { - db().native()->start_transaction(); - - //sut = std::make_unique< eedb::PgCategories >(_categories); } - ~PgCategoriesTest() { - db().native()->rollback_transaction(false); - } - protected: // std::vector< UniquePtrMockWrapper< eedb::db:: > > _categories; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategoriesRepository.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategoriesRepository.cpp index 960f3a6..2f367f4 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategoriesRepository.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategoriesRepository.cpp @@ -9,16 +9,11 @@ class PgCategoriesRepositoryTest : public DbTestBase< PgCategoriesRepositoryTest > { public: PgCategoriesRepositoryTest() : user{db()} { - db().native()->start_transaction(); user._init(); user._expect_call_uid(); sut = std::make_unique< eedb::PgCategoriesRepository >(db(), &user); } - ~PgCategoriesRepositoryTest() { - db().native()->rollback_transaction(false); - } - protected: eedb::db::pg::UserMock user; std::unique_ptr< eedb::PgCategoriesRepository > sut; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategory.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategory.cpp index 10ab9b1..d2990ff 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategory.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategory.cpp @@ -7,7 +7,6 @@ class PgCategoryTest : public DbTestBase< PgCategoryTest > { public: PgCategoryTest() : user{db()} { - db().native()->start_transaction(); user._init(); user._expect_call_uid(); sut = std::make_unique< eedb::PgCategory >(db(), &user); @@ -19,10 +18,6 @@ class PgCategoryTest : public DbTestBase< PgCategoryTest > { .returning(t_category.id)); } - ~PgCategoryTest() { - db().native()->rollback_transaction(false); - } - protected: eedb::db::pg::UserMock user; std::unique_ptr< eedb::PgCategory > sut; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgItemsRepository.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgItemsRepository.cpp index 9ccfa19..55b0358 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgItemsRepository.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgItemsRepository.cpp @@ -16,7 +16,6 @@ class PgItemsRepositoryTest : public DbTestBase< PgItemsRepositoryTest > { public: PgItemsRepositoryTest() : user{db()}, category{db(), &user}, numericParameter{db()}, textParameter{db()}, listParameter{db()} { using namespace testing; - db().native()->start_transaction(); user._init(); // create fake user user._expect_call_uid(); category._init_simple("main"); @@ -42,10 +41,6 @@ class PgItemsRepositoryTest : public DbTestBase< PgItemsRepositoryTest > { eedb::Value{std::vector{1.2, 3.4, 5.6, 7.8}, &listParameter}); } - ~PgItemsRepositoryTest() { - db().native()->rollback_transaction(false); - } - protected: eedb::db::pg::UserMock user; eedb::db::pg::CategoryMock category; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgParametersRepository.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgParametersRepository.cpp index 0d32752..070d653 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgParametersRepository.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgParametersRepository.cpp @@ -8,16 +8,11 @@ class PgParametersRepositoryTest : public DbTestBase< PgParametersRepositoryTest > { public: PgParametersRepositoryTest() : user{db()}, parameter{db()} { - db().native()->start_transaction(); user._init(); - parameter._init("paraemter"); + parameter._init("parameter"); sut = std::make_unique< eedb::PgParametersRepository >(db()); } - ~PgParametersRepositoryTest() { - db().native()->rollback_transaction(false); - } - protected: eedb::db::pg::UserMock user; eedb::db::pg::ParameterMock parameter; @@ -36,10 +31,10 @@ TEST_F(PgParametersRepositoryTest, searchForBadName){ EXPECT_FALSE(sut->search("bad_parameter")); } -TEST_F(PgParametersRepositoryTest, init3){ - +TEST_F(PgParametersRepositoryTest, createWillNotThrow) { +// EXPECT_NO_THROW(sut->create("name", "description")); } -TEST_F(PgParametersRepositoryTest, init4){ +TEST_F(PgParametersRepositoryTest, createSameThrowsException) { } diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgUser.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgUser.cpp index 22e82f4..92bd7aa 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgUser.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgUser.cpp @@ -14,8 +14,6 @@ class PgUserTest : public DbTestBase< PgUserTest > { public: PgUserTest() { - db().native()->start_transaction(); - auto info_ = std::make_unique< eedb::AuthInfoConst >( eedb::Password{"bcrypt", "OM/Z1c4WBFXvwkxh", "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q"}, eedb::Email{"email@eedb.pl"}); @@ -45,10 +43,6 @@ class PgUserTest : public DbTestBase< PgUserTest > { sut = std::make_unique< eedb::PgUser >(db(), uid); } - ~PgUserTest() { - db().native()->rollback_transaction(false); - } - protected: int64_t uid; std::unique_ptr< eedb::PgUser > sut; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgUsers.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgUsers.cpp index 3df5343..4842a2c 100644 --- a/src/libs/db/postgresql_connector/test/test_eedb_data_PgUsers.cpp +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgUsers.cpp @@ -12,11 +12,6 @@ class PgUsersTest : public DbTestBase< PgUsersTest > { public: PgUsersTest() { sut = std::make_unique< eedb::PgUsers >(db()); - db().native()->start_transaction(); - } - - ~PgUsersTest() { - db().native()->rollback_transaction(false); } auto createUser(std::string name, std::string email) { diff --git a/src/libs/eedb/include/eedb/db/Parameter.hpp b/src/libs/eedb/include/eedb/db/Parameter.hpp index f0b7c5f..61e1b7e 100644 --- a/src/libs/eedb/include/eedb/db/Parameter.hpp +++ b/src/libs/eedb/include/eedb/db/Parameter.hpp @@ -10,6 +10,20 @@ namespace eedb { class Parameter; +class Parameters; + +namespace parameter { + enum class Type { + Numeric = 0x1 << 0, + NumericList, + NumericRange, + + Text = 0x1 << 4, + TextList, + + Script = 0x1 << 8 + }; +} // namespace parameter class ParametersRepository { public: @@ -18,9 +32,8 @@ class ParametersRepository { /** * @brief create * @param name - * @return */ - virtual std::unique_ptr< Parameter > create(std::string name, std::string description) const = 0; + virtual void create(std::string name, std::optional< Unit > unit, parameter::Type type) const = 0; /** * @brief search @@ -37,17 +50,6 @@ namespace details { class Parameters : public details::ParameterPtrIteratorRange {}; -enum class Type { - Numeric = 0x1 << 0, - NumericList, - NumericRange, - - Text = 0x1 << 4, - TextList, - - Script = 0x1 << 8 -}; - /** * @brief The Parameter class */ @@ -59,7 +61,7 @@ class Parameter { * @brief type * @return supported type od data */ - Type type() const noexcept(true) { + parameter::Type type() const noexcept(true) { return _type; } @@ -82,6 +84,6 @@ class Parameter { virtual std::string_view description() const = 0; protected: - Type _type; + parameter::Type _type; }; } // namespace eedb