]> git.r.bdr.sh - rbdr/forum/blame - src/lib/stores/posts.ts
Use supabase
[rbdr/forum] / src / lib / stores / posts.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 { Post } from '$lib/data/types';
6
852ee620
RBR
7const client = createClient(supabase.url, supabase.key);
8
9export 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);
18export const postsForTopic = (id: string) => collection<Post>(client
19 .from('posts')
20 .select('*')
21 .eq('topic_id', id)
22 .order('created_at', { ascending: true }),
23 []);