From b9fe963646367f2da21ba1053bc086bd17b09967 Mon Sep 17 00:00:00 2001
From: Boris Kolpackov 9.2 Value Type Pragmas
@@ -3594,7 +3595,7 @@ private:
the order information. In the example above, for instance, the order
of person's nicknames is probably not important. To instruct the ODB
compiler to ignore the order in ordered containers we can use the
-
- 9.2.1 type
- 9.2.2 not_null
- 9.2.3 unordered
- 9.2.4 index_type
- 9.2.5 key_type
- 9.2.6 value_type
- 9.2.7 id_column
- 9.2.8 index_column
- 9.2.9 key_column
+ 9.2.10 value_column
+ 9.2.2 id_type
+ 9.2.3 not_null
+ 9.2.4 unordered
+ 9.2.5 index_type
+ 9.2.6 key_type
+ 9.2.7 value_type
+ 9.2.8 id_column
+ 9.2.9 index_column
+ 9.2.10 key_column
9.2.11 value_column
db unordered
pragma (Section 9.2.3,
+ db unordered
pragma (Section 9.2.4,
"unordered
", Section 9.3.8,
"unordered
"). For example:
id_type
not_null
NULL
unordered
index_type
key_type
value_type
id_column
index_column
key_column
value_column
mapping
example in the odb-examples
package shows how to do this for all the supported database systems.
- not_null
id_type
The id_type
specifier specifies the native database type
+ that should be used for data members of this type that are designated as
+ object identifiers (Section 9.3.1,
+ "id
"). In combination with the type
+ specifier (Section 9.2.1, "type
")
+ id_type
allows you to map a C++ type differently depending
+ on whether it is used in an ordinary member or an object id. For
+ example:
+#pragma db value(std::string) type("TEXT NOT NULL") \ + id_type("VARCHAR(128) NOT NULL") + +#pragma db object +class person +{ + ... +private: + #pragma db id + std::string email_; // Mapped to VARCHAR(128) NOT NULL. + + std::string name_; // Mapped to TEXT NOT NULL. +}; ++ +
Note that there is no corresponding member type specifier for
+ id_type
since the desired result can be achieved
+ with just the type
specifier, for example:
+#pragma db object +class person +{ + ... +private: + #pragma db id type("VARCHAR(128) NOT NULL") + std::string email_; + ... +}; ++ +
not_null
The not_null
specifier specifies that an object pointer
or a container of object pointers cannot have or contain the
@@ -5727,7 +5777,7 @@ typedef std::vector<shared_ptr<account> > accounts;
For a more detailed discussion of the NULL
object pointer
semantics, refer to Chapter 6, "Relationships".
unordered
unordered
The unordered
specifier specifies that the ordered
container should be stored unordered in the database. The database
@@ -5744,7 +5794,7 @@ typedef std::vector<std::string> names;
storage in the database, refer to Section 5.1,
"Ordered Containers".
index_type
index_type
The index_type
specifier specifies the native
database type that should be used for an ordered container's
@@ -5758,7 +5808,7 @@ typedef std::vector<std::string> names;
#pragma db value(names) index_type("SMALLINT UNSIGNED NOT NULL")
-
key_type
key_type
The key_type
specifier specifies the native
database type that should be used for a map container's
@@ -5772,7 +5822,7 @@ typedef std::map<unsigned short, float> age_weight_map;
#pragma db value(age_weight_map) key_type("INT UNSIGNED NOT NULL")
-
value_type
value_type
The value_type
specifier specifies the native
database type that should be used for a container's
@@ -5786,7 +5836,7 @@ typedef std::vector<std::string> names;
#pragma db value(names) value_type("VARCHAR(255) NOT NULL")
-
id_column
id_column
The id_column
specifier specifies the column
name that should be used to store the object id in a
@@ -5800,7 +5850,7 @@ typedef std::vector<std::string> names;
If the column name is not specified, then object_id
is used by default.
index_column
index_column
The index_column
specifier specifies the column
name that should be used to store the element index in an
@@ -5814,7 +5864,7 @@ typedef std::vector<std::string> names;
If the column name is not specified, then index
is used by default.
key_column
key_column
The key_column
specifier specifies the column
name that should be used to store the key in a map
@@ -5828,7 +5878,7 @@ typedef std::map<unsigned short, float> age_weight_map;
If the column name is not specified, then key
is used by default.
value_column
value_column
The value_column
specifier specifies the column
name that should be used to store the element value in a
--
cgit v1.1