Skip to content

Commit a9b1deb

Browse files
author
Sergio García Prado
committed
ISSUE #150
* Now default values are only set on the `PostgreSqlPool`.
1 parent ae5a3a1 commit a9b1deb

File tree

1 file changed

+46
-16
lines changed
  • packages/core/minos-microservice-common/minos/common/database

1 file changed

+46
-16
lines changed

packages/core/minos-microservice-common/minos/common/database/abc.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,55 @@ def __init__(
4343
**kwargs,
4444
):
4545
super().__init__(*args, **kwargs)
46-
47-
if host is None:
48-
host = "localhost"
49-
if port is None:
50-
port = 5432
51-
if user is None:
52-
user = "postgres"
53-
if password is None:
54-
password = ""
55-
56-
self.database = database
57-
self.host = host
58-
self.port = port
59-
self.user = user
60-
self.password = password
46+
self._database = database
47+
self._host = host
48+
self._port = port
49+
self._user = user
50+
self._password = password
6151

6252
self._pool = None
6353
self._owned_pool = False
6454

55+
@property
56+
def database(self) -> str:
57+
"""Get the database's database.
58+
59+
:return: A ``str`` value.
60+
"""
61+
return self.pool.database
62+
63+
@property
64+
def host(self) -> str:
65+
"""Get the database's host.
66+
67+
:return: A ``str`` value.
68+
"""
69+
return self.pool.host
70+
71+
@property
72+
def port(self) -> int:
73+
"""Get the database's port.
74+
75+
:return: An ``int`` value.
76+
"""
77+
return self.pool.port
78+
79+
@property
80+
def user(self) -> str:
81+
"""Get the database's user.
82+
83+
:return: A ``str`` value.
84+
"""
85+
return self.pool.user
86+
87+
@property
88+
def password(self) -> str:
89+
"""Get the database's password.
90+
91+
:return: A ``str`` value.
92+
"""
93+
return self.pool.password
94+
6595
async def _destroy(self) -> None:
6696
if self._owned_pool:
6797
await self._pool.destroy()
@@ -197,6 +227,6 @@ def _build_pool(self, pool: PostgreSqlPool = None) -> tuple[PostgreSqlPool, bool
197227
return pool, False
198228

199229
pool = PostgreSqlPool(
200-
host=self.host, port=self.port, database=self.database, user=self.user, password=self.password
230+
host=self._host, port=self._port, database=self._database, user=self._user, password=self._password
201231
)
202232
return pool, True

0 commit comments

Comments
 (0)