Add query for tagging multiple photos arbitrarily
This commit is contained in:
parent
ac5f709c3d
commit
f7984600e1
@ -243,6 +243,19 @@ export const renamePhotoTagGlobally = (tag: string, updatedTag: string) =>
|
||||
WHERE ${tag}=ANY(tags)
|
||||
`, 'renamePhotoTagGlobally');
|
||||
|
||||
export const addTagsToPhotos = (tags: string[], photoIds: string[]) =>
|
||||
safelyQueryPhotos(() => sql`
|
||||
UPDATE photos
|
||||
SET tags = (
|
||||
SELECT array_agg(DISTINCT elem)
|
||||
FROM unnest(
|
||||
array_cat(tags, ARRAY${convertArrayToPostgresString(tags, 'brackets')})
|
||||
) AS elem
|
||||
)
|
||||
WHERE id IN ${convertArrayToPostgresString(photoIds, 'brackets')}
|
||||
LIMIT ${photoIds.length}
|
||||
`, 'addTagsToPhotos');
|
||||
|
||||
export const deletePhoto = (id: string) =>
|
||||
safelyQueryPhotos(() => sql`
|
||||
DELETE FROM photos WHERE id=${id}
|
||||
|
||||
@ -41,8 +41,13 @@ export const sql = <T extends QueryResultRow>(
|
||||
return query<T>(result, values);
|
||||
};
|
||||
|
||||
export const convertArrayToPostgresString = (array?: string[]) => array
|
||||
? `{${array.join(',')}}`
|
||||
export const convertArrayToPostgresString = (
|
||||
array?: string[],
|
||||
type: 'braces' | 'brackets' = 'braces',
|
||||
) => array
|
||||
? type === 'braces'
|
||||
? `{${array.join(',')}}`
|
||||
: `[${array.map(i => `'${i}'`).join(',')}]`
|
||||
: null;
|
||||
|
||||
const isTemplateStringsArray = (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user