Make field in update set dynamic

Hey there,

I have this piece:

from(e in block.table,
          where: not is_nil(field(e, ^field)) and fragment("trim(?)", field(e, ^field)) == "",
          update: [
            set: Keyword.new([{field, nil}])
          ]
        )
        |> Repo.update_all([])

from(e in "events",
          where: not is_nil(field(e, ^field)),
          update: [
            set:  Keyword.new([{field, fragment("trim(?)", field(e, ^field))}]) 
          ]
        )
        |> Repo.update_all([])

Is it possible to make this work somehow?
To run a function in set, or the best bet is to rewrite this whole thing as a fragment?
What i want to do is I feed a block to this, with a table name and a field that need to be updated. or is there a better way to do this?

Thank you

this