You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
#include "crow.h"
|
|
|
|
#include <driver.h>
|
|
#include <statement.h>
|
|
|
|
using namespace sql;
|
|
using namespace std;
|
|
|
|
Driver *driver;
|
|
Connection *con;
|
|
Statement *stmt;
|
|
|
|
void exiting(){
|
|
delete con;
|
|
delete stmt;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
crow::SimpleApp app;
|
|
|
|
driver = get_driver_instance();
|
|
con = driver->connect(getenv("DBURL"),getenv("DBUSER"),getenv("DBPWD"));
|
|
con->setSchema("practice");
|
|
stmt = con->createStatement();
|
|
|
|
CROW_ROUTE(app, "/summary")([](){
|
|
crow::json::wvalue entries;
|
|
|
|
ResultSet *res = stmt->executeQuery("SELECT * FROM summary ORDER BY chunks_practiced ASC;");
|
|
|
|
int i = 0;
|
|
while (res->next()) {
|
|
int category_id = res->getInt("category_id");
|
|
string category = res->getString("category");
|
|
string instrument = res->getString("instrument");
|
|
double chunks_practiced = res->getDouble("chunks_practiced");
|
|
int weight = res->getInt("weight");
|
|
entries[i] = {{"category_id", category_id}, {"category", category}, {"instrument", instrument}, {"chunks_practiced", chunks_practiced}, {"weight", weight}};
|
|
i++;
|
|
}
|
|
|
|
delete res;
|
|
return entries;
|
|
});
|
|
|
|
app.port(18080).run();
|
|
|
|
atexit(exiting);
|
|
}
|
|
|