How do I do a bulk insert of data from a table into my table in a database?

Comments

1 comment

  • Avatar
    Mike O'Connor

    Dont know if you still need help but there is a few ways I have been able to do this. The way that works best for me is to loop through the table and do a separate PUT/POST request similar to the solution you posted. I like this way because then i can check if I need to do a PUT or POST depending on if the record exists already:

    Downsides:

    you are doing multiple PUT/POST requests instead of one bulk request

    you might want to check if your data has changed before doing a useless PUT request

     

    Here is some pseudoish code:

    for (var i=0; i< table.value.length; ++i) {
    //If record already exists, do PUT
    if (ID[i].value !== '') {
    var modifyRecord = {
    COLUMN1: COLUMN1.value,
    COLUMN2: COLUMN2.value,
    }
    http.put('http://<YOURSERVER>:8082/database/<YOURQUERYSET>/<YOURUPDATEQUERY>?id=' + ID[i].value, modifyRecord);
    }
    //If record dosent exists, do POST
    else {
    var newRecord = {
    ID: frevvo.uuid(),
    COLUMN1: COLUMN1.value,
    COLUMN2: COLUMN2.value,
    }
    http.post('http://<YOURSERVER>:8082/database/<YOURQUERYSET>/<YOURINSERTQUERY>', newRecord);
    }
    }

     

    0
    Comment actions Permalink

Please sign in to leave a comment.