|
11 | 11 | from sqlalchemy.orm import sessionmaker |
12 | 12 | import logging |
13 | 13 |
|
14 | | -lock = threading.Lock() |
15 | | - |
16 | 14 |
|
17 | 15 | def generate_unique_id() -> str: |
18 | 16 | """ |
@@ -112,7 +110,8 @@ def __init__(self, echo_sql=False): |
112 | 110 | database_url = os.getenv("FEEDS_DATABASE_URL") |
113 | 111 | if database_url is None: |
114 | 112 | raise Exception("Database URL not provided.") |
115 | | - self.engine = create_engine(database_url, echo=echo_sql, pool_size=10, max_overflow=0) |
| 113 | + self.pool_size = int(os.getenv("DB_POOL_SIZE", 10)) |
| 114 | + self.engine = create_engine(database_url, echo=echo_sql, pool_size=self.pool_size, max_overflow=0) |
116 | 115 | # creates a session factory |
117 | 116 | self.Session = sessionmaker(bind=self.engine, autoflush=False) |
118 | 117 |
|
@@ -154,17 +153,19 @@ def select( |
154 | 153 | group_by: Callable = None, |
155 | 154 | ): |
156 | 155 | """ |
157 | | - Executes a query on the database |
158 | | - :param model: the sqlalchemy model to query |
159 | | - :param query: the sqlalchemy ORM query execute |
160 | | - :param conditions: list of conditions (filters for the query) |
161 | | - :param attributes: list of model's attribute names that you want to fetch. If not given, fetches all attributes. |
162 | | - :param update_session: option to update session before running the query (defaults to True) |
163 | | - :param limit: the optional number of rows to limit the query with |
164 | | - :param offset: the optional number of rows to offset the query with |
165 | | - :param group_by: an optional function, when given query results will group by return value of group_by function. |
166 | | - Query needs to order the return values by the key being grouped by |
167 | | - :return: None if database is inaccessible, the results of the query otherwise |
| 156 | + Executes a query on the database. |
| 157 | +
|
| 158 | + :param session: The SQLAlchemy session object used to interact with the database. |
| 159 | + :param model: The SQLAlchemy model to query. If not provided, the query parameter must be given. |
| 160 | + :param query: The SQLAlchemy ORM query to execute. If not provided, a query will be created using the model. |
| 161 | + :param conditions: A list of conditions (filters) to apply to the query. Each condition should be a SQLAlchemy |
| 162 | + expression. |
| 163 | + :param attributes: A list of model's attribute names to fetch. If not provided, all attributes will be fetched. |
| 164 | + :param limit: An optional integer to limit the number of rows returned by the query. |
| 165 | + :param offset: An optional integer to offset the number of rows returned by the query. |
| 166 | + :param group_by: An optional function to group the query results by the return value of the function. The query |
| 167 | + needs to order the return values by the key being grouped by. |
| 168 | + :return: None if the database is inaccessible, otherwise the results of the query. |
168 | 169 | """ |
169 | 170 | try: |
170 | 171 | if query is None: |
|
0 commit comments