import { Generated, Insertable, JSONColumnType, Selectable, Updateable, } from "kysely" import { db } from "./database" export async function createSubscription( subscription: PushSubscriptionJSON ): Promise { const inserted = await db .insertInto("subscription") .values({ subscription: JSON.stringify(subscription) }) .returningAll() .executeTakeFirst() return inserted! } export async function updateSubscription( subscription: PushSubscriptionJSON, id: number ): Promise { await db .updateTable("subscription") .set({ subscription: JSON.stringify(subscription) }) .where("id", "=", id) .executeTakeFirst() } export async function getSubscription(id: number) { return await db .selectFrom("subscription") .selectAll() .where("id", "=", id) .executeTakeFirst() } export interface SubscriptionTable { id: Generated subscription: JSONColumnType } export type Subscription = Selectable export type NewSubscription = Insertable export type SubscriptionUpdate = Updateable