Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据库事件类型补全,可增加before_update和before_insert等事件 #1105

Open
xuekang opened this issue Mar 9, 2022 · 0 comments

Comments

@xuekang
Copy link

xuekang commented Mar 9, 2022

TP6官方文档中只提供部分数据库事件,不如模型事件齐全;当需要多Db和Model的增删改成都进行监听时,只能使用Db事件,而Db事件不齐全,相关业务需求无法实现。
(think\db\PDOConnection)新增before_update事件示例:

  /**
     * 更新记录
     * @access public
     * @param BaseQuery $query 查询对象
     * @return integer
     * @throws PDOException
     */
    public function update(BaseQuery $query): int
    {
        $query->parseOptions();

        $flag = $this->db->trigger('before_update', $query);
        if($flag === true) return 0;

        // 生成UPDATE SQL语句
        $sql = $this->builder->update($query);

        // 执行操作
        $result = '' == $sql ? 0 : $this->pdoExecute($query, $sql, $query->getBind());

        if ($result) {
            $this->db->trigger('after_update', $query);
        }

        return $result;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant