From 6375147d5ae76a84dd64f1996cb0d9d501839db6 Mon Sep 17 00:00:00 2001 From: Michael Shepanski Date: Tue, 4 Nov 2014 16:10:03 +1100 Subject: Implement {query,execute}_{one,value}() shortcut functions Useful in situations where the query is know to return at most one element (*_one) or exactly one element (*_value). --- odb/database.ixx | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) (limited to 'odb/database.ixx') diff --git a/odb/database.ixx b/odb/database.ixx index 6cfbeec..739db03 100644 --- a/odb/database.ixx +++ b/odb/database.ixx @@ -473,6 +473,90 @@ namespace odb } template + inline typename object_traits::pointer_type database:: + query_one () + { + return query_one (odb::query ()); + } + + template + inline bool database:: + query_one (T& o) + { + return query_one (odb::query (), o); + } + + template + inline T database:: + query_value () + { + return query_value (odb::query ()); + } + + template + inline typename object_traits::pointer_type database:: + query_one (const char* q) + { + return query_one (odb::query (q)); + } + + template + inline bool database:: + query_one (const char* q, T& o) + { + return query_one (odb::query (q), o); + } + + template + inline T database:: + query_value (const char* q) + { + return query_value (odb::query (q)); + } + + template + inline typename object_traits::pointer_type database:: + query_one (const std::string& q) + { + return query_one (odb::query (q)); + } + + template + inline bool database:: + query_one (const std::string& q, T& o) + { + return query_one (odb::query (q), o); + } + + template + inline T database:: + query_value (const std::string& q) + { + return query_value (odb::query (q)); + } + + template + inline bool database:: + query_one (const odb::query& q, T& o) + { + return query_one_ (q, o); + } + + template + inline typename object_traits::pointer_type database:: + query_one (const odb::query& q) + { + return query_one_ (q); + } + + template + inline T database:: + query_value (const odb::query& q) + { + return query_value_ (q); + } + + template inline prepared_query database:: prepare_query (const char* n, const char* q) { @@ -620,6 +704,32 @@ namespace odb erase_ (pointer_traits::get_ref (pobj)); } + template + inline typename object_traits::pointer_type database:: + query_one_ (const Q& q) + { + return query_::call (*this, q).one (); + } + + template + inline bool database:: + query_one_ (const Q& q, T& o) + { + return query_::call (*this, q).one (o); + } + + template + inline T database:: + query_value_ (const Q& q) + { + // Compiler error pointing here? The object must be default-constructible + // in order to use the return-by-value API. + // + T o; + query_::call (*this, q).value (o); + return o; + } + // execute() // inline unsigned long long database:: -- cgit v1.1