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

Embedded json #7

Closed EnOane closed 6 years ago

EnOane commented 6 years ago

Hello.

How can I update row "lala" in electron-db, if I have this:

"equipment": { "lala" :{ "id": "1525272872463", "group": "oil", "name": "Мотопомпа «KLINER»", "inventory": "00-000005/69", "factory": "I205NZP", "release": "2012", "lifetime": "10", "verification": "02/06/2012", "dateOfVerification": "01/01/2020", "stock": "1", "timetable": "1", "notes": "" },

alexiusacademia commented 6 years ago

Hi EnOane, I'm assuming that your table name is "equipment" in equipment.json. Now, first is that the table structure should look something like this,

{
  "equipment" : [
    {
      "row_name": "lala",
      "id": "1525272872463",
      "group": "oil",
      .......
    }
  ]
}

then you update the "lala" row by

const db = require('electron-db');
const electron = require('electron');

const app = electron.app || electron.remote.app;

let where = {
  "row_name": "lala"
};

let set = {
  "notes": "The things that you want to go in here.."
}

db.updateRow('equipment', where, set, (succ, msg) => {
  // succ - boolean, tells if the call is successful
  console.log("Success: " + succ);
  console.log("Message: " + msg);
});
EnOane commented 6 years ago

Thanks you. But I have another question. How I can get "row_name":

{ "equipment" : { "hope": { "row_name": "lala", "id": "1525272872463", "group": "oil" } }

alexiusacademia commented 6 years ago

WHat do you mean "How can u get "row_name"?

By the way, after the "equipment": it should be a list, square brackets instead of curly braces.

EnOane commented 6 years ago
"squads": {
    "firstSquad": {
      "id": "1",
      "name": "I смена",
      "description": "THIS",
      "rescues": [
        {
          "avatar": "/static/rescuers/10.jpg",
          "name": "Бондарев Максим",
          "birthday": "05/08/1984",
          "position": "Командир отделения",
          "dateOfEmployment": "01/02/2016",
          "certificationForGRW": "01/02/2016",
          "certificationForFW": "01/02/2016",
          "certificationForSRW": "01/02/2016",
          "certificationForHW": "1",
          "certificationForHWM": "01/02/2016",
          "docs": {
            "passport": {
              "name": "Паспорт",
              "description": "Документ, удостоверящий личность",
              "path": ""
            },
            "identityCardRescue": {
              "name": "Удостоверение спасателя",
              "description": "Выдается при первой аттестации",
              "path": ""
            },
            "booksRescue": {
              "name": "Книжка спасателя",
              "description": "Выдается вместе с удостоверением",
              "path": ""
            }
          }
        },
      ]
    } .....

How can I get "description"? Path = squads.firstSquad.description

alexiusacademia commented 6 years ago

At the current version of electron-db, you can't, based on the structure of your data.

At the moment, electron-db only support one level object. Which means only one object with the table name and that object contains a list of objects without any sub-level objects.

This is derived from the structure of a relational database where you can only have one level of fields in a table (e.g. "field1", "field2" etc.)

EnOane commented 6 years ago

@alexiusacademia Thanks you very much! )

alexiusacademia commented 6 years ago

Thank you too for the question. That type of data structure on a database could considered in the future version of electron-db @EnOane