-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic supabase queries to add and remove trees
- Loading branch information
1 parent
97b0490
commit ebb481e
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { supabase } from './client'; | ||
|
||
// Function to add a single tree | ||
export async function addTree(species: string) { | ||
const { data, error } = await supabase.rpc('add_tree', { species }); | ||
|
||
if (error) { | ||
throw new Error(`Error adding tree: ${error.message}`); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
// Function to add multiple trees | ||
export async function addMultipleTrees(species: string, quantity: number) { | ||
const { data, error } = await supabase.rpc('add_multiple_trees', { | ||
species, | ||
quantity, | ||
}); | ||
|
||
if (error) { | ||
throw new Error(`Error adding multiple trees: ${error.message}`); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
// Function to remove a single tree by UUID | ||
export async function removeTree(treeId: string) { | ||
const { data, error } = await supabase.rpc('remove_tree', { | ||
tree_id: treeId, | ||
}); | ||
|
||
if (error) { | ||
throw new Error(`Error removing tree: ${error.message}`); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
// Function to remove multiple trees by a list of UUIDs | ||
export async function removeMultipleTrees(treeIds: string[]) { | ||
const { data, error } = await supabase.rpc('remove_multiple_trees', { | ||
tree_ids: treeIds, | ||
}); | ||
|
||
if (error) { | ||
throw new Error(`Error removing multiple trees: ${error.message}`); | ||
} | ||
|
||
return data; | ||
} |