0
tx.executeSql("insert into Users (id, idNumber, uName) values (?,?,?)", [i,data.user[i].id, data.user[i].name],successCB,errorCB);

Is it possible to add multiple rows(objects) in JSON at runtime so that JSON can be passed to generate bulk data in single MySQL INSERT query?

ElasticCode
  • 7,311
  • 2
  • 34
  • 45

1 Answers1

0

Sure it's possible. Let's start with a basic data object:

let data = { user: [] }

Now we can just loop it 20k times, and append random data:

for(let i = 0; i < 20000; i++) {
    data.user.push({id: i, name: makeid() })
}

If you need it in JSON:

let json_data = JSON.stringify(data)

Please note, this example uses makeid() from this thread on generating random strings, but you can use anything you want for that.

  • A good library for seeding information is [faker](https://www.npmjs.com/package/faker) – Phix Apr 10 '18 at 21:12