]>
Commit | Line | Data |
---|---|---|
852ee620 RBR |
1 | import { createClient } from '@supabase/supabase-js' |
2 | import { single, collection } from './supabase'; | |
3 | import { supabase } from '$lib/config/config'; | |
a7cf03c1 | 4 | |
be1ce532 RBR |
5 | import type { Post } from '$lib/data/types'; |
6 | ||
852ee620 RBR |
7 | const client = createClient(supabase.url, supabase.key); |
8 | ||
9 | export const post = (id: string, withTopic = false) => single<Post>(client | |
10 | .from('posts') | |
11 | .select(withTopic ? `*, | |
12 | topic:topic_id ( | |
13 | * | |
14 | ) | |
15 | `: '*' ) | |
16 | .eq('id', id), | |
17 | null); | |
18 | export const postsForTopic = (id: string) => collection<Post>(client | |
19 | .from('posts') | |
20 | .select('*') | |
21 | .eq('topic_id', id) | |
22 | .order('created_at', { ascending: true }), | |
23 | []); |