]> git.r.bdr.sh - rbdr/forum/blob - src/lib/stores/forums.ts
Don't remember what this WIP was about
[rbdr/forum] / src / lib / stores / forums.ts
1 import { createClient } from '@supabase/supabase-js';
2 import { single, collection } from './supabase';
3 import { supabase } from '$lib/config/config';
4
5 import type { Forum } from '$lib/data/types';
6
7 const client = createClient(supabase.url, supabase.key);
8
9 export const forum = (id: string, withTopics = false) =>
10 single<Forum>(
11 client
12 .from('forums')
13 .select(
14 withTopics
15 ? `*,
16 topics (
17 *
18 )
19 `
20 : '*'
21 )
22 .eq('id', id),
23 null
24 );
25 export const forums = collection<Forum>(client.from('forums').select('*'), []);