refresh method
Refresh the model from DB.
Implementation
Future<T?> refresh([dynamic id]) async {
final currentId = this.id ?? id;
if (currentId == null) return null;
if (DB.driver == DBDriver.mysql) {
final result = await runQuery(
'SELECT * FROM ${table.name} WHERE $primaryKey = ? LIMIT 1',
positionalParams: [currentId],
);
if (result.isEmpty) return null;
return fromMap(convertDatabaseTypes(result.first));
} else {
final result = await runQuery(
'SELECT * FROM ${table.name} WHERE $primaryKey = :id LIMIT 1',
namedParams: {'id': currentId},
);
if (result.isEmpty) return null;
return fromMap(convertDatabaseTypes(result.first));
}
}