[odb-users] sqlite string type std::array
Boris Kolpackov
boris at codesynthesis.com
Wed Aug 19 12:27:26 EDT 2015
Hi,
MM <finjulhich at gmail.com> writes:
> typedef std::array<char,5> month_year_str_t;
> struct month_and_year
> { ...
> operator month_year_str_t() const;
> void set(month_year_str_t);
> };
>
> struct myobj
> {
> ...
> month_and_year my;
> };
>
>
> I would like to map the month_and_year type to a TEXT column in sqlite, and
> use the provided conversion operator to do that.
> What's the simplest way?
>
> #pragma db value(month_year_str_t) type("TEXT")
>
> #pragma db object(myobj) definition
> #pragma db member(myobj::my) transient
> #pragma db member(myobj::monthyear) virtual(month_year_str_t) \
> get( static_cast<month_year_str_t>(this.my) ) \
> set( set ((?)))
This is the simplest. In 2.5.0 you will be able to do this mapping
for the month_and_year type instead of having to do it for each data
member. The other option would be to map month_and_year directly to
TEXT by specializing odb::sqlite::value_traits. See "Custom C++ to
Database Type Mapping" on how to do this:
http://www.codesynthesis.com/~boris/blog/2012/10/16/custom-cxx-to-database-type-mapping-in-odb/
Boris
More information about the odb-users
mailing list