MadDevPro Howdy!
Since we use Laravel's database component under the hood, it's easy to be notified on these events.
Assuming that you know how to start with a Flarum extension, all you need to do is something along the lines of this:
use Illuminate\Contracts\Events\Dispatcher;
return function (Dispatcher $events) {
$events->listen('illuminate.query', $yourListener);
};