I don't think there is a proper way to do that atm since we don't have the posibility to work with instances of \OC\DB.

That is something I really like to change but way outside the scope of this PR