Skip to content

Commit

Permalink
Merge pull request #66 from AlexSciFier/fixes-for-queries
Browse files Browse the repository at this point in the history
Fixes for queries
  • Loading branch information
AlexSciFier authored Aug 25, 2023
2 parents e4fbdce + 1e4bf16 commit 65c8a2e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 44 deletions.
2 changes: 1 addition & 1 deletion frontend/src/helpers/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const APP_NAME = "NeonLink";
export const VERSION = "1.4.6";
export const VERSION = "1.4.7";
export const DEF_MAX_ITEMS = 20;
export const DEF_COLUMNS = 3;
export const CARD_HEADER_STYLE = [
Expand Down
14 changes: 7 additions & 7 deletions server/db/sqlite/stores/backgrounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export default class BackgroundsStore {

deleteItem(id, userId) {
const deleteQuery = `DELETE FROM backgrounds WHERE id=:id`;
let deleteParams = {id};
let deleteParams = { id };
if (userId) {
deleteQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)";
deleteParams += { userId };
deleteParams.userId = userId;
}
return this.db.prepare(deleteQuery).run(deleteParams).changes;
}
Expand All @@ -23,28 +23,28 @@ export default class BackgroundsStore {
let selectParams = {};
if (userId) {
selectQuery += " WHERE userId IN (:userId, 0) OR userId IS NULL";
selectParams += { userId };
selectParams.userId = userId;
}

return this.db.prepare(selectQuery).all(selectParams);
}

getItemById(id, userId) {
let selectQuery = `SELECT * FROM backgrounds WHERE id=:id`;
let selectParams = {id};
let selectParams = { id };
if (userId) {
selectQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)";
selectParams += { userId };
selectParams.userId = userId;
}
return this.db.prepare(selectQuery).all(selectParams);
}

getItemByUrl(url, userId) {
let selectQuery = `SELECT * FROM backgrounds WHERE url=:url`;
let selectParams = {url};
let selectParams = { url };
if (userId) {
selectQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)";
selectParams += { userId };
selectParams.userId = userId;
}
return this.db.prepare(selectQuery).all(selectParams);
}
Expand Down
55 changes: 34 additions & 21 deletions server/db/sqlite/stores/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export default class BookmarksStore {
selectParams.userId = userId;
}

selectQuery += ` WHERE ${conditions.join(" AND ")}`;
if (conditions.length > 0)
selectQuery += ` WHERE ${conditions.join(" AND ")}`;

selectQuery += ` GROUP BY bookmarks.id
ORDER BY bookmarks.created DESC`;
Expand Down Expand Up @@ -151,7 +152,9 @@ export default class BookmarksStore {
let conditions = [];

if (userId) {
conditions.push("(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)");
conditions.push(
"(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)"
);
countParams.userId = userId;
selectParams.userId = userId;
}
Expand Down Expand Up @@ -203,15 +206,20 @@ export default class BookmarksStore {
FROM bookmarks
LEFT JOIN bookmarkPosition ON bookmarks.id = bookmarkPosition.bookmarkId
`;
let selectParams = { categoryId, userId }
let selectParams = { categoryId, userId };

let conditions = []
conditions.push("bookmarks.categoryId = :categoryId")
if(userId){
conditions.push("(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)")
let conditions = [];
conditions.push("bookmarks.categoryId = :categoryId");
if (userId) {
conditions.push(
"(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)"
);
}
selectQuery += `WHERE ${conditions.join(" AND ")} `
selectQuery += "ORDER BY bookmarkPosition.position"

if (conditions.length > 0)
selectQuery += `WHERE ${conditions.join(" AND ")} `;

selectQuery += "ORDER BY bookmarkPosition.position";

return this.db
.prepare(selectQuery)
Expand All @@ -234,24 +242,29 @@ export default class BookmarksStore {
LEFT JOIN bookmarksTags ON bookmarksTags.bookmarkId = bookmarks.id
LEFT JOIN tags ON bookmarksTags.tagId = tags.id
`;
let selectParams = {id}
let conditions = ["bookmarks.id = :id"]
conditions.push()
if(userId){
conditions.push("(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)")
selectParams.userId = userId
let selectParams = { id };
let conditions = ["bookmarks.id = :id"];
conditions.push();
if (userId) {
conditions.push(
"(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)"
);
selectParams.userId = userId;
}
selectQuery += `WHERE ${conditions.join(" AND ")} `
selectQuery += `GROUP BY bookmarks.id`

if (conditions.length > 0)
selectQuery += `WHERE ${conditions.join(" AND ")} `;

selectQuery += `GROUP BY bookmarks.id`;
return this.db.prepare(selectQuery).get(selectParams);
}

getItemByUrl(userId, url) {
let selectQuery = `SELECT * FROM bookmarks WHERE url = :url`;
let selectParams = {url}
if(userId){
selectQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)"
selectParams.userId = userId
let selectParams = { url };
if (userId) {
selectQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)";
selectParams.userId = userId;
}
return this.db.prepare(selectQuery).get(selectParams);
}
Expand Down
33 changes: 18 additions & 15 deletions server/db/sqlite/stores/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export default class CategoriesStore {
getAll(userId) {
let selectQuery = `SELECT
id, name, color, position FROM category
INNER JOIN categoryPosition ON categoryPosition.categoryId = category.id`
let selectParams = {}
if(userId){
selectQuery += ` WHERE (userId IN (:userId, 0) OR userId IS NULL) `
selectParams.userId = userId
}
selectQuery += ` ORDER BY position ASC`;
INNER JOIN categoryPosition ON categoryPosition.categoryId = category.id`;
let selectParams = {};
if (userId) {
selectQuery += ` WHERE (userId IN (:userId, 0) OR userId IS NULL) `;
selectParams.userId = userId;
}
selectQuery += ` ORDER BY position ASC`;

return this.db.prepare(selectQuery).all(selectParams);
}
Expand All @@ -51,15 +51,18 @@ export default class CategoriesStore {
INNER JOIN categoryPosition ON categoryPosition.categoryId = category.id
`;
let selectParams = {name}
let conditions = []
conditions.push("name = :name")
if(userId){
conditions.push("(userId IN (:userId, 0) OR userId IS NULL)")
selectParams.userId = userId
let selectParams = { name };
let conditions = [];
conditions.push("name = :name");
if (userId) {
conditions.push("(userId IN (:userId, 0) OR userId IS NULL)");
selectParams.userId = userId;
}
selectQuery += ` WHERE ${conditions.join(" AND ")} `
selectQuery += `ORDER BY position ASC`

if (conditions.length > 0)
selectQuery += ` WHERE ${conditions.join(" AND ")} `;

selectQuery += `ORDER BY position ASC`;
return this.db.prepare(selectQuery).get(selectParams);
}

Expand Down

0 comments on commit 65c8a2e

Please sign in to comment.