Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async support work around. #344

Open
scmp197 opened this issue Jul 7, 2020 · 7 comments
Open

Async support work around. #344

scmp197 opened this issue Jul 7, 2020 · 7 comments

Comments

@scmp197
Copy link

scmp197 commented Jul 7, 2020

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?

@rbock
Copy link
Owner

rbock commented Jul 7, 2020

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();

@scmp197
Copy link
Author

scmp197 commented Jul 7, 2020

 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?

@rbock
Copy link
Owner

rbock commented Jul 8, 2020

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?

@anton-potapov
Copy link

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 )

@rbock
Copy link
Owner

rbock commented Sep 15, 2023

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;
}

@anton-potapov
Copy link

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 )

@rbock
Copy link
Owner

rbock commented Sep 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants