sqlpp11
sqlpp11 copied to clipboard
Async support work around.
Hey! Thanks for this library.
I am trying to figure out how to setup sqlpp11 to work with boost asio in an asynchronous manner.
I think for the first pass, I just want to retrieve the string sqlpp11 is passing into the connector libraries and then directly use it to talk to psql.
Is there a way to get at the sql string that the db
object passes to the connector?
Hi, thanks for the feedback. Please let me know how this works out for you!
Something like the following should work % typos:
::sqlpp::postgresql::connection::_serializer_context context;
std::string serialized_query = serialize(query, context).str();
auto query = sqlpp::select(all_of(_w_map))...
::sqlpp::postgresql::connection::_serializer_context_t context(db);
std::string serialized_query = serialize(query, context).str();
^ This works for me. Are there any plans on adding async support to the library? Especially with coroutines. That would be a cool feature.
If I wanted to contribute something like that any starting point you recommend?
Thanks for letting me know!
As of now, I have no plans for adding async support, and I know very little about coroutines. That being said, I believe the best place to start would be the connector libraries and/or the result_t
template. You probably could add a yield
function there?
BTW, How to do the opposite, i.e. parse returned results into C++ objects ? (I did a quick search, but did not mange to find, as unfamiliar with the codebase )
Not sure I understand the question?
The returned results are C++ objects. Each row has data members that have the name of the returned columns, e.g.
for (const auto& row : result) {
std:: cout << row.foo;
}
having this :
::sqlpp::postgresql::connection::_serializer_context context;
std::string serialized_query = serialize(query, context).str();
DSL expression can be serialized into text to be sent (asynchronously) to the DB. Once the reply is received (in text) - it has to be converted to the C++ objects according to DDL. I believe sqlpp does this under the hood.
The question is how to do this explicitly (if I do wish to send query and receive results by myself and use sqlpp to serialize and desirialize )
I see. This very much depends on the individual database and the type of the query. The most prominent result type is an array of char*. These are then parsed.
See for instance include/sqlpp11/sqlite3/bind_result.h
.
Note that these functions are implementation details. While currently stable, they might change any time.