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

feat(sql): 支持Upsert单数据的操作。 #45

Open
CarmJos opened this issue Apr 20, 2022 · 0 comments
Open

feat(sql): 支持Upsert单数据的操作。 #45

CarmJos opened this issue Apr 20, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@CarmJos
Copy link
Owner

CarmJos commented Apr 20, 2022

功能简述

通过Upsert实现数据表单个数据的改动,避免多次查询。

需求来源

有些情况下,只需要针对表中单个数据进行增加或减少,且对应的数据并未获取,此时便需要进行获取->修改->写入三个操作,十分不便。

因此,若支持通过Upsert针对该数据进行简单计算的修改,即可大大的增加整体效率。

功能参考(可选)

    public void updateStats(long uid, StatsType type, int modify) {
        if (modify == 0) return;
        String tableName = DBTables.STATS.getTableName();
        getSQLManager().executeSQL(
                "INSERT INTO " + tableName + "(uid,type,value) " +
                        "VALUE(?,?,?) ON DUPLICATE KEY " +
                        "UPDATE value = value " + (modify > 0 ? "+" : "-") + "?" + " ",
                new Object[]{uid, type.getID(), Math.abs(modify)}
        );
    }
@CarmJos CarmJos added the enhancement New feature or request label Apr 20, 2022
@CarmJos CarmJos changed the title 支持Upsert单数据的操作。 feat(upsert): 支持Upsert单数据的操作。 Sep 12, 2022
@CarmJos CarmJos self-assigned this Sep 12, 2022
@CarmJos CarmJos changed the title feat(upsert): 支持Upsert单数据的操作。 feat(sql): 支持Upsert单数据的操作。 Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant