Skip to content

Commit

Permalink
feat: queries to add and remove single or multiple trees (#2)
Browse files Browse the repository at this point in the history
* supabase queries to add and remove trees.

* query testing.
  • Loading branch information
AlexWang05 authored and christophertorres1 committed Nov 13, 2024
1 parent 9467743 commit 154cc08
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/supabase/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { supabase } from './client';

// Function to add a single tree
export async function addTree(species: string) {
const { error } = await supabase.rpc('add_tree', { species });

if (error) {
throw new Error(`Error adding tree: ${error.message}`);
}
}

// Function to add multiple trees
export async function addMultipleTrees(species: string, quantity: number) {
const { error } = await supabase.rpc('add_multiple_trees', {
species: species,
quantity: quantity,
});

if (error) {
throw new Error(`Error adding multiple trees: ${error.message}`);
}
}

// Function to remove a single tree by UUID
export async function removeTree(treeId: string) {
const { error } = await supabase.rpc('remove_tree', {
tree_uuid: treeId,
});

if (error) {
throw new Error(`Error removing tree: ${error.message}`);
}
}

// Function to remove multiple trees by a list of UUIDs
export async function removeMultipleTrees(treeIds: string[]) {
const { error } = await supabase.rpc('remove_multiple_trees', {
tree_uuids: treeIds,
});

if (error) {
throw new Error(`Error removing multiple trees: ${error.message}`);
}
}

0 comments on commit 154cc08

Please sign in to comment.