alexiusacademia / electron-db

Electron module that acts as database management and uses flat file database (json file) to store tables.
MIT License
87 stars 24 forks source link

Cannot find the specified record. #12

Closed jesusgvn closed 5 years ago

jesusgvn commented 5 years ago

Hi.I can't understand why this is happening. sorry for bad english

Code:

//about such a code is transmitted

var e = { 
            coords:[ [ 40.512722476180485, 68.77368450164796 ],
                        [ 40.50528313168216, 68.77432823181154 ],
                        [ 40.509590221186414, 68.78304004669191 ] ],
            info: [ 'second', '#2c8cd3' ],
            id: 1542267016734 
          }

  let where = {
    "id": e[0]
  };

  let set = {
    "info": e[1]
  };
  db.updateRow('polyZones',{"id": e[0]},{"info": e[1]},function(succ,msg){
    console.log(succ);
    console.log(msg);
  });

JSON Structure

{
  "polyZones": [
    {
      "coords": [
        [
          40.515234699969355,
          68.75501632690431
        ],
        [
          40.50381474249354,
          68.75334262847902
        ],
        [
          40.510960600748795,
          68.76321315765382
        ]
      ],
      "info": [
        "first",
        "#ee4811"
      ],
      "id": 1542267004698
    },
    {
      "coords": [
        [
          40.512722476180485,
          68.77368450164796
        ],
        [
          40.50528313168216,
          68.77432823181154
        ],
        [
          40.509590221186414,
          68.78304004669191
        ]
      ],
      "info": [
        "second",
        "#2c8cd3"
      ],
      "id": 1542267016734
    }
  ]
}

so, when i request item with id "1542267004698"( this is the first object in the json list) request returns true (the object exists). but as soon as I search for an object with a different id it returns false(Cannot find the specified record).

what could be the problem? Maybe there is something wrong in the structure? Thanks for attention. And yes, sorry again for my English: 3

jesusgvn commented 5 years ago

I want to note that this happens only when the object changes. When deleting and searching everything is fine.

alexiusacademia commented 5 years ago

Hi there, is the id your searching still exist? If it does, can I please see the content of your database file? Thanks

ParaSpl01t commented 5 years ago

Shouldn't id be e.coords[0] instead of e[0]?

alexiusacademia commented 5 years ago

Hi there. In the first example, the value of id can be accessed by

e.id

not

e[0]

Same for the info, it can be accessed using

e.info