Update query from custom plugin

Hello guys, for my project I would like to have opportunity to change query not only from query editor but also from custom plugin. Is there any way how can I do this?
I’ve already found some topics but there wasn’t any answer.

Thanks