diff --git a/src/photo/db.ts b/src/photo/db.ts index b4952e14..49e4ffb4 100644 --- a/src/photo/db.ts +++ b/src/photo/db.ts @@ -1,6 +1,6 @@ import { sql, - directQuery, + query, convertArrayToPostgresString, } from '@/services/postgres'; import { @@ -353,7 +353,7 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => { sortBy = PRIORITY_ORDER_ENABLED ? 'priority' : 'takenAt', limit = PHOTO_DEFAULT_LIMIT, offset = 0, - query, + query: queryOption, tag, camera, simulation, @@ -379,10 +379,10 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => { wheres.push(`taken_at <= $${valueIndex++}`); values.push(takenAfterInclusive.toISOString()); } - if (query) { + if (queryOption) { // eslint-disable-next-line max-len wheres.push(`CONCAT(title, ' ', caption, ' ', semantic_description) ILIKE $${valueIndex++}`); - values.push(`%${query.toLocaleLowerCase()}%`); + values.push(`%${queryOption.toLocaleLowerCase()}%`); } if (tag) { wheres.push(`$${valueIndex++}=ANY(tags)`); @@ -420,7 +420,7 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => { values.push(limit, offset); return safelyQueryPhotos(async () => { - return directQuery(sql.join(' '), values); + return query(sql.join(' '), values); }, sql.join(' ')) .then(({ rows }) => rows.map(parsePhotoFromDb)); }; @@ -434,7 +434,7 @@ export const getPhotosNearId = async ( : 'ORDER BY taken_at DESC'; return safelyQueryPhotos(async () => { - return directQuery( + return query( ` WITH twi AS ( SELECT *, row_number() diff --git a/src/services/postgres.ts b/src/services/postgres.ts index 2ca48ac6..c6442e92 100644 --- a/src/services/postgres.ts +++ b/src/services/postgres.ts @@ -8,7 +8,7 @@ const pool = new Pool({ export type Primitive = string | number | boolean | undefined | null; -export const directQuery = async ( +export const query = async ( queryString: string, values: Primitive[], ) => { @@ -38,7 +38,7 @@ export const sql = ( result += `$${i}${strings[i] ?? ''}`; } - return directQuery(result, values); + return query(result, values); }; export const convertArrayToPostgresString = (array?: string[]) => array