]> git.r.bdr.sh - rbdr/forum/blob - src/lib/stores/posts.ts
Use supabase
[rbdr/forum] / src / lib / stores / posts.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 { Post } from '$lib/data/types';
6
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 []);