So I've been trying to make a currency system and an inventory system for my Discord bot for the past few days. However, I can't seem to make any progress at all. I've tried using sequelize and better-sqlite3 (which is what I'm currently using), all with no success.
const table = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type ='table' AND name = 'balance';").get();
if (table["count(*)"] === 0) {
console.log("creating table...");
sql.prepare("CREATE TABLE scores (id TEXT PRIMARY KEY, user TEXT, guild TEXT, money INTEGER);").run();
sql.prepare("CREATE UNIQUE INDEX idx_scores_id ON scores (id);").run();
sql.pragma("synchronous = 1");
sql.pragma("journal_mode = wal");
}
client.getScore = sql.prepare("SELECT * FROM balance WHERE user = ? AND guild = ?");
client.setScore = sql.prepare("INSERT OR REPLACE INTO money (id, user, guild, money) VALUES (@id, @user, @guild, @money);");
The above code results in this error:
(node:13036) UnhandledPromiseRejectionWarning: SqliteError: table scores already exists
I don't have that much knowledge on stuff like this since there is so little material out there for me to refer to.