From 53ad6efb657c0661d27eedf0dcb27b5f1c5a3631 Mon Sep 17 00:00:00 2001 From: Jacyking <791026912@qq.com> Date: Fri, 18 Aug 2023 14:01:01 +0800 Subject: [PATCH] add get_fields api --- iguana/reflection.hpp | 18 ------------------ include/utility.hpp | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/iguana/reflection.hpp b/iguana/reflection.hpp index f9eb9de4..f4ee98fe 100644 --- a/iguana/reflection.hpp +++ b/iguana/reflection.hpp @@ -614,18 +614,6 @@ constexpr std::array get_alias_arr(Args... pairs) { constexpr static std::string_view struct_name() { \ return std::string_view(#STRUCT_NAME, sizeof(#STRUCT_NAME) - 1); \ } \ - static std::string_view fields() { \ - static std::string alisa_fields; \ - if (!alisa_fields.empty()) { \ - return alisa_fields; \ - } \ - for (const auto &it : arr()) { \ - alisa_fields += it.data(); \ - alisa_fields += ","; \ - } \ - alisa_fields.back() = ' '; \ - return alisa_fields; \ - } \ constexpr static size_t value() { return size_type::value; } \ constexpr static std::array arr() { \ return iguana::detail::get_alias_arr(__VA_ARGS__); \ @@ -923,12 +911,6 @@ constexpr const std::string_view get_name() { return M::name(); } -template -constexpr const std::string_view get_fields() { - using M = Reflect_members; - return M::fields(); -} - template constexpr std::enable_if_t::value, size_t> get_value() { using M = decltype(iguana_reflect_type(std::declval())); diff --git a/include/utility.hpp b/include/utility.hpp index 8934de4a..19af0c10 100644 --- a/include/utility.hpp +++ b/include/utility.hpp @@ -144,12 +144,26 @@ inline std::string get_name() { return quota_name; } +template >> +inline std::string get_fields() { + static std::string alisa_fields; + if (!alisa_fields.empty()) { + return alisa_fields; + } + for (const auto &it : iguana::Reflect_members::arr()) { + alisa_fields += it.data(); + alisa_fields += ","; + } + alisa_fields.back() = ' '; + return alisa_fields; +} + template inline std::string generate_insert_sql(bool replace) { std::string sql = replace ? "replace into " : "insert into "; constexpr size_t SIZE = iguana::get_value(); auto name = get_name(); - auto fields = iguana::get_fields(); + auto fields = get_fields(); append(sql, name.data(), "(", fields.data(), ")", "values("); for (size_t i = 0; i < SIZE; ++i) { @@ -257,7 +271,7 @@ inline std::string generate_query_sql(Args &&...args) { static_assert(param_size == 0 || param_size > 0); std::string sql = "select "; auto name = get_name(); - auto fields = iguana::get_fields(); + auto fields = get_fields(); append(sql, fields.data(), "from", name.data()); std::string where_sql = "";