This commit is contained in:
2026-01-29 12:26:13 +01:00
parent ba0f116bc2
commit 6dbcadcaee
79 changed files with 2795 additions and 657 deletions

View File

@@ -0,0 +1,31 @@
/**
* Message repository - handles all message-related database operations
*/
import { and, eq } from "drizzle-orm";
import { db } from "../connection";
import { messages, users, type InsertMessage, type Message } from "../schema";
export const messageRepository = {
async create(message: InsertMessage): Promise<void> {
await db.insert(messages).values(message);
},
async findByChannel(
guildId: string,
channelId: string
): Promise<Array<{ message: Message; userName: string | null }>> {
const results = await db
.select()
.from(messages)
.where(
and(eq(messages.guild_id, guildId), eq(messages.channel_id, channelId))
)
.leftJoin(users, eq(users.id, messages.user_id));
return results.map((r) => ({
message: r.messages,
userName: r.users?.name ?? null,
}));
},
};