batchedInsertOrReplace method
List<Statement>
batchedInsertOrReplace(
- QualifiedTablename table,
- List<
String> columns, - List<
Map< records,String, Object?> > - List<
String> conflictCols, - List<
String> updateCols, - int maxSqlParameters,
override
Inserts a batch of rows into a table, replacing them if they already exist.
Implementation
@override
List<Statement> batchedInsertOrReplace(
QualifiedTablename table,
List<String> columns,
List<Map<String, Object?>> records,
List<String> conflictCols,
List<String> updateCols,
int maxSqlParameters,
) {
final baseSql =
'''INSERT INTO $table (${columns.map(quote).join(', ')}) VALUES ''';
final statements = prepareInsertBatchedStatements(
baseSql,
columns,
records,
maxSqlParameters,
);
return statements
.map(
(stmt) => Statement(
'''
${stmt.sql}
ON CONFLICT (${conflictCols.map(quote).join(', ')}) DO UPDATE
SET ${updateCols.map((col) => '${quote(col)} = EXCLUDED.${quote(col)}').join(', ')};
''',
stmt.args,
),
)
.toList();
}