File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,6 +45,33 @@ struct Parser<boost::uuids::uuid> {
4545} // namespace sqlgen::parsing
4646```
4747
48+ The second step is to specialize `sqlgen::transpilation::ToValue` for `boost::uuids::uuid` and implement `operator()`:
49+
50+ ```cpp
51+ #include <boost/lexical_cast.hpp>
52+ #include <boost/uuid/uuid.hpp>
53+ #include <boost/uuid/uuid_io.hpp>
54+ #include <sqlgen/dynamic/types.hpp>
55+ #include <sqlgen/transpilation/to_value.hpp>
56+
57+ namespace sqlgen::transpilation {
58+
59+ template <>
60+ struct ToValue<boost::uuids::uuid> {
61+ dynamic::Value operator()(const boost::uuids::uuid& _u) const {
62+ return dynamic::Value{dynamic::String{.val = boost::uuids::to_string(_u)}};
63+ }
64+ };
65+
66+ } // namespace sqlgen::transpilation
67+ ```
68+
69+ This second step is necessary to ensure you can use your type in ` where(...) ` statements
70+ and other conditions.
71+
72+ The return type must always be ` sqlgen::dynamic::Value ` . ` dynamic::Value ` can contain
73+ ` dynamic::String ` (as in this example), ` dynamic::Float ` or ` dynamic::Integer ` .
74+
4875### Using ` boost::uuids::uuid ` in structs
4976
5077You can then automatically generate random UUIDs:
You can’t perform that action at this time.
0 commit comments