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 { import {
sql, sql,
directQuery, query,
convertArrayToPostgresString, convertArrayToPostgresString,
} from '@/services/postgres'; } from '@/services/postgres';
import { import {
@ -353,7 +353,7 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => {
sortBy = PRIORITY_ORDER_ENABLED ? 'priority' : 'takenAt', sortBy = PRIORITY_ORDER_ENABLED ? 'priority' : 'takenAt',
limit = PHOTO_DEFAULT_LIMIT, limit = PHOTO_DEFAULT_LIMIT,
offset = 0, offset = 0,
query, query: queryOption,
tag, tag,
camera, camera,
simulation, simulation,
@ -379,10 +379,10 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => {
wheres.push(`taken_at <= $${valueIndex++}`); wheres.push(`taken_at <= $${valueIndex++}`);
values.push(takenAfterInclusive.toISOString()); values.push(takenAfterInclusive.toISOString());
} }
if (query) { if (queryOption) {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
wheres.push(`CONCAT(title, ' ', caption, ' ', semantic_description) ILIKE $${valueIndex++}`); wheres.push(`CONCAT(title, ' ', caption, ' ', semantic_description) ILIKE $${valueIndex++}`);
values.push(`%${query.toLocaleLowerCase()}%`); values.push(`%${queryOption.toLocaleLowerCase()}%`);
} }
if (tag) { if (tag) {
wheres.push(`$${valueIndex++}=ANY(tags)`); wheres.push(`$${valueIndex++}=ANY(tags)`);
@ -420,7 +420,7 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => {
values.push(limit, offset); values.push(limit, offset);
return safelyQueryPhotos(async () => { return safelyQueryPhotos(async () => {
return directQuery(sql.join(' '), values); return query(sql.join(' '), values);
}, sql.join(' ')) }, sql.join(' '))
.then(({ rows }) => rows.map(parsePhotoFromDb)); .then(({ rows }) => rows.map(parsePhotoFromDb));
}; };
@ -434,7 +434,7 @@ export const getPhotosNearId = async (
: 'ORDER BY taken_at DESC'; : 'ORDER BY taken_at DESC';
return safelyQueryPhotos(async () => { return safelyQueryPhotos(async () => {
return directQuery( return query(
` `
WITH twi AS ( WITH twi AS (
SELECT *, row_number() SELECT *, row_number()

View File

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