Skip to content

Commit

Permalink
create supabase client
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezryr committed Sep 30, 2024
1 parent 6021f7a commit 2c7e9c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api/supabase/createClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createClient } from '@supabase/supabase-js';
import dotenv from 'dotenv';

dotenv.config();

if (
!process.env.NEXT_PUBLIC_SUPABASE_URL ||
!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
) {
throw new Error(
'No Supabase environment variables detected, please make sure they are in place!',
);
}

const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
);

export default supabase;
9 changes: 9 additions & 0 deletions api/supabase/queries/plantSeasonality.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Plant } from '@/types/schema';
import supabase from '../createClient';

export async function getPlantSeasonality(): Promise<Plant[]> {
const { data, error } = await supabase.rpc('get_plant_seasonality');
if (error)
throw new Error(`Error fetching plant seasonality: ${error.message}`);
return data;
}

0 comments on commit 2c7e9c5

Please sign in to comment.