find<T> method
Finds an entity of the specified type by primary key.
Implementation
@override
Future<T?> find<T>(key, [Type? type]) async {
var connection = await _openConnection;
var entitySupport = registry.lookup(type ?? T);
var tableName = _snakeCase(entitySupport.name);
var conditions = entitySupport.keyFields
.map((field) => '${_snakeCase(field)} = @$field')
.join(' AND ');
var values = (key is Map ? key : {entitySupport.keyFields.first: key})
as Map<String, dynamic>;
var results = await connection.mappedResultsQuery(
'SELECT * FROM "$tableName" WHERE $conditions',
substitutionValues: values);
if (results.isNotEmpty) {
return _mapRow<T>(results.first[tableName]!, entitySupport, type, [], []);
}
return null;
}