uniqueKeys property

  1. @override
List<Set<GeneratedColumn<Object>>> get uniqueKeys
override

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 {
 @override
 List<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.

Implementation

@override
List<Set<GeneratedColumn>> get uniqueKeys => [
      {date, packageName},
    ];