query select changes
This commit is contained in:
@@ -61,13 +61,29 @@ public:
|
||||
{
|
||||
return query_result<Type>(fetch());
|
||||
}
|
||||
|
||||
query_result<record> fetch_all();
|
||||
record fetch_one();
|
||||
template<typename Type>
|
||||
Type fetch_value()
|
||||
|
||||
template < class Type >
|
||||
std::optional<Type> fetch_one()
|
||||
{
|
||||
return fetch_one().at(0).as<Type>().value();
|
||||
auto result = query_result<Type>(fetch());
|
||||
auto first = result.begin();
|
||||
if (first == result.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return *first.get();
|
||||
}
|
||||
std::optional<record> fetch_one();
|
||||
|
||||
template<typename Type>
|
||||
std::optional<Type> fetch_value()
|
||||
{
|
||||
const auto result = fetch_one();
|
||||
if (result.has_value()) {
|
||||
return result.value().at(0).as<Type>().value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
statement prepare();
|
||||
|
||||
@@ -73,23 +73,30 @@ public:
|
||||
void on_attribute(const char *id, char *value, const utils::field_attributes &attr = utils::null_attributes);
|
||||
void on_attribute(const char *id, std::string &value, const utils::field_attributes &attr = utils::null_attributes);
|
||||
void on_attribute(const char *id, any_type &value, data_type_t type, const utils::field_attributes &attr = utils::null_attributes);
|
||||
// void on_attribute(const char *id, any_type &value, data_type_t type, const utils::field_attributes &attr = utils::null_attributes);
|
||||
|
||||
template < class Pointer >
|
||||
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &/*attr*/)
|
||||
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr)
|
||||
{
|
||||
if (!x.get()) {
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
} else {
|
||||
utils::access::process(*this, *x);
|
||||
}
|
||||
}
|
||||
template < class Pointer >
|
||||
void on_has_one(const char * /*id*/, Pointer &x, const utils::foreign_attributes &/*attr*/)
|
||||
void on_has_one(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr)
|
||||
{
|
||||
if (!x.get()) {
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
} else {
|
||||
utils::access::process(*this, *x);
|
||||
}
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
|
||||
Reference in New Issue
Block a user