How to perform bulk operations with help of SQL Agent?

Fri Aug 18 2017 09:53:24 GMT+0200 (CEST), Peter Širka

How to perform bulk operations in SQL Agent?

// .limit() paginates Array by 50 items
some_array.limit(50, function(items, next) {

    var sql = DB();
    var builder = [];

    // Creates raw SQL queries
    for (var i = 0, length = items.length; i < length; i++) {
        var item = items[i];
        builder.push('INSERT INTO tbl_products (id, name, price) VALUES({0},{1},{2})'.format(sql.escape(item.id), sql.escape(item.name), sql.escape(item.price)));
    }

    // Runs one big query
    sql.query(builder.join('\n'));
    sql.exec(function(err) {
        err && console.error(err);

        // Process next 50 pieces
        next();
    });

}, () => console.log('DONE'));

Tags

Follow us

Latest blogs
Total.js Dashboard v6.0
Mon Apr 23 2018 16:05:59 GMT+0200 (CEST)
Flow v5.0.0
Mon Apr 16 2018 12:32:11 GMT+0200 (CEST)
REST Azure DocumentDB in Node.js / Total.js
Mon Mar 26 2018 09:38:41 GMT+0200 (CEST)
How do I transform ErrorBuilder output?
Mon Jan 29 2018 09:22:49 GMT+0100 (CET)
Flow: REST API components
Mon Jan 22 2018 10:11:14 GMT+0100 (CET)

Latest comments
Not only for Total.js. You can communicate with different websocket servers.
Peter Širka
Mon Apr 23 2018 20:08:20 GMT+0200 (CEST)
hellow every one
umar
Sun Apr 22 2018 10:05:35 GMT+0200 (CEST)
hehehshshshshdhsd
Amaury
Sat Mar 24 2018 19:46:54 GMT+0100 (CET)
asdasd
getrgerg
Tue Mar 20 2018 15:07:31 GMT+0100 (CET)
Is WEBSOCKETCLIENT only for internal ws connections between totaljs apps?
Stelios Stephanua
Fri Mar 16 2018 06:04:22 GMT+0100 (CET)
Total.js is amazing! ;)
Leonardo Hessel
Tue Dec 19 2017 19:51:15 GMT+0100 (CET)
It's easy, just set e.g. `res.status = 404`.
Peter
Thu Nov 16 2017 07:54:11 GMT+0100 (CET)
Yes, it's valid.
Peter
Thu Nov 16 2017 07:53:06 GMT+0100 (CET)
How do we set the status code in custome middleware?
Nabeel
Mon Oct 02 2017 10:31:40 GMT+0200 (CEST)
Node... Awesome applications.
oscar
Thu Aug 31 2017 02:21:59 GMT+0200 (CEST)
Awesome!
Tema
Wed May 10 2017 06:33:13 GMT+0200 (CEST)
Awesome, thanks!
Tema
Tue May 02 2017 14:13:03 GMT+0200 (CEST)