]>
Commit | Line | Data |
---|---|---|
6ccc6f60 | 1 | import { createClient } from '@supabase/supabase-js'; |
852ee620 RBR |
2 | import { single, collection } from './supabase'; |
3 | import { supabase } from '$lib/config/config'; | |
a7cf03c1 | 4 | |
be1ce532 RBR |
5 | import type { Topic } from '$lib/data/types'; |
6 | ||
852ee620 RBR |
7 | const client = createClient(supabase.url, supabase.key); |
8 | ||
6ccc6f60 RBR |
9 | export const topic = (id: string, withPosts = false) => |
10 | single<Topic>( | |
11 | client | |
12 | .from('topics') | |
13 | .select( | |
14 | withPosts | |
15 | ? `*, | |
852ee620 RBR |
16 | forum: forums (*), |
17 | tags: topic_tags (*), | |
18 | posts ( | |
19 | *, | |
20 | author:author_id (*) | |
21 | ) | |
6ccc6f60 RBR |
22 | ` |
23 | : '*' | |
24 | ) | |
25 | .eq('id', id), | |
26 | null | |
27 | ); | |
28 | export const topicsForTag = (id: string) => | |
29 | collection<Topic>( | |
30 | client | |
31 | .from('topics') | |
32 | .select( | |
33 | ` | |
852ee620 | 34 | *,tags!inner(*) |
6ccc6f60 RBR |
35 | ` |
36 | ) | |
37 | .eq('tags.tag', id), | |
38 | [] | |
39 | ); |