lib/db.js
function pgsqlBulkUpsert(model, data) {
  var queries = [];

  // Transform data
  _.each(data, function(d) {
    // TODO: Postgres does not have easy UPSERT syntax, the ON CONFLICT UPDATE requires specific columns
    var query = "INSERT INTO " + model.tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])";
    query = query.replace("[[COLUMNS]]", _.keys(d).join(", "));
    query = query.replace("[[VALUES]]", _.map(d, function(v) {
      return sequelizeSS.escape(v, undefined, "postgres");
    }).join(", "));
    queries.push(query);
  });

  // Create final output and format
  return queries.join("; ");
}
function pgsqlBulkUpsert(model, data) {
  var queries = [];

  // Transform data
  _.each(data, function(d) {
    // TODO: Postgres does not have easy UPSERT syntax, the ON CONFLICT UPDATE requires specific columns
    var query = "INSERT INTO " + model.tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])";
    query = query.replace("[[COLUMNS]]", _.keys(d).join(", "));
    query = query.replace("[[VALUES]]", _.map(d, function(v) {
      return sequelizeSS.escape(v, undefined, "postgres");
    }).join(", "));
    queries.push(query);
  });

  // Create final output and format
  return queries.join("; ");
}
function pgsqlBulkUpsert ( model , data ) { var queries = [ ] ; // Transform data _ . each ( data , function ( d ) { // TODO: Postgres does not have easy UPSERT syntax, the ON CONFLICT UPDATE requires specific columns var query = "INSERT INTO " + model . tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])" ; query = query . replace ( "[[COLUMNS]]" , _ . keys ( d ) . join ( ", " ) ) ; query = query . replace ( "[[VALUES]]" , _ . map ( d , function ( v ) { return sequelizeSS . escape ( v , undefined , "postgres" ) ; } ) . join ( ", " ) ) ; queries . push ( query ) ; } ) ; // Create final output and format return queries . join ( "; " ) ; }
PGSQL query format bulk upsert
PGSQL query format bulk upsert