update method
Update records matching the query (schema-aware).
await DB.table('users')
.where('id', 1)
.update({'name': 'Updated Name'});
Implementation
Future<int> update(Map<String, dynamic> data) async {
// Filter data to only include existing columns
final filteredData = await _filterDataBySchema(data);
if (filteredData.isEmpty) {
return 0;
}
final setClauses = filteredData.keys.map((col) => '$col = ?').join(', ');
final values = filteredData.values.toList();
final whereSql = _buildWhereSql();
final whereParams = _buildWhereParams();
final sql = 'UPDATE $_table SET $setClauses$whereSql';
_db.connection.execute(sql, [..._prepareValues(values), ...whereParams]);
// Return affected rows
final result = _db.connection.select('SELECT changes() as count');
return result.first['count'] as int;
}