Skip to content

Commit 05db751

Browse files
committed
removed alembic migrations script, removed option to return as list of Row objects in get_multi
1 parent dbd4614 commit 05db751

File tree

5 files changed

+28
-83
lines changed

5 files changed

+28
-83
lines changed

docker-compose.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,33 @@ services:
4545
volumes:
4646
- redis-data:/data
4747

48-
# #-------- uncomment to create first superuser --------
49-
# create_superuser:
50-
# build:
51-
# context: .
52-
# dockerfile: Dockerfile
53-
# env_file:
54-
# - ./src/.env
55-
# depends_on:
56-
# - db
57-
# command: python -m src.scripts.create_first_superuser
58-
# volumes:
59-
# - ./src:/code/src
48+
#-------- uncomment to create first superuser --------
49+
create_superuser:
50+
build:
51+
context: .
52+
dockerfile: Dockerfile
53+
env_file:
54+
- ./src/.env
55+
depends_on:
56+
- db
57+
command: python -m src.scripts.create_first_superuser
58+
volumes:
59+
- ./src:/code/src
6060

61-
# #-------- uncomment to run tests --------
62-
# pytest:
63-
# build:
64-
# context: .
65-
# dockerfile: Dockerfile
66-
# env_file:
67-
# - ./src/.env
68-
# depends_on:
69-
# - db
70-
# - create_superuser
71-
# - redis
72-
# command: python -m pytest
73-
# volumes:
74-
# - ./src:/code/src
61+
#-------- uncomment to run tests --------
62+
pytest:
63+
build:
64+
context: .
65+
dockerfile: Dockerfile
66+
env_file:
67+
- ./src/.env
68+
depends_on:
69+
- db
70+
- create_superuser
71+
- redis
72+
command: python -m pytest
73+
volumes:
74+
- ./src:/code/src
7575

7676
volumes:
7777
postgres-data:

src/app/core/cache.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from fastapi import FastAPI
1212
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
1313

14-
from app.core.exceptions import CacheIdentificationInferenceError, InvalidRequestError, InvalidOutputTypeError
14+
from app.core.exceptions import CacheIdentificationInferenceError, InvalidRequestError
1515

1616
# --------------- server side caching ---------------
1717

@@ -209,9 +209,6 @@ async def sample_endpoint(request: Request, resource_id: int):
209209
def wrapper(func: Callable) -> Callable:
210210
@functools.wraps(func)
211211
async def inner(request: Request, *args, **kwargs) -> Response:
212-
if "output_type" in kwargs.keys() and kwargs["output_type"] == list:
213-
raise InvalidOutputTypeError
214-
215212
if resource_id_name:
216213
resource_id = kwargs[resource_id_name]
217214
else:

src/app/core/exceptions.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,3 @@ class InvalidRequestError(Exception):
88
def __init__(self, message="Type of request not supported."):
99
self.message = message
1010
super().__init__(self.message)
11-
12-
13-
class InvalidOutputTypeError(Exception):
14-
def __init__(self, message="output_type not allowed. If caching, use dict"):
15-
self.message = message
16-
super().__init__(self.message)

src/app/crud/crud_base.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
_extract_matching_columns_from_schema,
1111
_extract_matching_columns_from_kwargs
1212
)
13-
from app.core.exceptions import InvalidOutputTypeError
14-
1513

1614
ModelType = TypeVar("ModelType")
1715
CreateSchemaType = TypeVar("CreateSchemaType", bound=BaseModel)
@@ -157,7 +155,6 @@ async def get_multi(
157155
offset: int = 0,
158156
limit: int = 100,
159157
schema_to_select: Union[Type[BaseModel], List[Type[BaseModel]], None] = None,
160-
output_type: Union[Type[dict], Type[list]] = dict,
161158
**kwargs: Any
162159
) -> Dict[str, Any]:
163160
"""
@@ -173,19 +170,13 @@ async def get_multi(
173170
Maximum number of rows to fetch. Default is 100.
174171
schema_to_select : Union[Type[BaseModel], List[Type[BaseModel]], None], optional
175172
Pydantic schema for selecting specific columns. Default is None to select all columns.
176-
output_type : Union[Type[dict], Type[list]], optional
177-
Desired output type of the result. Default is dict.
178173
kwargs : dict
179174
Filters to apply to the query.
180175
181176
Returns
182177
-------
183178
Dict[str, Any]
184179
Dictionary containing the fetched rows under 'data' key and total count under 'total_count'.
185-
186-
Note
187-
----
188-
- The cache decorator only works with output_type=dict (default)
189180
"""
190181
to_select = _extract_matching_columns_from_schema(model=self._model, schema=schema_to_select)
191182
stmt = select(*to_select) \
@@ -194,14 +185,7 @@ async def get_multi(
194185
.limit(limit)
195186

196187
result = await db.execute(stmt)
197-
row_data = result
198-
199-
if output_type == dict:
200-
data = [dict(row) for row in row_data.mappings()]
201-
elif output_type == list:
202-
data = row_data.all()
203-
else:
204-
raise InvalidOutputTypeError
188+
data = [dict(row) for row in result.mappings()]
205189

206190
total_count = await self.count(db=db, **kwargs)
207191

src/migrations/versions/0b33c76d0a38_.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)