]> git.r.bdr.sh - rbdr/forum/blob - src/lib/stores/posts.ts
388eed3aef9bbbecfe2591474966b704279ed8cc
[rbdr/forum] / src / lib / stores / posts.ts
1 import { createClient } from '@supabase/supabase-js';
2 import { single } 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) =>
10 single<Post>(
11 client
12 .from('posts')
13 .select(
14 withTopic
15 ? `*,
16 topic:topic_id (
17 *
18 )
19 `
20 : '*'
21 )
22 .eq('id', id),
23 null
24 );