lib/kvdb.ts (view raw)
1const kv = await Deno.openKv();
2
3export const saveStop = (stop: Stop) => kv.set([stop.stopRef], stop);
4
5export const saveStops = async (stops: Stop[]) => {
6 for (const stop of stops) await saveStop(stop);
7};
8
9export const getStopByRef = (stopRef: string) => kv.get<Stop>([stopRef]);
10
11export const saveUserFavorite = (userId: string, stop: Stop) =>
12 kv.set([userId, "favorites", stop.stopRef], stop);
13
14export const getUserFavorites = (userId: string) =>
15 kv.list<Stop>({ prefix: [userId] });
16
17export const getUserFavorite = (userId: string, stopRef: string) =>
18 kv.get<Stop>([userId, "favorites", stopRef]);