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

81 lines
1.6 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,
keyspace: config.scylla.keyspace,
});
}
export const scyllaClient = newClient();
export const prepared = {
timeline: {
insert: `INSERT INTO note (
2023-07-24 04:29:38 +02:00
createdAtDate,
createdAt,
2023-07-19 16:35:47 +02:00
id,
visibility,
content,
name,
cw,
2023-07-24 04:29:38 +02:00
localOnly,
renoteCount,
repliesCount,
2023-07-19 16:35:47 +02:00
uri,
url,
score,
files,
2023-07-24 04:29:38 +02:00
visibleUsersId,
2023-07-19 16:35:47 +02:00
mentions,
emojis,
tags,
2023-07-24 04:29:38 +02:00
hasPoll,
threadId,
channelId,
channelName,
userId,
userId,
replyId,
renoteId,
2023-07-19 16:35:47 +02:00
reactions,
2023-07-24 04:29:38 +02:00
reactionEmojis
noteEdit,
updatedAt,
2023-07-19 16:35:47 +02:00
)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
select: {
2023-07-24 04:29:38 +02:00
byDate: "SELECT * FROM note WHERE createdAtDate = ? AND createdAt < ?",
2023-07-19 16:35:47 +02:00
byId: "SELECT * FROM note WHERE id IN ?",
byUri: "SELECT * FROM note WHERE uri = ?",
byUrl: "SELECT * FROM note WHERE url = ?",
2023-07-24 04:29:38 +02:00
byUserId: "SELECT * FROM note WHERE userId = ? AND createdAt < ?",
2023-07-19 16:35:47 +02:00
},
delete: "DELETE FROM note WHERE id IN ?",
},
}
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;
}