mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-03 12:18:11 +08:00
Optimize the Field class
This commit is contained in:
parent
f7173b1ff0
commit
7e6e0573e1
@ -196,7 +196,17 @@ template <>
|
|||||||
std::vector<char> Field::as<std::vector<char>>() const;
|
std::vector<char> Field::as<std::vector<char>>() const;
|
||||||
template <>
|
template <>
|
||||||
string_view Field::as<string_view>() const;
|
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;
|
// std::vector<int32_t> Field::as<std::vector<int32_t>>() const;
|
||||||
// template <>
|
// template <>
|
||||||
// std::vector<int64_t> Field::as<std::vector<int64_t>>() const;
|
// std::vector<int64_t> Field::as<std::vector<int64_t>>() const;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <drogon/orm/Field.h>
|
#include <drogon/orm/Field.h>
|
||||||
#include <drogon/utils/Utilities.h>
|
#include <drogon/utils/Utilities.h>
|
||||||
#include <trantor/utils/Logger.h>
|
#include <trantor/utils/Logger.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
using namespace drogon::orm;
|
using namespace drogon::orm;
|
||||||
Field::Field(const Row &row, Row::size_type columnNum) noexcept
|
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);
|
auto length = _result.getLength(_row, _column);
|
||||||
return string_view(first, length);
|
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
|
const char *Field::c_str() const
|
||||||
{
|
{
|
||||||
return as<const char *>();
|
return as<const char *>();
|
||||||
|
Loading…
Reference in New Issue
Block a user