diff --git a/cmake/build.cmake b/cmake/build.cmake index c369dc6..90454d9 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -16,4 +16,4 @@ if(BUILD_WITH_LIBCXX AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") message(STATUS "Build with libc++") else() message(STATUS "Build with libstdc++") -endif() +endif() \ No newline at end of file diff --git a/cmake/mariadb.cmake b/cmake/mariadb.cmake index e3e95e1..7157278 100644 --- a/cmake/mariadb.cmake +++ b/cmake/mariadb.cmake @@ -20,7 +20,12 @@ ELSEIF (LINUX) /usr/include/mariadb) ELSEIF (APPLE) FIND_PATH(MARIADB_INCLUDE_DIR mysql.h - /opt/homebrew/include/mariadb) + /opt/homebrew/include/mariadb) +ELSE (WIN32) + FIND_PATH(MARIADB_INCLUDE_DIR mysql.h + /opt/homebrew/include/mariadb + /usr/local/include/mariadb + /usr/include/mariadb) ENDIF() SET(MARIADB_NAMES mariadb) @@ -41,6 +46,13 @@ ELSEIF (APPLE) NAMES ${MARIADB_NAMES} PATHS /opt/homebrew/lib PATH_SUFFIXES mariadb) +ELSE (WIN32) + FIND_LIBRARY(MARIADB_LIBRARY + NAMES ${MARIADB_NAMES} + PATHS /usr/lib + /usr/local/lib + /opt/homebrew/lib + PATH_SUFFIXES mariadb) ENDIF() IF (MARIADB_INCLUDE_DIR AND MARIADB_LIBRARY) diff --git a/cmake/mysql.cmake b/cmake/mysql.cmake index 23778f8..3056baa 100644 --- a/cmake/mysql.cmake +++ b/cmake/mysql.cmake @@ -23,6 +23,13 @@ ELSEIF (APPLE) /opt/homebrew/include/mysql /opt/homebrew/opt/mysql@8.0/include /opt/homebrew/Cellar/mysql@8.0/*/include/mysql) +ELSE (WIN32) + FIND_PATH(MYSQL_INCLUDE_DIR mysql.h + /opt/homebrew/Cellar/mysql@8.0/*/include/mysql + /opt/homebrew/opt/mysql@8.0/include + /opt/homebrew/include/mysql + /usr/local/include/mysql + /usr/include/mysql) ENDIF() SET(MYSQL_NAMES mysqlclient) @@ -45,6 +52,15 @@ ELSEIF (APPLE) /opt/homebrew/opt/mysql@8.0/lib /opt/homebrew/Cellar/mysql@8.0/*/lib PATH_SUFFIXES mysql) +ELSE (WIN32) + FIND_LIBRARY(MYSQL_LIBRARY + NAMES ${MYSQL_NAMES} + PATHS /usr/lib + /usr/local/lib + /opt/homebrew/lib + /opt/homebrew/opt/mysql@8.0/lib + /opt/homebrew/Cellar/mysql@8.0/*/lib + PATH_SUFFIXES mysql) ENDIF() IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) diff --git a/cmake/pgsql.cmake b/cmake/pgsql.cmake index 7f8846c..65cf2db 100644 --- a/cmake/pgsql.cmake +++ b/cmake/pgsql.cmake @@ -21,6 +21,11 @@ ELSEIF (LINUX) ELSEIF (APPLE) FIND_PATH(PGSQL_INCLUDE_DIR libpq-fe.h /opt/homebrew/include/postgresql) +ELSE (WIN32) + FIND_PATH(PGSQL_INCLUDE_DIR libpq-fe.h + /opt/homebrew/include/postgresql + /usr/local/include/postgresql + /usr/include/postgresql) ENDIF() IF (WIN32) @@ -40,6 +45,13 @@ ELSEIF (APPLE) FIND_LIBRARY(PGSQL_LIBRARY NAMES ${PGSQL_NAMES} PATHS /opt/homebrew/lib) +ELSE (WIN32) + SET(PGSQL_NAMES pq) + FIND_LIBRARY(PGSQL_LIBRARY + NAMES ${PGSQL_NAMES} + PATHS /usr/lib + /usr/local/lib + /opt/homebrew/lib) ENDIF() IF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY) diff --git a/ormpp/mysql.hpp b/ormpp/mysql.hpp index f2566b6..86842de 100644 --- a/ormpp/mysql.hpp +++ b/ormpp/mysql.hpp @@ -341,11 +341,11 @@ class mysql { template std::enable_if_t, std::vector> query_s( const std::string &str, Args &&...args) { + constexpr auto SIZE = ylt::reflection::members_count_v; std::string sql = generate_query_sql(str); #ifdef ORMPP_ENABLE_LOG std::cout << sql << std::endl; #endif - constexpr auto SIZE = iguana::get_value(); stmt_ = mysql_stmt_init(con_); if (!stmt_) { @@ -482,7 +482,7 @@ class mysql { index++; } }, - std::make_index_sequence>{}); + std::make_index_sequence{}); if (index == 0) { return {}; @@ -506,7 +506,7 @@ class mysql { using U = ylt::reflection::remove_cvref_t; if constexpr (iguana::ylt_refletable_v) { ylt::reflection::for_each( - item, [¶m_binds, &index, &mp, &t, this]( + item, [¶m_binds, &index, &mp, this]( auto &field, auto /*name*/, auto /*index*/) { set_value(param_binds.at(index), field, index, mp); index++; @@ -529,9 +529,9 @@ class mysql { [&index, nulls](auto &item, auto /*index*/) { using U = ylt::reflection::remove_cvref_t; if constexpr (iguana::ylt_refletable_v) { - ylt::reflection::for_each(item, [&index, nulls, &t]( - auto &field, auto /*name*/, - auto /*index*/) { + ylt::reflection::for_each(item, [&index, nulls](auto &field, + auto /*name*/, + auto /*index*/) { if (nulls.at(index++)) { using W = ylt::reflection::remove_cvref_t; if constexpr (is_optional_v::value || @@ -562,11 +562,11 @@ class mysql { template std::enable_if_t, std::vector> query( Args &&...args) { + constexpr auto SIZE = ylt::reflection::members_count_v; std::string sql = generate_query_sql(args...); #ifdef ORMPP_ENABLE_LOG std::cout << sql << std::endl; #endif - constexpr auto SIZE = iguana::get_value(); stmt_ = mysql_stmt_init(con_); if (!stmt_) { @@ -945,7 +945,7 @@ class mysql { template int stmt_execute(const T &t, OptType type, Args &&...args) { std::vector param_binds; - constexpr auto arr = iguana::indexs_of(); + constexpr auto arr = indexs_of(); if constexpr (sizeof...(members) > 0) { (set_param_bind( param_binds, diff --git a/ormpp/postgresql.hpp b/ormpp/postgresql.hpp index 909eaa0..4c67b17 100644 --- a/ormpp/postgresql.hpp +++ b/ormpp/postgresql.hpp @@ -298,7 +298,6 @@ class postgresql { const Arg &s, Args &&...args) { static_assert(iguana::is_tuple::value); constexpr auto SIZE = std::tuple_size_v; - std::string sql = s; constexpr auto Args_Size = sizeof...(Args); if (Args_Size != 0) { @@ -449,8 +448,8 @@ class postgresql { bool has_add_field = false; for_each0( tp, - [&sql, &i, &has_add_field, &unique_fields, field_name, name, this]( - auto item, auto I) { + [&sql, &i, &has_add_field, &unique_fields, field_name, name, + this](auto item) { if constexpr (std::is_same_v || std::is_same_v) { if (item.fields.find(field_name.data()) == item.fields.end()) @@ -522,8 +521,8 @@ class postgresql { #ifdef ORMPP_ENABLE_LOG std::cout << sql << std::endl; #endif - res_ = - PQprepare(con_, "", sql.data(), (int)iguana::get_value(), nullptr); + res_ = PQprepare(con_, "", sql.data(), ylt::reflection::members_count_v, + nullptr); auto guard = guard_statment(res_); return PQresultStatus(res_) == PGRES_COMMAND_OK; } @@ -532,7 +531,7 @@ class postgresql { std::optional stmt_execute(const T &t, OptType type, Args &&...args) { std::vector> param_values; - constexpr auto arr = iguana::indexs_of(); + constexpr auto arr = indexs_of(); if constexpr (sizeof...(members) > 0) { (set_param_values( param_values, diff --git a/ormpp/sqlite.hpp b/ormpp/sqlite.hpp index 9cd6fd3..0e1a301 100644 --- a/ormpp/sqlite.hpp +++ b/ormpp/sqlite.hpp @@ -292,7 +292,6 @@ class sqlite { const Arg &s, Args &&...args) { static_assert(iguana::is_tuple::value); constexpr auto SIZE = std::tuple_size_v; - std::string sql = s; #ifdef ORMPP_ENABLE_LOG std::cout << sql << std::endl; diff --git a/ormpp/utility.hpp b/ormpp/utility.hpp index 2d36b13..1baeb6e 100644 --- a/ormpp/utility.hpp +++ b/ormpp/utility.hpp @@ -16,6 +16,12 @@ namespace ormpp { //-------------------------------------------------------------------------------------------------------------// //-------------------------------------------------------------------------------------------------------------// +template +constexpr std::array indexs_of() { + return std::array{ + ylt::reflection::index_of()...}; +} + template constexpr void for_each(std::tuple &t, F &&f, std::index_sequence) { @@ -94,6 +100,39 @@ struct is_optional_v : std::false_type {}; template struct is_optional_v> : std::true_type {}; +template +constexpr std::enable_if_t, size_t> get_value() { + return ylt::reflection::members_count_v; +} + +template +constexpr std::enable_if_t, size_t> +get_value() { + return 1; +} + +template +struct value_of; + +template +struct value_of { + static const auto value = (get_value()); +}; + +template +struct value_of { + static const auto value = (value_of::value + value_of::value); +}; + +template +struct result_size; + +template