Overview
The query functions provide a type-safe interface for database operations. All functions are located insrc/lib/supabase/queries.ts and use the Supabase client for data access.
Anime Entries
Functions for managing user’s anime list entries.getAnimeEntries()
Retrieves all anime entries for a specific user, ordered by creation date (newest first).The user’s UUID from Supabase Auth
Promise<AnimeEntry[]>
Throws: Supabase error if query fails
getAnimeEntry()
Retrieves a specific anime entry for a user.The user’s UUID
The anime ID from external API (e.g., MyAnimeList)
Promise<AnimeEntry | null>
Throws: Supabase error if query fails (except PGRST116 - not found)
upsertAnimeEntry()
Creates or updates an anime entry. Uses(user_id, anime_id) as conflict resolution key.
Anime entry data without auto-generated fields
user_id- User UUIDanime_id- Anime ID from external APItitle- Anime titlestatus- One of: ‘watching’, ‘completed’, ‘on-hold’, ‘dropped’, ‘plan-to-watch’episodes_watched- Number of episodes watched (default: 0)
Promise<AnimeEntry>
Throws: Supabase error if operation fails
deleteAnimeEntry()
Deletes an anime entry for a specific user.The user’s UUID
The anime ID to delete
Promise<void>
Throws: Supabase error if deletion fails
Reviews
Functions for managing anime reviews.getReviews()
Retrieves reviews with flexible filtering options, ordered by update date (newest first).Filter by specific anime ID
Filter by specific user ID
Filter by publication status
Maximum number of reviews to return
Promise<Review[]>
Throws: Supabase error if query fails
The function includes console logging for performance monitoring.
getReview()
Retrieves a single review by ID.The review UUID
Promise<Review>
Throws: Supabase error if query fails or review not found
getUserReview()
Retrieves a user’s review for a specific anime.The user’s UUID
The anime ID
Promise<Review | null>
Throws: Supabase error if query fails (except PGRST116 - not found)
upsertReview()
Creates or updates a review with complex logic for handling drafts and published reviews.Review data (id optional for creation)
user_id- User UUIDanime_id- Anime IDrating- Overall rating (1-10)title- Review titlebody- Review contentspoilers- Whether contains spoilerswatch_status- One of: ‘completed’, ‘watching’, ‘dropped’, ‘plan-to-watch’status- ‘draft’ or ‘published’tags- Array of tags
Promise<Review>
Throws: Supabase error if operation fails
deleteReview()
Permanently deletes a review and all associated votes/comments (CASCADE).The review UUID to delete
Promise<void>
Throws: Supabase error if deletion fails
Review Votes
Functions for helpful/not helpful voting on reviews.voteReview()
Casts or updates a vote on a review. Uses upsert to allow vote changes.The review UUID
The voting user’s UUID
True for helpful, false for not helpful
Promise<ReviewVote>
Throws: Supabase error if operation fails
The review’s
helpful_votes count is automatically updated by a database trigger.getUserReviewVote()
Retrieves a user’s vote on a specific review.The review UUID
The user’s UUID
Promise<ReviewVote | null>
Throws: Supabase error if query fails (except PGRST116 - not found)
Comments
Functions for managing review comments with threading support.getComments()
Retrieves all non-deleted comments for a review, ordered chronologically.The review UUID
Promise<Comment[]>
Throws: Supabase error if query fails
createComment()
Creates a new comment or reply on a review.Comment data without auto-generated fields
review_id- Review UUIDuser_id- Commenter’s UUIDcontent- Comment textparent_id- Parent comment UUID (null for top-level comments)
Promise<Comment>
Throws: Supabase error if creation fails
updateComment()
Updates the content of an existing comment.The comment UUID
New comment text
Promise<Comment>
Throws: Supabase error if update fails
The
updated_at timestamp is automatically set by a database trigger.deleteComment()
Soft deletes a comment by settingdeleted_at timestamp.
The comment UUID to delete
Promise<void>
Throws: Supabase error if deletion fails
Custom Lists
Functions for managing user-created anime lists.getCustomLists()
Retrieves all custom lists for a user with entry counts.The user’s UUID
Promise<(CustomList & { custom_list_entries: { anime_id: number }[] })[]>
Throws: Supabase error if query fails
The query joins with
custom_list_entries to include anime IDs in each list.createCustomList()
Creates a new custom list.List data without auto-generated fields
user_id- User UUIDname- List nameis_public- Public visibility (default: false)
Promise<CustomList>
Throws: Supabase error if creation fails
updateCustomList()
Updates properties of a custom list.The list UUID
Fields to update
Promise<CustomList>
Throws: Supabase error if update fails
deleteCustomList()
Deletes a custom list and all its entries (CASCADE).The list UUID to delete
Promise<void>
Throws: Supabase error if deletion fails
addAnimeToList()
Adds an anime to a custom list.The list UUID
The anime ID to add
Promise<CustomListEntry>
Throws: Supabase error if operation fails (e.g., duplicate entry)
removeAnimeFromList()
Removes an anime from a custom list.The list UUID
The anime ID to remove
Promise<void>
Throws: Supabase error if deletion fails
Error Handling
All query functions throw Supabase errors on failure. Wrap calls in try-catch blocks:Common Error Codes
PGRST116- Row not found (handled bygetAnimeEntry,getUserReview, etc.)23505- Unique constraint violation23503- Foreign key constraint violation42501- Insufficient privileges (RLS policy denied access)