insertOrReplaceWith method
Statement
insertOrReplaceWith(
- QualifiedTablename table,
- List<
String> columns, - List<
Object?> values, - List<
String> conflictCols, - List<
String> updateCols, - 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],
);
}