- DBT key;
- DBT data;
- int ret;
-
- const char* value;
-
- struct json_object* args;
- struct json_object* item;
-
- args = afb_req_json(req);
-
- if (!json_object_object_get_ex(args, "value", &item) || !item) value = NULL;
- else value = json_object_get_string(item);
-
- if (!value || !strlen(value))
- {
- afb_req_fail(req, "No value provided.", NULL);
- return;
- }
-
- if (get_key(req, &key))
- return;
-
- AFB_INFO("update: key=%s, value=%s", (char*)key.data, value);
-
- data.data = (void*)value;
- data.size = (uint32_t)strlen(value);
-
- if ((ret = database->put(database, NULL, &key, &data, 0)) == 0)
- afb_req_success_f(req, NULL, "db success: update %s=%s.", (char*)key.data, (char*)data.data);
- else
- afb_req_fail_f(req, "Failed to update datas.", "db fail: update %s=%s - %s", (char*)key.data, (char*)data.data, db_strerror(ret));