lib/db.js
function sqliteBulkUpsert(model, data) {
  var queries = ["BEGIN"];
  var values = [];

  // Transform data
  _.each(data, function(d) {
    var query = "INSERT OR REPLACE INTO " + model.tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])";
    query = query.replace("[[COLUMNS]]", _.keys(d).join(", "));

    // Put in ?'s
    query = query.replace("[[VALUES]]", _.map(d, function(v) {
      return "?";
    }).join(", "));

    // Get values
    values = values.concat(_.values(d));
    queries.push(query);
  });

  // Create final output and format
  queries.push("COMMIT");
  return {
    query: queries.join("; "),
    replacements: values
  };
}
function sqliteBulkUpsert(model, data) {
  var queries = ["BEGIN"];
  var values = [];

  // Transform data
  _.each(data, function(d) {
    var query = "INSERT OR REPLACE INTO " + model.tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])";
    query = query.replace("[[COLUMNS]]", _.keys(d).join(", "));

    // Put in ?'s
    query = query.replace("[[VALUES]]", _.map(d, function(v) {
      return "?";
    }).join(", "));

    // Get values
    values = values.concat(_.values(d));
    queries.push(query);
  });

  // Create final output and format
  queries.push("COMMIT");
  return {
    query: queries.join("; "),
    replacements: values
  };
}
function sqliteBulkUpsert ( model , data ) { var queries = [ "BEGIN" ] ; var values = [ ] ; // Transform data _ . each ( data , function ( d ) { var query = "INSERT OR REPLACE INTO " + model . tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])" ; query = query . replace ( "[[COLUMNS]]" , _ . keys ( d ) . join ( ", " ) ) ; // Put in ?'s query = query . replace ( "[[VALUES]]" , _ . map ( d , function ( v ) { return "?" ; } ) . join ( ", " ) ) ; // Get values values = values . concat ( _ . values ( d ) ) ; queries . push ( query ) ; } ) ; // Create final output and format queries . push ( "COMMIT" ) ; return { query : queries . join ( "; " ) , replacements : values } ; }
SQLite query format bulk upsert.  SQLite uses a bind function that automatically replaces ?
SQLite query format bulk upsert . SQLite uses a bind function that automatically replaces ?