primaryKey property

  1. @override
Set<Column<Object>> primaryKey

Override this to specify custom primary keys:

class IngredientInRecipes extends Table {
 Set<Column> get primaryKey => {recipe, ingredient};

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

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

The getter must return a set literal using the => syntax so that the drift generator can understand the code. Also, please note that it's an error to have an BuildIntColumn.autoIncrement column and a custom primary key. As an auto-incremented IntColumn is recognized by drift to be the primary key, doing so will result in an exception thrown at runtime.


Set<Column> get primaryKey => $primaryKey;