How to use the pg-promise.as function in pg-promise

To help you get started, we’ve selected a few pg-promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AraiEzzra / DDKCORE / backlog / helpers / inserts.js View on Github external
this.template = function () {
        let values;
        const fields = record.fields.map(pgp.as.name).join(',');
        if (concat) {
            values = '$1';
        } else {
            values = `(${this.namedTemplate()})`;
        }
        // TODO: https://trello.com/c/D3iBP5UZ/220-remove-on-conflict-do-nothing-from-inserts-function
        return pgp.as.format('INSERT INTO $1~($2^) VALUES $3^ ON CONFLICT DO NOTHING', [record.table, fields, values]);
    };
github AraiEzzra / DDKCORE / backlog / helpers / inserts.js View on Github external
this.template = function () {
        let values;
        const fields = record.fields.map(pgp.as.name).join(',');
        if (concat) {
            values = '$1';
        } else {
            values = `(${this.namedTemplate()})`;
        }
        // TODO: https://trello.com/c/D3iBP5UZ/220-remove-on-conflict-do-nothing-from-inserts-function
        return pgp.as.format('INSERT INTO $1~($2^) VALUES $3^ ON CONFLICT DO NOTHING', [record.table, fields, values]);
    };
github nlf / muckraker / test / mock.js View on Github external
any(q, p) {

    return PG.as.format(q, p);
  }
github jamesplease / api-pls / packages / api-pls-postgres-adapter / sql / many-to-many-util.js View on Github external
function getPrimaryKeyColumnName({host, guest, escaped}) {
  const rawName = `${host.name}_${guest.name}_pkey`;
  return escaped ? pgp.as.name(rawName) : rawName;
}
github RiseVision / rise-node / helpers / inserts.js View on Github external
this.template = function () {
		var values;
		var fields = record.fields.map(pgp.as.name).join(',');
		if (concat) {
			values = '$1^';
		} else {
			values = '(' + this.namedTemplate() + ')';
		}
		return pgp.as.format('INSERT INTO $1~($2^) VALUES $3^', [record.table, fields, values]);
	};
github RiseVision / rise-node / packages / core-accounts / src / models / AccountsModel.ts View on Github external
      addresses.map((address) => pgp.as.format('($1)', address)).join(', ')
    );
github 1ven / do / server / models / List.js View on Github external
    const props = _.keys(_data).map(k => pgp.as.name(k)).join();
    const values = _.values(_data);
github LiskHQ / lisk-sdk / sql / delegates.js View on Github external
'(CASE WHEN producedblocks + missedblocks = 0 THEN 0.00 ELSE',
          'ROUND(100 - (missedblocks::numeric / (producedblocks + missedblocks) * 100), 2)',
        'END)::float AS productivity,',
        'COALESCE(v.voters_cnt, 0) AS voters_cnt,',
        't.timestamp AS register_timestamp',
      'FROM delegates d',
      'LEFT JOIN mem_accounts m ON d.username = m.username',
      'LEFT JOIN trs t ON d."transactionId" = t.id',
      'LEFT JOIN (SELECT "dependentId", COUNT(1)::int AS voters_cnt from mem_accounts2delegates GROUP BY "dependentId") v ON v."dependentId" = ENCODE(m."publicKey", \'hex\')',
      'WHERE m."isDelegate" = 1',
      'ORDER BY ' + [params.sortField, params.sortMethod].join(' ') + ')',
      'SELECT * FROM delegates WHERE username LIKE ${q} LIMIT ${limit}'
    ].join(' ');

    params.q = '%' + String(params.q).toLowerCase() + '%';
    return pgp.as.format(sql, params);
  },
github ShiftNrg / shift / logic / account.js View on Github external
var queries = sqles.concat(round).map(function (sql) {
		return pgp.as.format(sql.query, sql.values);
	}).join('');
github RiseVision / rise-node / packages / core-accounts / src / models / AccountsModel.ts View on Github external
public static createBulkAccountsSQL(addresses: string[]) {
    if (!addresses) {
      return '';
    }
    addresses = addresses.filter((addr) => addr);
    if (addresses.length === 0) {
      return '';
    }
    return pgp.as.format(
      `
    INSERT into mem_accounts(address)
    SELECT address from (VALUES $1:raw ) i (address)
    LEFT JOIN mem_accounts m1 USING(address)
    WHERE m1.address IS NULL`,
      addresses.map((address) => pgp.as.format('($1)', address)).join(', ')
    );
  }
}