Skip to content

Instantly share code, notes, and snippets.

@marty1885
Created Nov 12, 2022
Embed
What would you like to do?
int main() {
drogon::app().addListener("0.0.0.0",5000);
drogon::app().loadConfigFile("../config.json");
drogon::app().registerHandler("/twitter?user_id={1}&type={2}&phrase={3}&hashtag={4}",
[](const drogon::HttpRequestPtr &req,
std::function<void (const drogon::HttpResponsePtr &)> &&callback,
const std::string &a, const std::string &b, const std::string &c, const std::string &d){
auto clientPtr = drogon::app().getDbClient();
auto resp=drogon::HttpResponse::newHttpResponse();
clientPtr->execSqlAsync("select * from test_table limit 5",
[](const drogon::orm::Result &result) {
std::cout << result.size() << " rows selected!" << std::endl;
int i = 0;
for (auto row : result)
{
std::cout << i++ << ": user name is " << row["id"].as<std::string>() << std::endl;
}
},
[](const drogon::orm::DrogonDbException &e) {
std::cerr << "error in main.cc:" << e.base().what() << std::endl;
});
resp->setBody("2");
callback(resp);
});
drogon::app().run();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment