Something went wrong. Try again.
A Takuzu game native to the AT Protocol. atkuzu.tomplanche.com
binairo atproto game takuzu
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546// A key value key to the database that is mostly used for atproto session storage and state storage during the oauth session creation// The "stores" are divided up by a where on the store type so it can share the same interface just with that
import { db } from "./db";import { keyValueStore } from "./db/schema";import { and, eq } from "drizzle-orm";
export const SESSION_STORE = "sessions";export const STATE_STORE = "states";
export class Cache { db: typeof db; cacheName: string;
constructor(database: typeof db, cacheName: string) { this.db = database; this.cacheName = cacheName; }
async get(key: string) { const result = await this.db .select() .from(keyValueStore) .where(and(eq(keyValueStore.key, key), eq(keyValueStore.storeName, this.cacheName))) .limit(1); if (result.length > 0) { return result[0].value; } return null; }
async set(key: string, value: string) { return this.db .insert(keyValueStore) .values({ key, value, storeName: this.cacheName, createdAt: new Date() }) .onConflictDoUpdate({ target: keyValueStore.key, set: { value, createdAt: new Date() } }); }
async delete(key: string) { return this.db.delete(keyValueStore).where(eq(keyValueStore.key, key)); }}