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

How to get all rows from table using sql_orm ? #11

Closed
adibro500 opened this issue May 14, 2020 · 22 comments
Closed

How to get all rows from table using sql_orm ? #11

adibro500 opened this issue May 14, 2020 · 22 comments

Comments

@adibro500
Copy link

adibro500 commented May 14, 2020

How to get all rows from table using sql_orm ? Please guide me here
error: 'struct li::mysql_result<li::mysql_functions_blocking>' has no member named 'map' 29 | connection("Select id,time from items_table;").map([&] (std::string id, std::string time) {

Getting the above error
Thanks,
adibro500

@matt-42
Copy link
Owner

matt-42 commented May 14, 2020 via email

@adibro500
Copy link
Author

Not working with sql commands.

con("select name, age from users;").map([] (std::string name, int age) { std::cout << name << ":" << age << std::endl; });

This example not working.

@matt-42
Copy link
Owner

matt-42 commented May 14, 2020 via email

@adibro500
Copy link
Author

using mysql

@adibro500
Copy link
Author

Also I am getting CORS error

@adibro500
Copy link
Author

the Access-Control-Allow-Origin working only in get apis

@matt-42
Copy link
Owner

matt-42 commented May 14, 2020

Use the prepared statement api for the map method:

connection.prepare("Select id,time from items_table;").map([...])

I'll add an issue to have the map method on the non prepared mysql queries.

@matt-42
Copy link
Owner

matt-42 commented May 14, 2020 via email

@adibro500
Copy link
Author

Getting this error:
error: 'struct li::mysql_statement<li::mysql_functions_blocking>' has no member named 'map'

@matt-42
Copy link
Owner

matt-42 commented May 15, 2020

Sorry I forgot to call the prepared statement, use this instead:
connection.prepare("Select id,time from items_table;")().map([...])

@adibro500
Copy link
Author

adibro500 commented May 16, 2020

getting this error :

/usr/local/include/c++/9.3.0/tuple:1277:29: error: incomplete type 'std::tuple_size<main()::<lambda(li::http_request&, li::http_response&)>::<lambda(std::string&, std::string&, std::string, std::string&, std::string&)> >' used in nested name specifier 1277 | inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value; | ^~~~~~~~~~~~

Can you post the complete expression ? Like what to be passed in map function ?

@matt-42
Copy link
Owner

matt-42 commented May 16, 2020

can you share the code that generated this error ?

@adibro500
Copy link
Author

adibro500 commented May 16, 2020

This code caused the error:

db.connect().prepare("Select id,post from post_items;")().map([&](std::string id, std::string post) {

});

what i am doing wrong ?

Please look at my most recent edit

@matt-42
Copy link
Owner

matt-42 commented May 21, 2020

Do you still have this compilation error ? I've added a test and it seems to compile and work fine on my computer. (But it fails on travis, still have to find why...):
https://github.com/matt-42/lithium/blob/master/libraries/sql/tests/mysql.cc#L53

@adibro500
Copy link
Author

which compiler and compiler version you are using ?

@adibro500
Copy link
Author

I am using gcc version 9.3.0

@matt-42
Copy link
Owner

matt-42 commented May 24, 2020

I also have gcc 9.3.0, can you share a simple c++ pease of code that would allow me to reproduce the error ?

@adibro500
Copy link
Author

adibro500 commented May 24, 2020

db.connect().prepare("Select id,post from post_items;")().map([&](std::string id, std::string post) {

});

@matt-42
Copy link
Owner

matt-42 commented May 24, 2020

this code is right, the error must come from somewhere else. If you want me to help more please share a c++ file that I can compile myself.

@matt-42
Copy link
Owner

matt-42 commented May 25, 2020

Also note that on master the non prepared query API is finished.
You can now use:

db.connect()("Select id,post from post_items;").map([&](std::string id, std::string post) {

});

@matt-42
Copy link
Owner

matt-42 commented May 31, 2020

Did you succeed ? can we close this issue ?

@adibro500
Copy link
Author

Yes working

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

2 participants