@@ -34,7 +34,7 @@ async def search_signals(cursor: AsyncCursor, filters: SignalFilters) -> SignalP
34
34
page : SignalPage
35
35
Paginated search results for signals.
36
36
"""
37
- query = """
37
+ query = f """
38
38
SELECT
39
39
*, COUNT(*) OVER() AS total_count
40
40
FROM
@@ -84,17 +84,13 @@ async def search_signals(cursor: AsyncCursor, filters: SignalFilters) -> SignalP
84
84
AND (%(unit)s IS NULL OR unit_region = %(unit)s OR unit_name = %(unit)s)
85
85
AND (%(query)s IS NULL OR text_search_field @@ websearch_to_tsquery('english', %(query)s))
86
86
ORDER BY
87
- {} {}
87
+ { filters . order_by } { filters . direction }
88
88
OFFSET
89
89
%(offset)s
90
90
LIMIT
91
91
%(limit)s
92
92
;
93
93
"""
94
- query = sql .SQL (query ).format (
95
- sql .Identifier (filters .order_by ),
96
- sql .SQL (filters .direction ),
97
- )
98
94
await cursor .execute (query , filters .model_dump ())
99
95
rows = await cursor .fetchall ()
100
96
# extract total count of rows matching the WHERE clause
@@ -112,7 +108,8 @@ async def create_signal(cursor: AsyncCursor, signal: Signal) -> int:
112
108
cursor : AsyncCursor
113
109
An async database cursor.
114
110
signal : Signal
115
- A signal object to insert.
111
+ A signal object to insert. The following fields are supported:
112
+ - secondary_location: list[str] | None
116
113
117
114
Returns
118
115
-------
@@ -137,6 +134,7 @@ async def create_signal(cursor: AsyncCursor, signal: Signal) -> int:
137
134
relevance,
138
135
keywords,
139
136
location,
137
+ secondary_location,
140
138
score
141
139
)
142
140
VALUES (
@@ -156,6 +154,7 @@ async def create_signal(cursor: AsyncCursor, signal: Signal) -> int:
156
154
%(relevance)s,
157
155
%(keywords)s,
158
156
%(location)s,
157
+ %(secondary_location)s,
159
158
%(score)s
160
159
)
161
160
RETURNING
@@ -221,7 +220,8 @@ async def read_signal(cursor: AsyncCursor, uid: int) -> Signal | None:
221
220
;
222
221
"""
223
222
await cursor .execute (query , (uid ,))
224
- if (row := await cursor .fetchone ()) is None :
223
+ row = await cursor .fetchone ()
224
+ if row is None :
225
225
return None
226
226
return Signal (** row )
227
227
@@ -236,7 +236,8 @@ async def update_signal(cursor: AsyncCursor, signal: Signal) -> int | None:
236
236
cursor : AsyncCursor
237
237
An async database cursor.
238
238
signal : Signal
239
- A signal object to update.
239
+ A signal object to update. The following fields are supported:
240
+ - secondary_location: list[str] | None
240
241
241
242
Returns
242
243
-------
@@ -263,6 +264,7 @@ async def update_signal(cursor: AsyncCursor, signal: Signal) -> int | None:
263
264
relevance = COALESCE(%(relevance)s, relevance),
264
265
keywords = COALESCE(%(keywords)s, keywords),
265
266
location = COALESCE(%(location)s, location),
267
+ secondary_location = COALESCE(%(secondary_location)s, secondary_location),
266
268
score = COALESCE(%(score)s, score)
267
269
WHERE
268
270
id = %(id)s
@@ -271,7 +273,8 @@ async def update_signal(cursor: AsyncCursor, signal: Signal) -> int | None:
271
273
;
272
274
"""
273
275
await cursor .execute (query , signal .model_dump ())
274
- if (row := await cursor .fetchone ()) is None :
276
+ row = await cursor .fetchone ()
277
+ if row is None :
275
278
return None
276
279
signal_id = row ["id" ]
277
280
@@ -308,7 +311,8 @@ async def delete_signal(cursor: AsyncCursor, uid: int) -> Signal | None:
308
311
"""
309
312
query = "DELETE FROM signals WHERE id = %s RETURNING *;"
310
313
await cursor .execute (query , (uid ,))
311
- if (row := await cursor .fetchone ()) is None :
314
+ row = await cursor .fetchone ()
315
+ if row is None :
312
316
return None
313
317
signal = Signal (** row )
314
318
if signal .attachment is not None :
@@ -358,7 +362,8 @@ async def read_user_signals(
358
362
;
359
363
"""
360
364
await cursor .execute (query , (user_email , status ))
361
- return [Signal (** row ) async for row in cursor ]
365
+ rows = await cursor .fetchall ()
366
+ return [Signal (** row ) for row in rows ]
362
367
363
368
364
369
async def is_signal_favorited (cursor : AsyncCursor , user_email : str , signal_id : int ) -> bool :
0 commit comments