0
0
Supabasecloud~20 mins

CRUD operations with supabase-js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Supabase CRUD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What is the output of this Supabase insert operation?
Given the following code snippet using supabase-js, what will be the value of data after execution?
Supabase
const { data, error } = await supabase
  .from('profiles')
  .insert([{ id: '123', username: 'alice' }]);
AAn array with the inserted row object: [{ id: '123', username: 'alice' }]
Bnull
CAn empty array []
DA string message confirming insertion
Attempts:
2 left
💡 Hint
Think about what supabase-js returns after a successful insert.
Configuration
intermediate
2:00remaining
Which option correctly updates a user's email in supabase-js?
You want to update the email of the user with id 'abc123' in the 'users' table. Which code snippet correctly performs this update?
Aawait supabase.from('users').modify({ email: 'new@example.com' }).filter('id', 'abc123');
Bawait supabase.from('users').set({ email: 'new@example.com' }).where('id', 'abc123');
Cawait supabase.from('users').update({ email: 'new@example.com' }).eq('id', 'abc123');
Dawait supabase.update('users').set({ email: 'new@example.com' }).eq('id', 'abc123');
Attempts:
2 left
💡 Hint
Check the supabase-js method names for updating and filtering.
Architecture
advanced
2:00remaining
Which architecture best supports real-time updates with supabase-js?
You want your app to show live changes from the 'messages' table without refreshing. Which architecture choice best supports this with supabase-js?
AUse a separate REST API server to push updates to the client.
BPeriodically poll the 'messages' table every 5 seconds using supabase-js select queries.
CFetch all messages once on app load and store locally without updates.
DUse supabase-js subscriptions to listen to changes on 'messages' and update UI accordingly.
Attempts:
2 left
💡 Hint
Supabase supports real-time subscriptions natively.
security
advanced
2:00remaining
Which option correctly restricts data access in supabase-js using Row Level Security (RLS)?
You want to ensure users can only read their own profiles from the 'profiles' table. Which setup correctly enforces this using supabase-js and RLS?
AUse supabase-js to filter profiles by user id but keep RLS disabled.
BEnable RLS on 'profiles' and create a policy: 'USING (auth.uid() = id)'. Then query normally with supabase-js.
CEnable RLS but do not create any policies; supabase-js will automatically restrict access.
DDisable RLS and filter profiles by user id in supabase-js client code.
Attempts:
2 left
💡 Hint
RLS requires explicit policies to restrict access.
Best Practice
expert
2:00remaining
What is the best practice to handle errors in supabase-js CRUD operations?
You perform an insert operation with supabase-js. Which approach correctly handles possible errors?
Supabase
const { data, error } = await supabase.from('tasks').insert([{ title: 'New Task' }]);
ACheck if <code>error</code> is not null and handle it before using <code>data</code>.
BIgnore <code>error</code> and assume <code>data</code> is always valid.
CUse try-catch block around the insert call without checking <code>error</code>.
DOnly check if <code>data</code> is null to detect errors.
Attempts:
2 left
💡 Hint
Supabase-js returns errors separately from data.