asUpdateCommand method
Generates an UPDATE command for the given table name, WHERE clause, and map of values.
The tableName
parameter specifies the name of the table to update.
The where
parameter specifies the WHERE clause as a map of column names and values.
The nullAsBlank
parameter determines whether null values should be treated as blank strings.
The quoteChar
parameter specifies the character used for quoting identifiers.
The dataBaseProvider
parameter specifies the database provider.
Returns the generated UPDATE command as a string.
Implementation
String asUpdateCommand({
required String tableName,
required Map<String, dynamic> where,
bool nullAsBlank = false,
dynamic quoteChar,
String dataBaseProvider = "",
}) {
var upsertMap = JsonRow.from(this);
String updates = upsertMap.entries.map((e) => "${SqlUtil.wrap(e.key, quoteChar, dataBaseProvider)} = ${SqlUtil.value(e.value, nullAsBlank)}").join(', ');
String whereClause = where.asWhereClausule(
nullAsBlank: nullAsBlank,
quoteChar: quoteChar,
dataBaseProvider: dataBaseProvider,
);
return 'UPDATE ${SqlUtil.wrap(tableName, quoteChar, dataBaseProvider)} SET $updates WHERE $whereClause;';
}