aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-22 11:47:55 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-22 11:47:55 +0200
commit1feaef1c1e2c8daba97b20e1fb012706c6adf1ce (patch)
treea3c7f577e7019a14e45990d50a8b0da1c294e9e4 /odb
parent5b6649e6f7dd256147b48197a007c23001cef647 (diff)
Add database::erase_query() function
New test: common/erase-query. Documentation is in Section 3.9, "Deleting Persistent Objects". The current implementation does not work well with the session (no removal of the erased objects from the cache).
Diffstat (limited to 'odb')
-rw-r--r--odb/database.hxx18
-rw-r--r--odb/database.ixx33
-rw-r--r--odb/database.txx15
3 files changed, 66 insertions, 0 deletions
diff --git a/odb/database.hxx b/odb/database.hxx
index c4458d9..2e6c79d 100644
--- a/odb/database.hxx
+++ b/odb/database.hxx
@@ -125,6 +125,24 @@ namespace odb
void
erase (const typename object_traits<T>::pointer_type& obj_ptr);
+ // Erase multiple objects matching a query predicate.
+ //
+ template <typename T>
+ unsigned long long
+ erase_query ();
+
+ template <typename T>
+ unsigned long long
+ erase_query (const char*);
+
+ template <typename T>
+ unsigned long long
+ erase_query (const std::string&);
+
+ template <typename T>
+ unsigned long long
+ erase_query (const odb::query<typename object_traits<T>::object_type>&);
+
// Query API.
//
template <typename T>
diff --git a/odb/database.ixx b/odb/database.ixx
index a308bfe..ccbbe41 100644
--- a/odb/database.ixx
+++ b/odb/database.ixx
@@ -170,6 +170,39 @@ namespace odb
}
template <typename T>
+ inline unsigned long long database::
+ erase_query ()
+ {
+ // T can be const T while object_type will always be T.
+ //
+ typedef typename odb::object_traits<T>::object_type object_type;
+
+ return erase_query<T> (odb::query<object_type> ());
+ }
+
+ template <typename T>
+ inline unsigned long long database::
+ erase_query (const char* q)
+ {
+ // T can be const T while object_type will always be T.
+ //
+ typedef typename odb::object_traits<T>::object_type object_type;
+
+ return erase_query<T> (odb::query<object_type> (q));
+ }
+
+ template <typename T>
+ inline unsigned long long database::
+ erase_query (const std::string& q)
+ {
+ // T can be const T while object_type will always be T.
+ //
+ typedef typename odb::object_traits<T>::object_type object_type;
+
+ return erase_query<T> (odb::query<object_type> (q));
+ }
+
+ template <typename T>
inline result<T> database::
query (bool cache)
{
diff --git a/odb/database.txx b/odb/database.txx
index 832c7ad..e60d7a8 100644
--- a/odb/database.txx
+++ b/odb/database.txx
@@ -208,6 +208,21 @@ namespace odb
}
template <typename T>
+ unsigned long long database::
+ erase_query (const odb::query<typename object_traits<T>::object_type>& q)
+ {
+ // T can be const T while object_type will always be T.
+ //
+ typedef typename odb::object_traits<T>::object_type object_type;
+ typedef odb::object_traits<object_type> object_traits;
+
+ if (!transaction::has_current ())
+ throw not_in_transaction ();
+
+ return object_traits::erase_query (*this, q);
+ }
+
+ template <typename T>
result<T> database::
query (const odb::query<typename object_traits<T>::object_type>& q,
bool cache)