Something went wrong. Try again.
Schedule posts and reposts to Bluesky (and other PDSes) with Cloudflare workers. skyscheduler.work
scheduling social-media cloudflare bsky service cloudflare-workers bsky-tool bluesky
Something went wrong. Try again.
1.5 kB · 42 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142// this is an extensive class shim that allows us to specify a single DB object but use read replicas// since drizzle does not support it yet.import { USE_READ_REPLICAS } from "../config";
// however we see fit.export class ExtendedD1Database implements D1Database { DB: D1Database|D1DatabaseSession; isReplica: boolean;
constructor(inDB: D1Database) { this.DB = (USE_READ_REPLICAS) ? inDB.withSession() : inDB; this.isReplica = USE_READ_REPLICAS; } prepare(query: string): D1PreparedStatement { return this.DB.prepare(query); } async batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]> { return this.DB.batch(statements); } // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents withSession(constraintOrBookmark?: D1SessionBookmark | D1SessionConstraint): D1DatabaseSession { if (this.DB instanceof D1DatabaseSession) { return this.DB; } return this.DB.withSession(constraintOrBookmark); } async exec(query: string): Promise<D1ExecResult> { if (this.DB instanceof D1DatabaseSession) { const results = await this.DB.prepare(query).run(); return { count: results.meta.changes, duration: results.meta.duration }; } return this.DB.exec(query); } // eslint-disable-next-line @typescript-eslint/require-await async dump(): Promise<ArrayBuffer> { // this function is deprecated, it should do nothing. return new ArrayBuffer(); }}