aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-09-20 14:24:17 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-09-20 14:24:17 +0200
commit1be330551017742b923b324ea4534e592f43397e (patch)
treed598265ae720af82e9804aa6b12ee975322d1538
parentcf503d65bf38512a89fd44e94346a3ffe56d4f40 (diff)
Cache result by default
-rw-r--r--odb/database.hxx12
-rw-r--r--odb/database.ixx15
-rw-r--r--odb/database.txx9
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<T>::id_type& id);
- // Object query API.
+ // Query API.
//
template <typename T>
result<T>
- query ();
+ query (bool cache = true);
template <typename T>
result<T>
- query (const std::string&);
+ query (const char*, bool cache = true);
template <typename T>
result<T>
- query (const odb::query<T>&);
+ query (const std::string&, bool cache = true);
+
+ template <typename T>
+ result<T>
+ query (const odb::query<T>&, 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 <typename T>
inline result<T> database::
- query ()
+ query (bool cache)
{
- return query (odb::query<T> ());
+ return query (odb::query<T> (), cache);
}
template <typename T>
inline result<T> database::
- query (const std::string& q)
+ query (const char* q, bool cache)
{
- return query (odb::query<T> (q));
+ return query (odb::query<T> (q), cache);
+ }
+
+ template <typename T>
+ inline result<T> database::
+ query (const std::string& q, bool cache)
+ {
+ return query (odb::query<T> (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 <typename T>
result<T> database::
- query (const odb::query<T>& q)
+ query (const odb::query<T>& q, bool cache)
{
if (!transaction::has_current ())
throw not_in_transaction ();
- return object_traits<T>::query (*this, q);
+ result<T> r (object_traits<T>::query (*this, q));
+
+ if (cache)
+ r.cache ();
+
+ return r;
}
}