Skip to content

Commit

Permalink
linted
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Oct 27, 2024
1 parent d14c826 commit 76590f8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/masoniteorm/connections/PostgresConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(
self.database = database
self.user = user
self.password = password

self.prefix = prefix
self.full_details = full_details or {}
self.connection_pool_size = full_details.get("connection_pooling_max_size", 100)
Expand Down Expand Up @@ -67,24 +67,31 @@ def make_connection(self):
self.open = 1

return self

def create_connection(self):
import psycopg2

# Initialize the connection pool if the option is set
initialize_size = self.full_details.get("connection_pooling_min_size")
if self.full_details.get("connection_pooling_enabled") and initialize_size and len(CONNECTION_POOL) < initialize_size:
if (
self.full_details.get("connection_pooling_enabled")
and initialize_size
and len(CONNECTION_POOL) < initialize_size
):
for _ in range(initialize_size - len(CONNECTION_POOL)):
connection = psycopg2.connect(
database=self.database,
user=self.user,
password=self.password,
host=self.host,
port=self.port,
options=f"-c search_path={self.schema or self.full_details.get('schema')}" if self.schema or self.full_details.get('schema') else "",
options=(
f"-c search_path={self.schema or self.full_details.get('schema')}"
if self.schema or self.full_details.get("schema")
else ""
),
)
CONNECTION_POOL.append(connection)


if (
self.full_details.get("connection_pooling_enabled")
Expand All @@ -99,11 +106,15 @@ def create_connection(self):
password=self.password,
host=self.host,
port=self.port,
options=f"-c search_path={self.schema or self.full_details.get('schema')}" if self.schema or self.full_details.get('schema') else "",
options=(
f"-c search_path={self.schema or self.full_details.get('schema')}"
if self.schema or self.full_details.get("schema")
else ""
),
)

return connection

def get_database_name(self):
return self.database

Expand All @@ -121,7 +132,7 @@ def get_default_post_processor(cls):

def reconnect(self):
pass

def close_connection(self):
if (
self.full_details.get("connection_pooling_enabled")
Expand Down

0 comments on commit 76590f8

Please sign in to comment.