summaryrefslogtreecommitdiff
path: root/common/id/auto/test.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-07-03 18:23:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-07-03 18:23:51 +0200
commit0d65234bc5c6742721c00360a0e3117d51d89c5f (patch)
tree000052c43d9676077a7216c28b23683f001be56e /common/id/auto/test.hxx
parentdb1bec04ae8b70281c61ffc468126445a612ae28 (diff)
Implement nested id support
Now the 'id' specifier can optionally include the data member path to the id inside the composite value. For example: #pragma db id(first) std::pair<int, int> p; Note that one somewhat counter-intuitive aspect of this new feature is that the whole member marked with id ('p' in the above example) and not just the actual id member ('p.first' in the above example) is treated as readonly. Such nested id also cannot be automatically assigned (auto specifier).
Diffstat (limited to 'common/id/auto/test.hxx')
-rw-r--r--common/id/auto/test.hxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/common/id/auto/test.hxx b/common/id/auto/test.hxx
new file mode 100644
index 0000000..1605cfe
--- /dev/null
+++ b/common/id/auto/test.hxx
@@ -0,0 +1,41 @@
+// file : common/id/auto/test.hxx
+// copyright : Copyright (c) 2009-2015 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <string>
+
+#include <odb/core.hxx>
+
+#pragma db object
+struct object
+{
+ object (const std::string& str)
+ : id_ (1), str_ (str)
+ {
+ }
+
+ #pragma db auto id
+ unsigned long id_;
+ std::string str_;
+
+private:
+ object ()
+ {
+ }
+
+ friend class odb::access;
+};
+
+// Test the case where the object has just the auto id.
+//
+#pragma db object
+struct auto_only
+{
+ #pragma db auto id pgsql:type("BIGINT")
+ unsigned short id_;
+};
+
+#endif // TEST_HXX