Pg-promise: Generate tasks list with array of tables names

Created on 23 Jan 2017  路  2Comments  路  Source: vitaly-t/pg-promise

Hello

I saw this questions : https://github.com/vitaly-t/pg-promise/issues/90 but in my case I'm wondering how I can generate simple query like :
REFRESH MATERIALIZED VIEW CONCURRENTLY ${tableName}; ?

I have an array of table names (5). I'm not in the case of an insert

I tried something like :

  return db.tx(function (t) {
    let batchQueries = [];
    event.tables_names.forEach(function(tableName) {
      batchQueries.push(t.none(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${tableName};`));
    });
    return t.batch(batchQueries);
  })
question

All 2 comments

return db.tx(function (t) {
    var queries = event.tables_names.map(function (name) {
        return t.none(`REFRESH MATERIALIZED VIEW CONCURRENTLY $1~`, name);
    });
    return t.batch(queries);
});

Thanks a lot again @vitaly-t for the fast and correct answer. 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

msjoshi picture msjoshi  路  4Comments

ForbesLindesay picture ForbesLindesay  路  3Comments

calibermind picture calibermind  路  3Comments

cortopy picture cortopy  路  5Comments