From 446347e2e40cc1c49893af2223ccff792171ec76 Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Tue, 28 Jan 2020 10:25:14 +0100 Subject: [PATCH] GROUP BY is working. --- src/queries.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/queries.js b/src/queries.js index 225f6b3..ac8c7db 100644 --- a/src/queries.js +++ b/src/queries.js @@ -8,18 +8,14 @@ export function escape_regex(s) { export function do_image_query(query, database, collection_path, collection_thumbs_path) { return new Promise(function (resolve, reject) { var queries = []; - var ids = []; // TODO: this is for always uniquifying because of GROUP BY apparent bug in AlaSQL queries.push(query); database.queries_async(queries).then(res => { var photos = []; if (res && Array.isArray(res)) { res.forEach(row => { - if (!ids.includes(row["id"])) { //uniquify - ids.push(row["id"]); //uniquify - var imagepath = process.env.PUBLIC_URL + collection_path + "/" + row["relativePath"] + "/" + row["name"]; - var thumbpath = process.env.PUBLIC_URL + collection_thumbs_path + "/" + row["uniqueHash"] + ".jpg"; - photos.push(create_photo(row["id"], row["name"], imagepath, thumbpath)); - } + var imagepath = process.env.PUBLIC_URL + collection_path + "/" + row["relativePath"] + "/" + row["name"]; + var thumbpath = process.env.PUBLIC_URL + collection_thumbs_path + "/" + row["uniqueHash"] + ".jpg"; + photos.push(create_photo(row["id"], row["name"], imagepath, thumbpath)); }); } resolve(photos); @@ -223,9 +219,7 @@ export class UserQuery { // This query will return database entries with the fields "id", "uniqueHash", "relativePath" (of the album) and "name" for each matching image. export function image_query_with_where(maybe_where) { - return "SELECT Images.id, Images.name, Images.uniqueHash, Albums.relativePath FROM Images INNER JOIN Albums ON Images.album=Albums.id LEFT JOIN ImageTags ON Images.id=ImageTags.imageid LEFT JOIN Tags ON ImageTags.tagid=Tags.id " + (maybe_where ? maybe_where : ""); - // TODO: the following for some reason breaks the query: - //+ " GROUP BY Images.id;"; + return "SELECT Images.id, Images.name, Images.uniqueHash, Albums.relativePath FROM Images INNER JOIN Albums ON Images.album=Albums.id LEFT JOIN ImageTags ON Images.id=ImageTags.imageid LEFT JOIN Tags ON ImageTags.tagid=Tags.id " + (maybe_where ? maybe_where : "" + " GROUP BY id;"); } // This query will return database entries with the fields "id" and "relativePath" for each matching album.