added some new features. (Showing student's reviews and courses, Show course reviews, Show Top Courses with a tag or in a category, skipping optional fields when creating entity)
This commit is contained in:
+9
-10
@@ -5,28 +5,26 @@ from psycopg2 import pool
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Connection pool for reusing connections (important for serverless!)
|
||||
# Connection pool for reusing connections
|
||||
_connection_pool = None
|
||||
|
||||
|
||||
def get_connection_pool():
|
||||
"""Create a connection pool"""
|
||||
global _connection_pool
|
||||
if _connection_pool is None:
|
||||
try:
|
||||
# --- Production settings
|
||||
# DATABASE_URL = os.environ.get("DATABASE_URL")
|
||||
# _connection_pool = psycopg2.pool.SimpleConnectionPool(1, 5, DATABASE_URL);
|
||||
|
||||
# --- Development settings
|
||||
dev_url = "postgresql://postgres:123@localhost:5432/OLP"
|
||||
_connection_pool = psycopg2.pool.SimpleConnectionPool(1, 5, dev_url);
|
||||
|
||||
DATABASE_URL = os.environ.get("DATABASE_URL")
|
||||
_connection_pool = psycopg2.pool.SimpleConnectionPool(
|
||||
1, 5, DATABASE_URL)
|
||||
|
||||
logger.info("Database connection pool created")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create connection pool: {e}")
|
||||
return None
|
||||
return _connection_pool
|
||||
|
||||
|
||||
def get_db_connection():
|
||||
"""Get a connection from the pool"""
|
||||
try:
|
||||
@@ -39,6 +37,7 @@ def get_db_connection():
|
||||
logger.error(f"Database connection error: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def release_db_connection(conn):
|
||||
"""Return connection to the pool"""
|
||||
try:
|
||||
@@ -46,4 +45,4 @@ def release_db_connection(conn):
|
||||
if pool and conn:
|
||||
pool.putconn(conn)
|
||||
except Exception as e:
|
||||
logger.error(f"Error releasing connection: {e}")
|
||||
logger.error(f"Error releasing connection: {e}")
|
||||
|
||||
Reference in New Issue
Block a user