Anyway I finally went via custom module but with knex. This way I can avoid having to use a PL/pgsql function.
const db = require('../../../lib/core/db');
exports.anytable = async function(options) {
// connection option is required
const connection = this.parseRequired('db', 'string', 'connection is required.');
const table = this.parseRequired(options.table, 'string', 'table is required.');
// get the database connection
const db = this.getDbConnection(connection);
// throw error if connection not found
if (!db) throw new Error(`Connection "${connection}" doesn't exist.`);
// get results from database
return db.select('*').from(table);
}