sqlite_orm
sqlite_orm copied to clipboard
std::vector<std::string> class member
class Vect { std::vectorstd::string _Vec; };
decltype(auto) GetStorage() { return make_storage( "Vector", make_table("vec", make_column("R", &Vect::_Vec) ) ); }
How to store and restore std::vector in and from database?
This is a good question. First you have to decide how would you store it without sqlite_orm but with pure sqlite3. The problem is that there is no string array type in sqlite or varray just like Oracle DB has. Please check a question here. But you have two options to do a trick.
- Store string in a different table with id foreign key per every string. Something similar can be found in subentities.cpp example
- Serialize string array somehow on insert. In JSON probably. Parse it on select. There is a very comfortable json lib here.
Thanks, I am planning to store it as comma separated strings.