]> git.r.bdr.sh - rbdr/forum/blame - src/lib/stores/topics.ts
Use supabase
[rbdr/forum] / src / lib / stores / topics.ts
CommitLineData
852ee620
RBR
1import { createClient } from '@supabase/supabase-js'
2import { single, collection } from './supabase';
3import { supabase } from '$lib/config/config';
a7cf03c1 4
be1ce532
RBR
5import type { Topic } from '$lib/data/types';
6
852ee620
RBR
7const client = createClient(supabase.url, supabase.key);
8
9export 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);
21export const topicsForForum = (id: string) => collection<Topic>(client
22 .from('topics')
23 .select('*')
24 .eq('forum_id', id),
25 []);
26export const topicsForTag = (id: string) => collection<Topic>(client
27 .from('topics')
28 .select(`
29 *,tags!inner(*)
30 `)
31 .eq('tags.tag', id),
32 []);