Skip to content

Commit

Permalink
Search by multiple tags gregordr#59
Browse files Browse the repository at this point in the history
  • Loading branch information
unyacat committed Dec 27, 2021
1 parent 75e9929 commit 818483a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions backend/src/database/mediaDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ export const media = (async () => {
})()

export async function getMedia(searchTerm: string, label: string): Promise<unknown[]> {
const queryWords = label.split(/\s+/);
return transaction(async (client) => {
const result = await client.query(`SELECT OID::text as id, ${photo} as name, h as height, w as width, date as date, type as type, coordX as coordX, coordY as coordY FROM ${await media} WHERE
const result = await client.query(`SELECT OID::text as id, ${photo} as name, h as height, w as width, date as date, type as type, coordX as coordX, coordY as coordY FROM ${await media} WHERE
(
${photo} like $1::text
OR
OID IN
(
SELECT photo
FROM ${await labelTable}
WHERE label = $2::text
WHERE label = ANY ($2)
GROUP BY photo
HAVING COUNT( photo )=$3::integer
)
)
ORDER BY date DESC
;`, [searchTerm, label]);
;`, [searchTerm, queryWords, queryWords.length]);
return result.rows;
});
}
Expand Down

0 comments on commit 818483a

Please sign in to comment.