docs(examples): add database CRUD with PostgREST example#1616
Conversation
Adds a runnable task-manager example under examples/database_crud that demonstrates select/insert/update/delete, filters, ordering and a join with supabase.from(...). Database access lives in a TasksRepository so it can later be driven from an end-to-end integration test. Adds the shared schema and seed data to examples/supabase (projects 1:N tasks) with RLS and grants so the example runs with the publishable key. Registers the example in the workspace and the examples README.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a Flutter Sequence Diagram(s)sequenceDiagram
participant User
participant TasksPage
participant TasksRepository
participant Supabase
User->>TasksPage: Apply filters or mutate task
TasksPage->>TasksRepository: Fetch or update task
TasksRepository->>Supabase: Execute PostgREST query
Supabase-->>TasksRepository: Return task rows
TasksRepository-->>TasksPage: Return mapped models
TasksPage-->>User: Render updated task list
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/database_crud/lib/main.dart`:
- Around line 74-90: Update _load to track a request generation for each
invocation, and before applying fetched projects/tasks verify that the
invocation is still current and the widget is mounted. Prevent stale or disposed
requests from calling setState, while preserving the existing
loading/error/finalization behavior.
In `@examples/database_crud/lib/models.dart`:
- Around line 2-50: Resolve the SDK capability-matrix failures by registering or
appropriately excluding the public APIs in
examples/database_crud/lib/models.dart lines 2-50, including Project and Task;
examples/database_crud/lib/tasks_repository.dart lines 8-98, including
TasksRepository; and examples/database_crud/lib/main.dart lines 28-48, including
CrudExampleApp and TasksPage. Ensure all newly exposed symbols are accounted for
without changing their behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cc91b617-a08a-462b-ad6d-27482e0670d1
📒 Files selected for processing (10)
examples/README.mdexamples/database_crud/README.mdexamples/database_crud/analysis_options.yamlexamples/database_crud/lib/main.dartexamples/database_crud/lib/models.dartexamples/database_crud/lib/tasks_repository.dartexamples/database_crud/pubspec.yamlexamples/supabase/migrations/20240601000000_crud_example.sqlexamples/supabase/seed.sqlpubspec.yaml
- Load projects once instead of on every task reload. - Debounce the search field so typing does not fire a query per keystroke and race the responses out of order. - Keep the task list on screen during reloads instead of flashing a spinner over it when toggling a task or changing a filter. - Add web scaffolding so the launcher can run it on Chrome.
- Add examples/ to .sdk-parse-ignore so the example apps' public classes are not treated as SDK capability-matrix symbols. - Guard the task reload with a request-generation id so a slower earlier request cannot overwrite the results of a later one, and skip state updates once the request is stale or the widget is disposed.
…ctices - Guard writes behind a single _mutate helper that ignores overlapping calls, so a double tap can't fire duplicate requests; disable the FAB and row controls while a write is in flight. - Model priority as a Priority enum instead of a raw int and a magic label map. - Add tooltips to the row actions and make the 'Only incomplete' filter label tappable with a CheckboxListTile. - Note the setState + refetch simplification in the README.
What
Adds a runnable Database CRUD with PostgREST example under
examples/database_crud, plus the shared schema and seed data it runs against. Closes SDK-1065.The example is a small task manager that covers everything
supabase.from(...)offers for CRUD:select('*, projects(name)'))eq(project, completion),ilike(title search)order('priority', ascending: false).order('created_at')insert().select().single())update().eq())delete().eq())All database access lives in
lib/tasks_repository.dart, kept separate from the UI so the queries are easy to read and can later be driven from a full end-to-end integration test.Shared config
examples/supabase/migrations/20240601000000_crud_example.sql—projects1:Ntaskswith a foreign key and index, RLS enabled with permissive demo policies, and grants so the publishable (anon) key can read projects and manage tasks without signing in.examples/supabase/seed.sql— sample projects and tasks.Wiring
examples/database_crudin the root workspacepubspec.yamland theexamples/README.mdtable. The launcher auto-discovers it.Verification
flutter analyze examples→ no issues;dart formatclean.supabase db resetagainstexamples/applies the migration and seed cleanly.ilikeselect, insert returning the joined row, update, filtered select, and delete (204) with confirmation.