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
equivalent code would be connection.on("open", () => {
container.client.logger.info("Succesfully Connected To DB Instance");
});
tested and it works
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 enabledconsole.log(this.emitter)
okay so it's not
null
I'm honestly not sure then
I don't use Mongoose (or MongoDB for that matter)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.
i think ill switch to prisma thx for the help
do you have any examples for sapphire with prisma?
@Gemboard uses it, it's open source on our GH org