uniqueKeys property Null safety

List<Set<Column>>? uniqueKeys

Unique constraints in this table.

When two rows have the same value in any set specified in uniqueKeys, the database will reject the second row for inserts.

Override this to specify unique keys:

class IngredientInRecipes extends Table {
 Set<Column> get uniqueKeys =>
    [{recipe, ingredient}, {recipe, amountInGrams}];

 IntColumn get recipe => integer()();
 IntColumn get ingredient => integer()();

 IntColumn get amountInGrams => integer().named('amount')();

The getter must return a list of set literals using the => syntax so that the drift generator can understand the code.

Note that individual columns can also be marked as unique with BuildGeneralColumn.unique. This is equivalent to adding a single-element set to this list.


List<Set<Column>>? get uniqueKeys => null;