Skip to content

Commit aedf02f

Browse files
Added documentation
1 parent 9d06bcc commit aedf02f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

docs/dynamic.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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

5077
You can then automatically generate random UUIDs:

0 commit comments

Comments
 (0)