]> git.r.bdr.sh - rbdr/forum/blob - src/lib/stores/forums.ts
40a3f2cc89d580c0abb8e477926558f9471701a5
[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) => single<Forum>(client
10 .from('forums')
11 .select(withTopics ? `*,
12 topics (
13 *
14 )
15 `: '*' )
16 .eq('id', id),
17 null);
18 export const forums = collection<Forum>(client.from('forums').select('*'), []);