eis/mix_cc/sql/value.h

52 lines
1.1 KiB
C++

/**
* @file mix_cc/sql/value.h
* @brief SQL语句中的设置数值
* @author Cat (null.null.null@qq.com)
* @version 0.1
* @date 2021-09-17
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#pragma once
#include <mix_cc/sql/public.h>
#include <mix_cc/sql/op/compare.h>
#include <string>
namespace mix_cc {
namespace sql {
template <typename Name, typename Tp>
struct value_t {
using value_type = Tp;
private:
Name val_name_;
value_type value_;
public:
constexpr value_t(Name val, value_type value)
: val_name_(val), value_(value) {}
~value_t() {}
constexpr auto get_str() {
return std::string(val_name_.c_str()) + "=" + get_value();
}
constexpr auto get_col_name() { return std::string(val_name_.c_str()); }
constexpr auto get_value() {
std::string value_str;
if constexpr (std::is_integral_v<value_type> ||
std::is_floating_point_v<value_type>) {
value_str = boost::str(boost::format("%1%") % value_);
} else {
value_str = boost::str(boost::format("%2%%1%%2%") % value_ % '\'');
}
return value_str;
}
};
} // namespace sql
} // namespace mix_cc