Import data from SQL Server to Collection

I need to import data from a SQL Server table to a Collection. I’m using a Rest API and have not problems if there are very few records, but when I try to import 300 records only I get about 200.
I use this code in the page:

export async function RefreshInventario(event)
{
//Insert data from Rest Api into Collection
let idClienteSel = $w(‘#inputIdCliente’).value;

getInventarioSel(idClienteSel) 
.then( AllInfo => 
{ 

const cantRegistros = AllInfo.lenght;

for ( var i = 0; i < AllInfo.length; i++)
{
let toInsert =
{
“idCliente”: i,
//“idCliente”: AllInfo[i].IdCliente,
“nombreCliente”: AllInfo[i].NombreCliente,
“entradaNo”: AllInfo[i].EntradaNo,
“mp_esp”: AllInfo[i].MP_Esp
};

            wixData.insert("colInventario", toInsert) 
            .then(results => 
            { 

let item = results;
})
. catch (err =>
{
let errorMsg = err;
})
}
})
}

And it uses getInventarioSel from this backend function:

export async function getInventarioSel(idClienteTxt)
{
let idCliente = parseInt(idClienteTxt,10)
//https://restclaripack.azurewebsites.net/api/inventario?IdCliente=198
const url = ‘https://restclaripack.azurewebsites.net/api/inventario?IdCliente=’ + idCliente;
console.log("Url: " + url);

try
{
console.log(“fun getInventarioSel”);
let response = await fetch (url, {method: ‘get’});
let data = await response.json();
return data;
}
catch (err)
{
console.log(err)
}
}

I read that I should use async/await but I don’t understand where I have to use it.
Please somebody can help me???

This has come up several times. What you do now is creating traffic per row. That tends to be too much, The usual answers is this; get the amount of rows (you do that), devide it up in chuncks, like 50 or 100), read them, buffer them in memory and then use bulkinsert to write all 50 or 100 of them at once. That way, you create less I/O.

Thank you Giri. I’ll try your solution.
But I wonder if there is another solution working with promises? I will develop my pages importing the SQL Server data to collections using a Rest API and then I’ll manipulate the data in the pages using the collections. There are several tables so I’ll have to do the process of import data very often and it need to be as fast as possible.

Giri, I couldn’t use the bulkinsert!!! I’m very new in WIX and I don’t know how to do the steps you advice me. Can you send me the code to do it? Sorry ;(

@avillarg

As Giri has already stated about it coming up before, see Yisrael’s links from a previous post too.

For accessing an external database, refer to the following:
Corvid: Working with External Database Collections
Corvid: Adding and Deleting an External Database Collection
External Database Collections API
Github repository for wix/corvid-external-db-mysql-adapter

@Giri Zano: I need your help again! Could you pleas llok my question in https://www.wix.com/corvid/forum/community-discussion/bulkremove
I’m very frustrated!

@givemeawhisky : I need your help again! Could you please look my question in https://www.wix.com/corvid/forum/community-discussion/bulkremove
I’m very frustrated!