Fixed postgres not properly getting command count on newly registered commands
This commit is contained in:
parent
43e0f7f447
commit
48fb0c98c8
1 changed files with 5 additions and 2 deletions
|
@ -59,8 +59,11 @@ exports.getCounts = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.addCount = async (command) => {
|
exports.addCount = async (command) => {
|
||||||
const count = await connection.query("SELECT * FROM counts WHERE command = $1", [command]);
|
let count = await connection.query("SELECT * FROM counts WHERE command = $1", [command]);
|
||||||
if (!count.rows[0]) await connection.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]);
|
if (!count.rows[0]) {
|
||||||
|
await connection.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]);
|
||||||
|
count = await connection.query("SELECT * FROM counts WHERE command = $1", [command]);
|
||||||
|
}
|
||||||
await connection.query("UPDATE counts SET count = $1 WHERE command = $2", [count.rows[0].count ? count.rows[0].count + 1 : 1, command]);
|
await connection.query("UPDATE counts SET count = $1 WHERE command = $2", [count.rows[0].count ? count.rows[0].count + 1 : 1, command]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue