Rename query command

This commit is contained in:
Sam Becker 2024-05-03 09:11:49 -05:00
parent e5c74335be
commit 8a2621c9e1
2 changed files with 8 additions and 8 deletions

View File

@ -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()

View File

@ -8,7 +8,7 @@ const pool = new Pool({
export type Primitive = string | number | boolean | undefined | null;
export const directQuery = async <T extends QueryResultRow = any>(
export const query = async <T extends QueryResultRow = any>(
queryString: string,
values: Primitive[],
) => {
@ -38,7 +38,7 @@ export const sql = <T extends QueryResultRow>(
result += `$${i}${strings[i] ?? ''}`;
}
return directQuery<T>(result, values);
return query<T>(result, values);
};
export const convertArrayToPostgresString = (array?: string[]) => array