From 0374af511d7efdb856af372f126e66e5a78841d7 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 19 Jul 2015 20:02:00 +0200 Subject: o Applying clang-format to all apps. --- apps/sm-db-insert.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'apps/sm-db-insert.h') diff --git a/apps/sm-db-insert.h b/apps/sm-db-insert.h index b786e41..7e08268 100644 --- a/apps/sm-db-insert.h +++ b/apps/sm-db-insert.h @@ -8,13 +8,12 @@ namespace trygvis { namespace apps { -template +template using o = boost::optional; using namespace std; using json = nlohmann::json; class sm_db_insert : public app { - public: sm_db_insert() : app("sm-db-insert") { } @@ -22,8 +21,7 @@ public: ~sm_db_insert() = default; void add_options(po::options_description_easy_init &options) override { - options - ("file", po::value()->required(), "The file to read"); + options("file", po::value()->required(), "The file to read"); } int main(app_execution &execution) override { @@ -42,31 +40,36 @@ public: string mac = j["mac"]; // "aa:bb:cc:dd:ee:ff"; - auto rs = work.parameterized("select id from soil_moisture_device where mac=$1")(mac).exec(); + auto select_device = "select id from soil_moisture_device where mac=$1"; + auto rs = work.parameterized(select_device)(mac).exec(); if (!rs.size()) { cout << "New device: " << mac << endl; - rs = work.parameterized("insert into soil_moisture_device(mac) values($1) returning id")(mac).exec(); + auto insert_device = "insert into soil_moisture_device(mac) values($1) returning id"; + rs = work.parameterized(insert_device)(mac).exec(); } auto deviceId = rs.begin()["id"].as(); int sensor = j["sensor"]; - rs = work.parameterized("select id from soil_moisture_sensor where device=$1 and sensor=$2")(deviceId)(sensor).exec(); + auto select_sensor = "select id from soil_moisture_sensor where device=$1 and sensor=$2"; + rs = work.parameterized(select_sensor)(deviceId)(sensor).exec(); if (!rs.size()) { cout << "New sensor: " << sensor << endl; - rs = work.parameterized("insert into soil_moisture_sensor(device, sensor) values($1, $2) returning id")(deviceId)(sensor).exec(); + auto insert_sensor = "insert into soil_moisture_sensor(device, sensor) values($1, $2) returning id"; + rs = work.parameterized(insert_sensor)(deviceId)(sensor).exec(); } auto sensorId = rs.begin()["id"].as(); unsigned long timestamp = get(j, "timestamp"); unsigned int value = get(j, "value"); - work.parameterized("insert into soil_moisture_sample(sensor, timestamp, value) values($1, $2, $3)")(sensorId)(timestamp)(value).exec(); + auto insert_sample = "insert into soil_moisture_sample(sensor, timestamp, value) values($1, $2, $3)"; + work.parameterized(insert_sample)(sensorId)(timestamp)(value).exec(); cout << "Sample inserted" << endl; @@ -75,6 +78,5 @@ public: return EXIT_SUCCESS; } }; - } } -- cgit v1.2.3