diff --git a/.vscode/settings.json b/.vscode/settings.json index 52fcf281..7ce3345f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,6 +12,7 @@ "sonner", "thephotoblog", "trpc", + "unnest", "WRHGZC", "zadd", "zrange" diff --git a/src/services/postgres.ts b/src/services/postgres.ts index 7c20c9ff..5c288faf 100644 --- a/src/services/postgres.ts +++ b/src/services/postgres.ts @@ -246,6 +246,10 @@ export const getPhotosCount = async () => sql` SELECT COUNT(*) FROM photos `.then(({ rows }) => parseInt(rows[0].count, 10)); +export const getUniqueTags = async () => sql` + SELECT DISTINCT unnest(tags) FROM photos +`.then(({ rows }) => rows.map(row => row.unnest as string)); + export const getPhoto = async (id: string): Promise => { // Check for photo id forwarding // and convert short ids to uuids