addOnConflictConstraint method
Implementation
void addOnConflictConstraint({
List<TableColumn>? target,
WhereClause? where,
}) {
statement.buffer.write('ON CONFLICT');
if (target != null && target.isEmpty) {
// An empty list indicates that no explicit target should be generated
// by drift, the default rules by the database will apply instead.
return;
}
statement.buffer.write('(');
final conflictTarget =
target ?? currentInsertStatement!.table.resolvedPrimaryKey;
if (conflictTarget.isEmpty) {
throw ArgumentError(
'Table has no primary key, so a conflict target is needed.',
);
}
var first = true;
for (final target in conflictTarget) {
if (!first) statement.comma();
addReference(target.name);
first = false;
}
statement.buffer.write(')');
if (where != null) {
statement.space();
where.compileWith(this);
}
}