summaryrefslogtreecommitdiff
path: root/bucky/db/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'bucky/db/index.js')
-rw-r--r--bucky/db/index.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/bucky/db/index.js b/bucky/db/index.js
index 8ab29ff..36541f8 100644
--- a/bucky/db/index.js
+++ b/bucky/db/index.js
@@ -114,6 +114,38 @@ db.getLastlog = function (limit) {
.limit(limit || 10);
};
+/** HOOTSTREAM */
+
+db.getHootstreamFiles = ({ limit, offset }) =>
+ knex("files")
+ .join("threads", "threads.id", "=", "files.thread")
+ .select("files.*")
+ .where("threads.privacy", false)
+ .orderBy("files.id", "desc")
+ .offset(offset)
+ .limit(limit);
+db.getHootstreamComments = ({ limit, offset }) =>
+ knex("comments")
+ .join("threads", "threads.id", "=", "comments.thread")
+ .select("comments.*")
+ .where("threads.privacy", false)
+ .orderBy("comments.id", "desc")
+ .offset(offset)
+ .limit(limit);
+db.getHootstreamThreads = ({ files, comments }) =>
+ Thread.where((builder) =>
+ builder.whereIn(
+ "id",
+ Array.from(
+ new Set(
+ [...comments, ...files]
+ .map((item) => item?.thread)
+ .filter((item) => !!item)
+ )
+ )
+ )
+ ).fetchAll();
+
/* THREADS */
db.getLatestThreads = function () {
@@ -149,6 +181,7 @@ db.getThreadsById = function (ids) {
return Thread.where("id", "in", ids).fetchAll();
};
db.createThread = function (data) {
+ console.log(data);
return new db.Thread(data).save();
};
db.updateThread = function (data) {};