primaryKeyByUniqueColumns method Null safety
- RunFile instance,
- DatabaseExecutor executor
override
Find a record based on the existence of all contained fields annotated with
@Sqlite(unique: true)
. The Brick-defined primary key of the table is not included
in the query. Returns the Brick-defined primary key of the discovered record.
executor
accepts a Database
or Transaction
.
Implementation
@override
Future<int?> primaryKeyByUniqueColumns(
RunFile instance, DatabaseExecutor executor) async {
final results = await executor.rawQuery('''
SELECT * FROM `RunFile` WHERE id = ? LIMIT 1''', [instance.id]);
// SQFlite returns [{}] when no results are found
if (results.isEmpty || (results.length == 1 && results.first.isEmpty)) {
return null;
}
return results.first['_brick_id'] as int;
}