Quantcast
Viewing all articles
Browse latest Browse all 70875

Populate SQL from JSON...faster?

@arfons wrote:

I have a JSON I get from an API which I iterate through with some simple loops and then feed data to some SQL inserts to populate some tables, which are divided by models. The current method works like this:

.js:
...
processed_data = data.json();

if (processed_data.products) {
    for (let i = 0; i < processed_data.products.length; i++) {
        promises.push(this.product.addItemSQL(processed_data.products[i]));
    }
}
...

( I do promises.push instead of running the functions as is because I need to wait until all the inserts are done to go to the next page )
And then in the model I have the addItemSQL funciton which is just:

return this.platform.ready().then(() => {
    return this.db.query("INSERT INTO ...");
},(error) => {
});

But the result is that it's rather slow; apparently I can use transactions to speed up these inserts, but I'm unsure how.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70875

Trending Articles