]> git.r.bdr.sh - rbdr/forum/blob - src/lib/stores/topics.ts
04c1e9e7770a80ab1dd739a023e489cb6699a364
[rbdr/forum] / src / lib / stores / topics.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 { Topic } from '$lib/data/types';
6
7 const client = createClient(supabase.url, supabase.key);
8
9 export const topic = (id: string, withPosts = false) => single<Topic>(client
10 .from('topics')
11 .select(withPosts ? `*,
12 forum: forums (*),
13 tags: topic_tags (*),
14 posts (
15 *,
16 author:author_id (*)
17 )
18 `: '*' )
19 .eq('id', id),
20 null);
21 export const topicsForForum = (id: string) => collection<Topic>(client
22 .from('topics')
23 .select('*')
24 .eq('forum_id', id),
25 []);
26 export const topicsForTag = (id: string) => collection<Topic>(client
27 .from('topics')
28 .select(`
29 *,tags!inner(*)
30 `)
31 .eq('tags.tag', id),
32 []);