diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-20 16:05:01 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-20 16:05:01 +0200 |
commit | 2d3d20ee4e3ce52d6a2b235e86aa3fa63fe61611 (patch) | |
tree | 54f5b2a074c997c9f762147c65b1b9406a63d0bb | |
parent | 4ecaf6e91c2f1107f855c93fc2e0e4efb03c4cb0 (diff) |
Add persist(const) version, make update()'s argument const
-rw-r--r-- | odb/database.hxx | 6 | ||||
-rw-r--r-- | odb/database.txx | 15 |
2 files changed, 19 insertions, 2 deletions
diff --git a/odb/database.hxx b/odb/database.hxx index ab80da4..4858f0f 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -35,6 +35,10 @@ namespace odb // template <typename T> typename object_traits<T>::id_type + persist (const T& object); + + template <typename T> + typename object_traits<T>::id_type persist (T& object); // Throw object_not_persistent if not found. @@ -61,7 +65,7 @@ namespace odb // template <typename T> void - update (T& object); + update (const T& object); // Make the object transient. Throw object_not_persistent if not // found. diff --git a/odb/database.txx b/odb/database.txx index f5449b6..a94f471 100644 --- a/odb/database.txx +++ b/odb/database.txx @@ -10,6 +10,19 @@ namespace odb { template <typename T> typename object_traits<T>::id_type database:: + persist (const T& obj) + { + typedef object_traits<T> traits; + + if (!transaction::has_current ()) + throw not_in_transaction (); + + traits::persist (*this, obj); + return traits::id (obj); + } + + template <typename T> + typename object_traits<T>::id_type database:: persist (T& obj) { typedef object_traits<T> traits; @@ -64,7 +77,7 @@ namespace odb template <typename T> void database:: - update (T& obj) + update (const T& obj) { if (!transaction::has_current ()) throw not_in_transaction (); |