public function inTransaction(callable $function)
    {
        if (!is_callable($function)) {
            throw new InvalidArgumentException('$function must be callable.');
        }
        $this->beginTransaction();
        try {
            if (func_num_args() === 1) {
                $returnValue = $function($this);
            } else {
                $args    = func_get_args();
                $args[0] = $this;
                $returnValue = call_user_func_array($function, $args);
            }
            $this->commit();
            return $returnValue;
        } catch (\PDOException $e) {
            $this->rollBack();
            throw $e;
        }
    }