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.hxx | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'odb/database.hxx') diff --git a/odb/database.hxx b/odb/database.hxx index 4e59aaf..1f56b7f 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -242,6 +242,56 @@ namespace odb result query (const odb::query&, bool cache = true); + // Query one API. + // + template + typename object_traits::pointer_type + query_one (); + + template + bool + query_one (T& object); + + template + T + query_value (); + + template + typename object_traits::pointer_type + query_one (const char*); + + template + bool + query_one (const char*, T& object); + + template + T + query_value (const char*); + + template + typename object_traits::pointer_type + query_one (const std::string&); + + template + bool + query_one (const std::string&, T& object); + + template + T + query_value (const std::string&); + + template + typename object_traits::pointer_type + query_one (const odb::query&); + + template + bool + query_one (const odb::query&, T& object); + + template + T + query_value (const odb::query&); + // Query preparation. // template @@ -487,6 +537,18 @@ namespace odb void erase_ (const typename object_traits::pointer_type&); + template + typename object_traits::pointer_type + query_one_ (const Q&); + + template + bool + query_one_ (const Q&, T&); + + template + T + query_value_ (const Q&); + template ::kind> -- cgit v1.1