diff --git a/orm_lib/inc/drogon/orm/Field.h b/orm_lib/inc/drogon/orm/Field.h index 2f3ea087..6309d95b 100644 --- a/orm_lib/inc/drogon/orm/Field.h +++ b/orm_lib/inc/drogon/orm/Field.h @@ -196,7 +196,17 @@ template <> std::vector Field::as>() const; template <> string_view Field::as() const; -// template <> +template <> +int Field::as() const; +template <> +long Field::as() const; +template <> +long long Field::as() const; +template <> +float Field::as() const; +template <> +double Field::as() const; + // std::vector Field::as>() const; // template <> // std::vector Field::as>() const; diff --git a/orm_lib/src/Field.cc b/orm_lib/src/Field.cc index a5d5cb4e..f1e45c90 100644 --- a/orm_lib/src/Field.cc +++ b/orm_lib/src/Field.cc @@ -15,6 +15,7 @@ #include #include #include +#include using namespace drogon::orm; Field::Field(const Row &row, Row::size_type columnNum) noexcept @@ -90,6 +91,37 @@ string_view Field::as() const auto length = _result.getLength(_row, _column); return string_view(first, length); } + +template <> +int Field::as() const +{ + return atoi(_result.getValue(_row, _column)); +} + +template <> +long Field::as() const +{ + return atol(_result.getValue(_row, _column)); +} + +template <> +long long Field::as() const +{ + return atoll(_result.getValue(_row, _column)); +} + +template <> +float Field::as() const +{ + return atof(_result.getValue(_row, _column)); +} + +template <> +double Field::as() const +{ + return std::stod(_result.getValue(_row, _column)); +} + const char *Field::c_str() const { return as();