db = $db; } /** * Execute $callback inside a transaction. * * Nested calls reuse the outer transaction (no savepoints in MySQL via wpdb by default). * * @template T * @param callable(): T $callback Work to run. * @return T * * @throws Throwable Re-throws after rollback. * * @since 0.1.0 */ public function run( callable $callback ): mixed { $this->db->query( 'START TRANSACTION' ); try { $result = $callback(); $this->db->query( 'COMMIT' ); return $result; } catch ( Throwable $e ) { $this->db->query( 'ROLLBACK' ); throw $e; } } }