Database connection

Hey I have a mysql database, I can connect to it and run CRUD actions. But I feel like the setup is wrong. I have this function:
export const db = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
});
export const db = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
});
and I call the db for running queries. But that means I create a connection on any query, what would be the correct way to connection the bot on startup and have a live connection?
9 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Amgelo
Amgelo2mo ago
this doesn't have to do with djs at all, #other-js-ts
Zuk
ZukOP2mo ago
There isn't a best practice for doing that on discord.js?
Amgelo
Amgelo2mo ago
djs is simply a library to interact with the discord api it has nothing to do with databases how you manage your databases, or whether you have one at all is entirely up to your needs and preferences
Zuk
ZukOP2mo ago
you right, got that!
Amgelo
Amgelo2mo ago
there are best practices for managing databases in general though, but that falls outside the scope of djs
Zuk
ZukOP2mo ago
Mind pointing me in the right direction before I close the ticket?
Amgelo
Amgelo2mo ago
it's better to discuss further in the other channel basically just move your question there
Zuk
ZukOP2mo ago
Thank you!
Want results from more Discord servers?
Add your server