json - Unable to update table in Advanced Data Persistence mode -


i have issue related database. working gupshup bot programming. there 2 different data persistence modes can read here , here. in advanced data persistence, following code documeneted put data data base

function messagehandler(context, event) {       if(event.message=='update bug - 1452') {          jiraupdate(context);     }           }    function jiraupdate(context){        //connect jira , check latest update , values        if(true){       context.simpledb.doput("1452" ,"{\"status\":\"qa pending\",\"lastupdated\":\"06\/05\/2016\",\"username\":\"john\",\"comment\":\"dependent on builds team provide right build\"}"); } else{          context.sendresponse('no new updates'); }   } function dbputhandler(context, event) {       context.sendresponse("new update in bug, type in bug id see update");      }  

if want change 1 of column (say status or last updated) in table row key value 1452, unable that. how can done?

i used following code:

function messagehandler(context, event) {     // var nlptoken = "xxxxxxxxxxxxxxxxxxxxxxx";//your api.ai token     // context.sendresponse(json.stringify(event)); if(event.message=='deposit') {          context.sendresponse("enter amount deposited");     }       if(event.message=="1000") {         jiraupdate(context);     }      if(event.message== "show"){ context.simpledb.doget("1452");      } }  function httpresponsehandler(context, event) {            var datejson = json.parse(event.getresp);            var date = datejson.date;            context.sendresponse("today's date : "+date+":-)");        }  function jiraupdate(context){        //connect jira , check latest update , values        if(true){       context.simpledb.doput("aaa" ,"{\"account_number\":\"90400\",\"balance\":\"5800\"}"); } else{          context.sendresponse('no new updates'); }   }  /** functions declared below required **/ function eventhandler(context, event) {     if (!context.simpledb.botleveldata.numinstance)         context.simpledb.botleveldata.numinstance = 0;     numinstances = parseint(context.simpledb.botleveldata.numinstance) + 1;     context.simpledb.botleveldata.numinstance = numinstances;     context.sendresponse("thanks adding me. are:" + numinstances); }    function dbgethandler(context, event) {     var bugobj = json.parse(event.dbval);              var bal = bugobj.balance;   var acc = bugobj.account_number;   context.sendresponse(bal);   var = parseint (bal,10);   var b = +1000;   var num = b.tostring();   context.simpledb.doput.aaa.balance = num;   }  function dbputhandler(context, event) {     context.sendresponse("testdbput keyword last put by:" + event.dbval); } 

since hosted db provided gupshup dynamodb of aws. hence can enter key, value pair.

hence have set right key while using doput method store data database , use same key data database using doget method.

to update data should first call doget method , update json right data , call doput method update database latest data.

i have added not present in documentation, can make db calls , choose function response goes to.

i refactoring example using 3 keywords , hard coding few things example -

  1. have - update database these values

    {"account_number":"90400","balance":"5800"}

  2. deposit - on this, code add 1000 balance

  3. show - on this, code show balance user.

code -

function messagehandler(context, event) {  if(event.message=='have') {     var data = {"account_number":"90400","balance":"5800"};       context.simpledb.doput(event.sender,json.stringify(data),insertdata); //using event.sender keep key unique       return;     } if(event.message=="deposit") {    context.simpledb.doget(event.sender, updatedata);     return; } if(event.message== "show"){ context.simpledb.doget(event.sender); return;     } } function insertdata(context){     context.sendresponse("i have data now. update \"deposit\""); } function updatedata(context,event){   var bugobj = json.parse(event.dbval);    var bal = bugobj.balance;   var = parseint(bal,10);   var b = + 1000;   var num = b.tostring();   bugobj.balance = num;   context.simpledb.doput(event.sender,bugobj); }  function eventhandler(context, event) {     if (!context.simpledb.botleveldata.numinstance)         context.simpledb.botleveldata.numinstance = 0;     numinstances = parseint(context.simpledb.botleveldata.numinstance) + 1;     context.simpledb.botleveldata.numinstance = numinstances;     context.sendresponse("thanks adding me. are:" + numinstances); }  function dbgethandler(context, event) {      var accountobj = json.parse(event.dbval);      context.sendresponse(accountobj); }  function dbputhandler(context, event) {     context.sendresponse("i have updated data. \"show\" view data."); } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -