

def generate_update(self, query):
    model = query.model_class
    alias_map = self.alias_map_class()
    alias_map.add(model, model._meta.db_table)
    if query._on_conflict:
        statement = ('UPDATE OR %s' % query._on_conflict)
    else:
        statement = 'UPDATE'
    clauses = [SQL(statement), model.as_entity(), SQL('SET')]
    update = []
    for (field, value) in self._sorted_fields(query._update):
        if (not isinstance(value, (Node, Model))):
            value = Param(value, conv=field.db_value)
        update.append(Expression(field.as_entity(with_table=False), OP.EQ, value, flat=True))
    clauses.append(CommaClause(*update))
    if query._where:
        clauses.extend([SQL('WHERE'), query._where])
    if (query._returning is not None):
        returning_clause = Clause(*query._returning)
        returning_clause.glue = ', '
        clauses.extend([SQL('RETURNING'), returning_clause])
    return self.build_query(clauses, alias_map)

dataset/ETHPy150Open coleifer/peewee/peewee.py QueryCompiler.generate_update/original