Skip to content

docs(examples): add database CRUD with PostgREST example#1616

Open
spydon wants to merge 4 commits into
mainfrom
lukasklingsbo/sdk-1065-example-database-crud-with-postgrest
Open

docs(examples): add database CRUD with PostgREST example#1616
spydon wants to merge 4 commits into
mainfrom
lukasklingsbo/sdk-1065-example-database-crud-with-postgrest

Conversation

@spydon

@spydon spydon commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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 tasks joined to their project (select('*, projects(name)'))
  • Filters: eq (project, completion), ilike (title search)
  • Ordering: order('priority', ascending: false).order('created_at')
  • Insert returning the created joined row (insert().select().single())
  • Update title and completion state (update().eq())
  • Delete (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.sqlprojects 1:N tasks with 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

  • Registered examples/database_crud in the root workspace pubspec.yaml and the examples/README.md table. The launcher auto-discovers it.

Verification

  • flutter analyze examples → no issues; dart format clean.
  • supabase db reset against examples/ applies the migration and seed cleanly.
  • Exercised the full flow over PostgREST with the publishable key: joined + ordered + ilike select, insert returning the joined row, update, filtered select, and delete (204) with confirmation.

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.
@spydon
spydon requested a review from a team as a code owner July 17, 2026 11:44
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fb86d128-df6f-4a85-9900-4433b24645f1

📥 Commits

Reviewing files that changed from the base of the PR and between 2588486 and 3750fb3.

📒 Files selected for processing (4)
  • examples/database_crud/README.md
  • examples/database_crud/lib/main.dart
  • examples/database_crud/lib/models.dart
  • examples/database_crud/lib/tasks_repository.dart
🚧 Files skipped from review as they are similar to previous changes (3)
  • examples/database_crud/README.md
  • examples/database_crud/lib/tasks_repository.dart
  • examples/database_crud/lib/main.dart

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a new Flutter database_crud example demonstrating CRUD via PostgREST.
    • Includes task management with project selection, debounced search, and an “only incomplete” filter.
    • Supports creating, renaming, toggling completion, and deleting tasks.
  • Documentation

    • Expanded the examples README with the new database_crud row.
    • Added detailed database_crud example documentation and run instructions.
    • Added a schema migration and seed data for the demo.
  • Chores

    • Added the database_crud example scaffolding (pubspec, web entrypoint, gitignore, and shared analysis settings).
    • Updated workspace and example exposure scanning configuration.

Walkthrough

Adds a Flutter database_crud task manager using Supabase/PostgREST for joined queries, filtering, insertion, updates, completion toggling, renaming, and deletion. It adds the related database schema, RLS policies, grants, seed data, Dart models, repository, Flutter UI, package and workspace configuration, web entrypoint, lint/tooling files, API-scan exclusion, and documentation.

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
Loading

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d46c514 and fec2f53.

📒 Files selected for processing (10)
  • examples/README.md
  • examples/database_crud/README.md
  • examples/database_crud/analysis_options.yaml
  • examples/database_crud/lib/main.dart
  • examples/database_crud/lib/models.dart
  • examples/database_crud/lib/tasks_repository.dart
  • examples/database_crud/pubspec.yaml
  • examples/supabase/migrations/20240601000000_crud_example.sql
  • examples/supabase/seed.sql
  • pubspec.yaml

Comment thread examples/database_crud/lib/main.dart Outdated
Comment thread examples/database_crud/lib/models.dart
spydon added 3 commits July 17, 2026 13:49
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants