Skip to content

Commit

Permalink
Merge pull request #20 from seunggabi/feature/#19_singleton
Browse files Browse the repository at this point in the history
(#19) feat: singleton
  • Loading branch information
jkklee committed Sep 5, 2023
2 parents cfa69f8 + 38fa566 commit b7f1de5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ eggs
.idea
test.py
*.swp

venv
14 changes: 14 additions & 0 deletions pymysqlpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,17 @@ def wrapper(*args, **kwargs):
for name, fn in inspect.getmembers(Connection, inspect.isfunction):
if not name.startswith('_'):
setattr(Connection, name, already_returned_conn(fn))


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)

0 comments on commit b7f1de5

Please sign in to comment.