diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-02 11:04:55 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-02 11:07:28 +0200 |
commit | ed17172ea74a8beaaaf5f2494bd1fecc81ff6144 (patch) | |
tree | 475930953f47199fc2a8a7286b0dfe8148c3b690 | |
parent | 1df3835ada62bd3c6d091469d4596589735abd18 (diff) |
Add result_iterator::id() function that returns id without loading object
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | doc/manual.xhtml | 22 |
2 files changed, 26 insertions, 0 deletions
@@ -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 (); }; } </pre> @@ -3905,6 +3908,25 @@ namespace odb } </pre> + <p>The <code>id()</code> 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:</p> + + <pre class="c++"> + 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. + } + } + </pre> <!-- CHAPTER --> |