Optimize the Field class

This commit is contained in:
antao 2019-07-08 16:42:06 +08:00
parent f7173b1ff0
commit 7e6e0573e1
2 changed files with 43 additions and 1 deletions

View File

@ -196,7 +196,17 @@ template <>
std::vector<char> Field::as<std::vector<char>>() const;
template <>
string_view Field::as<string_view>() const;
// template <>
template <>
int Field::as<int>() const;
template <>
long Field::as<long>() const;
template <>
long long Field::as<long long>() const;
template <>
float Field::as<float>() const;
template <>
double Field::as<double>() const;
// std::vector<int32_t> Field::as<std::vector<int32_t>>() const;
// template <>
// std::vector<int64_t> Field::as<std::vector<int64_t>>() const;

View File

@ -15,6 +15,7 @@
#include <drogon/orm/Field.h>
#include <drogon/utils/Utilities.h>
#include <trantor/utils/Logger.h>
#include <stdlib.h>
using namespace drogon::orm;
Field::Field(const Row &row, Row::size_type columnNum) noexcept
@ -90,6 +91,37 @@ string_view Field::as<string_view>() const
auto length = _result.getLength(_row, _column);
return string_view(first, length);
}
template <>
int Field::as<int>() const
{
return atoi(_result.getValue(_row, _column));
}
template <>
long Field::as<long>() const
{
return atol(_result.getValue(_row, _column));
}
template <>
long long Field::as<long long>() const
{
return atoll(_result.getValue(_row, _column));
}
template <>
float Field::as<float>() const
{
return atof(_result.getValue(_row, _column));
}
template <>
double Field::as<double>() const
{
return std::stod(_result.getValue(_row, _column));
}
const char *Field::c_str() const
{
return as<const char *>();