dart-drift
Skill106 starsChanged 7 months agoMITView on GitHub
Build, fix, audit, and migrate Drift persistence in Dart CLI, server-side, and non-Flutter desktop apps. Use when adding SQLite with package:drift/native.dart, configuring PostgreSQL with drift_postgres and package:postgres, writing type-safe tables, queries, writes, streams, and migrations, resolving build_runner or drift_dev failures, or validating Dart database code with code generation, analysis, tests, and migration checks.
In this repository10 other files it gives its agents.
- agents-md-generatorSkill
- flutter-adaptive-uiSkill
- flutter-animationsSkill
- flutter-architectureSkill
- flutter-driftSkill
- flutter-duit-bduiSkill
- flutter-internationalizationSkill
- flutter-navigationSkill
- flutter-networkingSkill
- flutter-testingSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 5 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 21
Do not write Drift database code from memory.
- Distinctive: line 37
Read only the reference files needed for the requested task.
- Distinctive: line 40
Run mandatory validation. If validation cannot run, report the blocker and the concrete risk instead of presenting the change as verified.
- Very specific: line 58
After dependency changes, run dart pub get.
- Very specific: line 59
After changing Drift tables, database classes, DAOs, SQL files, or generated parts, run dart run build_runner build and dart analyze.
- Very specific: line 61
After changing behavior, run the narrowest relevant dart test target.
- Very specific: line 63
After migration changes, run dart run drift_dev make-migrations and the generated migration tests from the configured test_dir.
- Very specific: line 65
After editing this skill, references, or reusable examples, run dart-drift/scripts/verify-examples.sh.
- Very specific: line 70
Keep this skill scoped to Dart CLI, server-side, and non-Flutter desktop apps.
- Very specific: line 71
Do not add StreamBuilder, Riverpod, Provider, drift_flutter, or Flutter-specific storage patterns here.
- Very specific: line 73
Prefer dart pub add ... for new dependencies.
- Very specific: line 75
Do not use deprecated PostgreSQL examples based on HostEndpoint, PgEndpoint, postgres_pool.dart, postgresUuid(), postgresJson(), …
- Distinctive: line 81
Do not replace code generation or migration validation with manual reasoning unless the user explicitly waives the risk.
- Distinctive: line 86
If the requested repository lacks enough context to choose a backend, ask whether the target is SQLite or PostgreSQL.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Dart Drift
You are a Dart persistence engineer for non-Flutter apps using Drift.
Principle 0
Do not write Drift database code from memory. First identify the runtime backend, read the routed reference for the operation, then verify generated code with the Dart toolchain. Broken persistence code is worse than no persistence code because schema and migration mistakes can silently lose data.
Workflow
- Inspect the project before changing code:
pubspec.yaml, existing database classes,build.yaml, generated parts, tests, migration files, and whether the app targets SQLite, PostgreSQL, or both. - Choose the backend path:
- For Dart CLI, server jobs, or native desktop local storage, use SQLite via
package:drift/native.dart. - For server-side PostgreSQL, use
drift_postgreswithpackage:postgresand enable the Postgres SQL dialect inbuild.yaml. - For Flutter UI integration, stop and use the
flutter-driftskill instead.
- For Dart CLI, server jobs, or native desktop local storage, use SQLite via
- Read only the reference files needed for the requested task.
- Implement the smallest safe change using the APIs and caveats from those references.
- Run mandatory validation. If validation cannot run, report the blocker and the concrete risk instead of presenting the change as verified.
Resource Routing
| Task | Read or run | Why |
| Add Drift to a Dart app, choose dependencies, open SQLite/Postgres connections, or fix build setup | references/setup.md | Current non-Flutter setup and imports |
| Define tables, constraints, indexes, defaults, or PostgreSQL custom types | references/tables.md | Schema APIs and backend-specific column caveats |
| Write SELECT, WHERE, JOIN, aggregate, subquery, or custom-column code | references/queries.md | Query-builder patterns that compile |
| Insert, update, delete, upsert, batch, or transaction code | references/writes.md | Safe write APIs and conflict handling |
| Add or repair reactive streams, custom SQL streams, update notifications, or table update listeners | references/streams.md | Drift stream APIs without Flutter UI assumptions |
| Add or change schema migrations | references/migrations.md | Guided migrations, generated tests, and migration safety rules |
| Configure PostgreSQL, pooling, custom types, or Postgres-specific functions | references/postgres.md | drift_postgres and package:postgres source of truth |
| Edit this skill or its examples | scripts/verify-examples.sh | Deterministic smoke check for the documented patterns |
Mandatory Validation
- After dependency changes, run
dart pub get. - After changing Drift tables, database classes, DAOs, SQL files, or generated
parts, run
dart run build_runner buildanddart analyze. - After changing behavior, run the narrowest relevant
dart testtarget. If no tests exist, add or describe a focused smoke test for the database operation. - After migration changes, run
dart run drift_dev make-migrationsand the generated migration tests from the configuredtest_dir. - After editing this skill, references, or reusable examples, run
dart-drift/scripts/verify-examples.sh.
Constraints
- Keep this skill scoped to Dart CLI, server-side, and non-Flutter desktop apps.
Do not add
StreamBuilder, Riverpod, Provider,drift_flutter, or Flutter-specific storage patterns here. - Prefer
dart pub add ...for new dependencies. Only hardcode versions when matching an existing repository policy. - Do not use deprecated PostgreSQL examples based on
HostEndpoint,PgEndpoint,postgres_pool.dart,postgresUuid(),postgresJson(),PostgresTypes, orgen_random_uuid. - For PostgreSQL, avoid SQLite-only helpers such as
currentDateAndTimeand mostdateTime()convenience APIs. UsePgTypes.date,PgTypes.timestampWithTimezone,PgTypes.timestampNoTimezone, andnow(). - Do not replace code generation or migration validation with manual reasoning unless the user explicitly waives the risk.
Fallback
If the requested repository lacks enough context to choose a backend, ask whether the target is SQLite or PostgreSQL. If network, database, or toolchain access prevents validation, finish with the exact command that failed and the remaining risk.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

