Insert, update, upsert and delete rows with JSON bodies.
| Operation | Request |
|---|---|
| Insert | POST /rest/v1/todos with a JSON body |
| Update | PATCH /rest/v1/todos?id=eq.1 |
| Delete | DELETE /rest/v1/todos?id=eq.1 |
#From JavaScript
JavaScript
await stitchdb.from('todos').insert({ task: 'New task' })
await stitchdb.from('todos').insert([{ task: 'One' }, { task: 'Two' }]) // many rows at once
await stitchdb.from('todos').update({ is_complete: true }).eq('id', 1)
await stitchdb.from('todos').delete().eq('id', 1)
// Insert or update by primary key (or another unique column)
await stitchdb.from('profiles').upsert({ id: uid, username: 'ada' }, { onConflict: 'id' })
// Get the changed rows back
const { data } = await stitchdb.from('todos').insert({ task: 'New task' }).select()#With cURL
Terminal
curl -X PATCH 'https://<project-ref>.p.stitchdb.com/rest/v1/todos?id=eq.1' \
-H "apikey: <anon-key>" \
-H "Authorization: Bearer <user-access-token>" \
-H "Content-Type: application/json" \
-H "Prefer: return=representation" \
-d '{"is_complete":true}'
# Upsert
curl -X POST 'https://<project-ref>.p.stitchdb.com/rest/v1/profiles?on_conflict=id' \
-H "apikey: <anon-key>" -H "Authorization: Bearer <user-access-token>" \
-H "Content-Type: application/json" \
-H "Prefer: resolution=merge-duplicates" \
-d '{"id":"<user-id>","username":"ada"}'#Get changed rows back
Add the header Prefer: return=representation (or .select() in the SDK) to receive the changed rows in the response. Row Level Security applies to the returned rows too.