From ed17172ea74a8beaaaf5f2494bd1fecc81ff6144 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Nov 2011 11:04:55 +0200 Subject: Add result_iterator::id() function that returns id without loading object --- NEWS | 4 ++++ doc/manual.xhtml | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/NEWS b/NEWS index 6de41f6..b3e329e 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ Version 1.7.0 functionality. For more information, refer to Section 11.1.5 "id", in the ODB manual. + * Query result iterator now provides the id() function with allows one to + get object id without loading the object. For more information, refer to + Section 4.4 "Query Result", in the ODB manual. + Version 1.6.0 * New concept, view, is a C++ class that embodies a light-weight, read- diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 690c17f..d262319 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -3837,6 +3837,9 @@ namespace odb void load (T& x); + + typename object_traits<T>::id_type + id (); }; } @@ -3905,6 +3908,25 @@ namespace odb } +

The id() function return the object id of the current + object. While we can achieve the same by loading the object and getting + its id, this function is more efficient since it doesn't actually + create the object. This can be useful when all we need is the object's + identifier. For example:

+ +
+  std::set<unsigned long> set = ...; // Persons of interest.
+
+  result r (db.query<person> (query::first == "John"));
+
+  for (result::iterator i (r.begin ()); i != r.end (); ++i)
+  {
+    if (set.find (i.id ()) != set.end ()) // No object loaded.
+    {
+      cout << i->first () << endl; // Object loaded.
+    }
+  }
+  
-- cgit v1.1