Process Flow - Inserting and querying data
Start
Connect to DB
Insert Data
Query Data
Receive Results
End
The flow starts by connecting to the database, then inserting data, followed by querying the data, and finally receiving the results.
const { data, error } = await supabase
.from('users')
.insert([{ name: 'Alice', age: 30 }])
.select();| Step | Action | Input Data | Database State | Output | Notes |
|---|---|---|---|---|---|
| 1 | Connect to DB | None | DB ready | Connection established | Ready to perform operations |
| 2 | Insert Data | { name: 'Alice', age: 30 } | Empty users table | Insert success | Data added to users table |
| 3 | Query Data | Select all from users | Users table has Alice | [{ name: 'Alice', age: 30 }] | Returns inserted data |
| 4 | End | None | Users table unchanged | Operation complete | Process finished |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| data | undefined | [{ name: 'Alice', age: 30 }] | [{ name: 'Alice', age: 30 }] | [{ name: 'Alice', age: 30 }] |
| error | undefined | null | null | null |
Supabase insert and query:
- Use .from('table') to select table
- Use .insert([{...}]) to add data
- Use .select() after insert to get inserted rows
- Await the call to get data and error
- Check error to handle failures