I am currently writing a C ++ application where I need to connect to a SQLite database. I am looking for a library and found SOCI, and I have to say: I like it. The flow syntax and mapping is so awesome. But I have one problem:
I have an Event class, and I wrote parser functions for it:
template<> struct type_conversion<Event>
{
typedef values base_type;
static void from_base(const values& v, indicator , Event& event)
{
event.m_id = v.get<std::string>("id");
event.m_title = v.get<std::string>("Title");
event.m_description = v.get<std::string>("Description");
event.m_date = v.get<std::tm>("Date");
}
static void to_base(const Event& event, values& v, indicator& ind)
{
v.set("id", event.m_id);
v.set("Title", event.m_title);
v.set("Description", event.m_description);
v.set("Date", event.m_date);
ind = i_ok;
}
};
This is great for queries like this:
sql << "SELECT * FROM Event WHERE id=5", into(event);
I would like to highlight most of the events in std::vector<Event*>, but if I try to do it with
std::vector<Event*> events;
sql << "SELECT * FROM Event", into(events)
But with this, I get the following compiler error:
No known convertation from
soci::details::conversion_into_type<std::vector<Event>> into
soci::details::into_type_base
Is it not possible with SOCI, or am I missing something? I also found OTL as a library. Perhaps this is a good alternative? As I said, I like the SOCI path. Is this possible with OTL?