mongoose listener not working

im trying to setup a mongoose listener for the 'open' event however saphire doesnt seem to catch it my best guess is i didnt specify the right emitter as my other listeners work here is a screenshot
8 Replies
s4g
s4gOP2y ago
equivalent code would be connection.on("open", () => { container.client.logger.info("Succesfully Connected To DB Instance"); }); tested and it works
Favna
Favna2y ago
i'm assuming connection is something that is available as emitter through dependency injection when using mongoose? when is it being initialised? Or rather, can you try setting a breakpoint / adding console.log to node_modules/@sapphire/framework/dist/lib/structures/Listener.js between line 14 and 15? To check whether this.emitter is null or not. because if it's null when the listener is loaded because the connetion is established too late then the listener doesn't get enabled
s4g
s4gOP2y ago
console.log(this.emitter)
s4g
s4gOP2y ago
Favna
Favna2y ago
okay so it's not null I'm honestly not sure then I don't use Mongoose (or MongoDB for that matter)
Favna
Favna2y ago
I know it's not really a solution per-se but you could consider switching to https://www.prisma.io which is the ORM that most of us here use
Prisma
Prisma | Next-generation ORM for Node.js & TypeScript
Prisma is a next-generation Node.js and TypeScript ORM for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB, and CockroachDB. It provides type-safety, automated migrations, and an intuitive data model.
s4g
s4gOP2y ago
i think ill switch to prisma thx for the help do you have any examples for sapphire with prisma?
Favna
Favna2y ago
@Gemboard uses it, it's open source on our GH org
Want results from more Discord servers?
Add your server