Insert JSON Object to SQLITE Database

Viewed 503

i am trying to insert a json which contains many values i got from cloud into an SQLITE database

I wrote the following:

var listUsers = await response.json(); //This is to pass to listUsers the response i get from the cloud
//Here i remove unecessary fields
        listUsers.items.forEach(user=> {
          delete(user.tenant)
          delete(user.user_admin)
          delete(user.user_owner)
          delete(user.update_date)
          console.log(user); //check what i get
          //Here the code that i guess helps me save the json to database
          db.serialize(() => {
          db.run(`INSERT INTO users VALUES`, JSON.stringify(user[![enter image description here][1]][1]));
          })  
          });
         } catch (error) {
           console.log(error);
         }
         };

Here is for example what i want to save (of course i have many)

enter image description here

I tried codes like :

db.run(`INSERT INTO users VALUES`, { user });

Or

db.run(`INSERT INTO users VALUES(uid, first_name, last_name, birth_date, code, birthsex)`, patient);

But nothing seems to work i get this as an error : enter image description here

Can you please help me ? I know there is json1 for sqlite and json but couldn't make it work, and i tried db.push unsuccessfully.. Thank you

0 Answers
Related