-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import PrismaClientManager from "./pgSingelton"; | ||
|
||
const prisma = new PrismaClient(); | ||
const prisma = PrismaClientManager.getInstance().getPrismaClient(); | ||
|
||
export default prisma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
class PrismaClientManager { | ||
private static instance: PrismaClientManager; | ||
private prismaClient: PrismaClient; | ||
|
||
private constructor() { | ||
this.prismaClient = new PrismaClient(); | ||
} | ||
|
||
public static getInstance(): PrismaClientManager { | ||
if (!PrismaClientManager.instance) { | ||
PrismaClientManager.instance = new PrismaClientManager(); | ||
} | ||
return PrismaClientManager.instance; | ||
} | ||
|
||
public getPrismaClient(): PrismaClient { | ||
return this.prismaClient; | ||
} | ||
|
||
public async checkStatus() { | ||
try { | ||
return await this.prismaClient.$queryRaw`SELECT 'OK!' as result`; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
public async disconnect() { | ||
await this.prismaClient.$disconnect(); | ||
} | ||
} | ||
|
||
export default PrismaClientManager; |