The Singleton Pattern ensures that a class has only one instance throughout the lifetime of the application and provides a global point of access to that instance.
I don’t say I’m totally confused, but rather that in this case it’s possible to argue both sides of the coin. I suppose there’s a best practice to get the maximum out of such a scenario.
It seems that Prisma actually encourages the DB connection to be a singleton, to be able to make use of connection pooling. But it really seems a lot neater to use dependency injection. And then it looks kinda stoobid to pass around a singleton. Unless, for being able to test, of course. So what’s best, apart from not using Prisma, I wonder…?
…and the git link actually mentions it… :-)
I don’t say I’m totally confused, but rather that in this case it’s possible to argue both sides of the coin. I suppose there’s a best practice to get the maximum out of such a scenario.
It seems that Prisma actually encourages the DB connection to be a singleton, to be able to make use of connection pooling. But it really seems a lot neater to use dependency injection. And then it looks kinda stoobid to pass around a singleton. Unless, for being able to test, of course. So what’s best, apart from not using Prisma, I wonder…?