so im making a dscord bot and i used sqlite, but becous emy host (heroku) i could no use that. thay said i needed to use postgres so i did im updating my code to use but i cant get it to work for creating my table i use this code
client.query('CREATE TABLE users(name text, money bigint);', (err, res) => {
if (err) throw err;
for (let row of res.rows) {
console.log(JSON.stringify(row));
}
client.end();
});
that works fine the table is created.
then for insertinf data i use this:
client.query(`INSERT INTO users(name,money) SELECT ${message.author.id},0 WHERE NOT EXISTS(SELECT 1 FROM users WHERE name = '${message.author.id}'); `, (err, res) => {
if (err) throw err;
message.reply(`inserted data`);
});
that also works fin i think.
but then when i wanted to get data with:
client.query(`SELECT * FROM users WHERE name = ?`, id,(err, row) => {
if(err) throw err;
console.log(id);
if (!row) return message.reply(`${name} has no money`);
message.reply(`${name} has ${row.money} money`);
});
i get this error:
G:\dolphin casino\cmds\money.js:17
if(err) throw err;
^
Error: Query values must be an array
at Query.submit (G:\dolphin casino\node_modules\pg\lib\query.js:156:17)
at Client._pulseQueryQueue (G:\dolphin casino\node_modules\pg\lib\client.js:356:24)
at Client.query (G:\dolphin casino\node_modules\pg\lib\client.js:393:8)
at Object.module.exports.run (G:\dolphin casino\cmds\money.js:16:10)
at Client.bot.on.message (G:\dolphin casino\bot.js:80:14)
at emitOne (events.js:96:13)
at Client.emit (events.js:188:7)
at MessageCreateHandler.handle (G:\dolphin casino\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (G:\dolphin casino\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (G:\dolphin casino\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
wich is weird becouse the name column is text not an array.
does someone know whats going on ?
What I have tried:
searching the internet. but i did not found an solution.