insertOrReplace method

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

Insert a row into a table, replacing it if it already exists.

Implementation

@override
Statement insertOrReplace(
  QualifiedTablename table,
  List<String> columns,
  List<Object?> values,
  List<String> conflictCols,
  List<String> updateCols,
) {
  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.map((col) => '${quote(col)} = EXCLUDED.${quote(col)}').join(', ')};
    ''',
    values,
  );
}