From 1be330551017742b923b324ea4534e592f43397e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 20 Sep 2010 14:24:17 +0200 Subject: Cache result by default --- odb/database.hxx | 12 ++++++++---- odb/database.ixx | 15 +++++++++++---- odb/database.txx | 9 +++++++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/odb/database.hxx b/odb/database.hxx index ca0cc4c..832c1a6 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -74,19 +74,23 @@ namespace odb void erase (const typename object_traits::id_type& id); - // Object query API. + // Query API. // template result - query (); + query (bool cache = true); template result - query (const std::string&); + query (const char*, bool cache = true); template result - query (const odb::query&); + query (const std::string&, bool cache = true); + + template + result + query (const odb::query&, bool cache = true); // Transaction API. // diff --git a/odb/database.ixx b/odb/database.ixx index fb26d64..8085210 100644 --- a/odb/database.ixx +++ b/odb/database.ixx @@ -19,15 +19,22 @@ namespace odb template inline result database:: - query () + query (bool cache) { - return query (odb::query ()); + return query (odb::query (), cache); } template inline result database:: - query (const std::string& q) + query (const char* q, bool cache) { - return query (odb::query (q)); + return query (odb::query (q), cache); + } + + template + inline result database:: + query (const std::string& q, bool cache) + { + return query (odb::query (q), cache); } } diff --git a/odb/database.txx b/odb/database.txx index c037892..86336ea 100644 --- a/odb/database.txx +++ b/odb/database.txx @@ -84,11 +84,16 @@ namespace odb template result database:: - query (const odb::query& q) + query (const odb::query& q, bool cache) { if (!transaction::has_current ()) throw not_in_transaction (); - return object_traits::query (*this, q); + result r (object_traits::query (*this, q)); + + if (cache) + r.cache (); + + return r; } } -- cgit v1.1