hippofish/packages/backend/src/db/scylla.ts

90 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-07-19 16:35:47 +02:00
import config from "@/config/index.js";
2023-07-24 04:29:38 +02:00
import { DriveFile } from "@/models/entities/drive-file.js";
2023-07-19 16:35:47 +02:00
import { Client } from "cassandra-driver";
function newClient(): Client | null {
if (!config.scylla) {
return null;
}
return new Client({
contactPoints: config.scylla.nodes,
2023-07-24 11:35:44 +02:00
localDataCenter: config.scylla.localDataCentre,
2023-07-19 16:35:47 +02:00
keyspace: config.scylla.keyspace,
});
}
export const scyllaClient = newClient();
export const prepared = {
2023-07-24 11:35:44 +02:00
note: {
2023-07-19 16:35:47 +02:00
insert: `INSERT INTO note (
2023-07-24 11:35:44 +02:00
"createdAtDate",
"createdAt",
"id",
"visibility",
"content",
"name",
"cw",
"localOnly",
"renoteCount",
"repliesCount",
"uri",
"url",
"score",
"files",
"visibleUsersId",
"mentions",
"emojis",
"tags",
"hasPoll",
"threadId",
"channelId",
"channelName",
"userId",
"replyId",
"renoteId",
"reactions",
"reactionEmojis",
"noteEdit",
"updatedAt"
2023-07-19 16:35:47 +02:00
)
VALUES
2023-07-24 11:35:44 +02:00
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2023-07-19 16:35:47 +02:00
select: {
2023-07-24 11:35:44 +02:00
byDate: `SELECT * FROM note WHERE "createdAtDate" = ? AND "createdAt" < ?`,
2023-07-24 13:52:35 +02:00
byId: `SELECT * FROM note WHERE "id" IN ?`,
byUri: `SELECT * FROM note WHERE "uri" = ?`,
byUrl: `SELECT * FROM note WHERE "url" = ?`,
2023-07-24 11:35:44 +02:00
byUserId: `SELECT * FROM note_by_userid WHERE "userId" = ? AND "createdAt" < ?`,
2023-07-19 16:35:47 +02:00
},
2023-07-24 13:52:35 +02:00
delete: `DELETE FROM note WHERE "createdAtDate" = ? AND "createdAt" = ?`,
2023-07-24 11:35:44 +02:00
update: {
2023-07-24 13:52:35 +02:00
renoteCount: `UPDATE note SET "renoteCount" = ?, "score" = ? WHERE "createdAtDate" = ? AND "createdAt" = ? IF EXISTS`,
reactions: `UPDATE note SET "reactions" = ?, "score" = ? WHERE "createdAtDate" = ? AND "createdAt" = ? IF EXISTS`,
},
2023-07-19 16:35:47 +02:00
},
2023-07-24 11:35:44 +02:00
reaction: {
2023-07-24 13:52:35 +02:00
insert: `INSERT INTO reaction
("id", "noteId", "userId", "reaction", "emoji", "createdAt")
VALUES (?, ?, ?, ?, ?, ?)`,
2023-07-24 11:35:44 +02:00
},
};
2023-07-24 04:29:38 +02:00
export interface ScyllaDriveFile {
id: string;
type: string;
createdAt: Date;
name: string;
comment: string | null;
blurhash: string | null;
url: string;
thumbnailUrl: string;
isSensitive: boolean;
isLink: boolean;
md5: string;
size: number;
width: number;
height: number;
}