insertOrReplaceWith method

  1. @override
Statement insertOrReplaceWith(
  1. QualifiedTablename table,
  2. List<String> columns,
  3. List<Object?> values,
  4. List<String> conflictCols,
  5. List<String> updateCols,
  6. List<Object?> updateVals,
)
override

Insert a row into a table. If it already exists we update the provided columns updateCols with the provided values updateVals

Implementation

@override
Statement insertOrReplaceWith(
  QualifiedTablename table,
  List<String> columns,
  List<Object?> values,
  List<String> conflictCols,
  List<String> updateCols,
  List<Object?> updateVals,
) {
  return Statement(
    '''
      INSERT INTO $table (${columns.map(quote).join(', ')})
        VALUES (${columns.mapIndexed((i, _) => "\$${i + 1}").join(', ')})
      ON CONFLICT (${conflictCols.map(quote).join(', ')}) DO UPDATE
        SET ${updateCols.mapIndexed((i, col) => '${quote(col)} = \$${columns.length + i + 1}').join(', ')};
    ''',
    [...values, ...updateVals],
  );
}