import { prisma } from '@repo/db'; import { StorageAdapter } from 'grammy'; export class PrismaStorageAdapter implements StorageAdapter { async read(key: string): Promise { return prisma.telegramSession .findUnique({ where: { id: key, }, }) .then((session) => (session?.data as T) || undefined); } async write(key: string, data: T): Promise { await prisma.telegramSession.upsert({ where: { id: key, }, create: { id: key, data, }, update: { data, }, }); } async delete(key: string): Promise { await prisma.telegramSession.delete({ where: { id: key } }); } async has(key: string): Promise { return prisma.telegramSession.exists({ id: key }); } }