From ca431beb02744d781c0843e2e145a22c1eb6cd76 Mon Sep 17 00:00:00 2001 From: seunggabi Date: Thu, 17 Aug 2023 00:56:49 +0900 Subject: [PATCH] (#19) feat: singleton --- .gitignore | 2 ++ pymysqlpool_singleton.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 pymysqlpool_singleton.py diff --git a/.gitignore b/.gitignore index 91a0d9f..5c4b3c3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ eggs .idea test.py *.swp + +venv diff --git a/pymysqlpool_singleton.py b/pymysqlpool_singleton.py new file mode 100644 index 0000000..a151f17 --- /dev/null +++ b/pymysqlpool_singleton.py @@ -0,0 +1,15 @@ +from pymysqlpool import ConnectionPool + + +class ConnectionPoolSingleton: + _instance = None + + def __new__(cls, *args, **kwargs): + if cls._instance is None: + cls._instance = cls._create_pool(*args, **kwargs) + + return cls._instance + + @staticmethod + def _create_pool(*args, **kwargs): + return ConnectionPool(*args, **kwargs)