Skip to main content
skill CX Codex

dart-drift — Claude Code skill: Drift persistence in Dart

A skill for Drift persistence in Dart CLI, server-side and non-Flutter desktop apps: tables, queries, migrations, PostgreSQL.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add MADTeacher/mad-agents-skills --skill dart-drift -a claude-code
Open on GitHub

What dart-drift does

The skill casts the agent as a Dart persistence engineer for non-Flutter apps on Drift. Before writing any database code it makes the agent pick a backend: SQLite through package:drift/native.dart for CLI tools, server jobs and local desktop storage, or PostgreSQL through drift_postgres and package:postgres with the Postgres dialect enabled in build.yaml. If the task turns out to need Flutter UI integration, the skill stops and hands off to a separate flutter-drift skill.

Inside there is task routing. Separate reference files cover setup, tables, queries, writes, streams, migrations and PostgreSQL, and the agent reads only the ones the current operation needs. Validation is mandatory: dart pub get after dependency changes, dart run build_runner build and dart analyze after touching tables or DAOs, dart run drift_dev make-migrations plus the generated migration tests after a schema change.

The constraints are strict. Deprecated PostgreSQL examples built on HostEndpoint, PgEndpoint, postgres_pool.dart, postgresUuid(), postgresJson() and gen_random_uuid are off the table. On Postgres, SQLite-only helpers such as currentDateAndTime and most dateTime() conveniences are banned in favour of PgTypes.date, PgTypes.timestampWithTimezone, PgTypes.timestampNoTimezone and now(). If the repository does not make the target backend clear, the agent asks instead of guessing.

What it helps with

  • add SQLite to a Dart CLI with package:drift/native.dart
  • wire up PostgreSQL with drift_postgres and package:postgres
  • write type-safe Drift tables and queries
  • fix a failing build_runner or drift_dev run
  • run a schema migration and its generated tests

Example prompts for the agent

  • add Drift with SQLite to my Dart CLI, start with the dependencies
  • define an orders table with a date index and write a query for one month
  • the schema changed — make a migration and run the migration tests

How to install dart-drift

1Skills CLI (Vercel)

npx skills add MADTeacher/mad-agents-skills --skill dart-drift -a claude-code

2Manually: put the files in place

~/.claude/skills/dart-drift/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dart-drift/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about dart-drift

How do I install dart-drift in Claude?

Run npx skills add MADTeacher/mad-agents-skills --skill dart-drift -a claude-code. The skill file lands at ~/.claude/skills/dart-drift/SKILL.md.

What does dart-drift do?

It helps the agent write and repair Drift code in Dart CLI, server-side and non-Flutter desktop apps: tables, queries, writes, streams and migrations. SQLite and PostgreSQL setup are covered too.

How is dart-drift different from flutter-drift?

dart-drift stays on non-Flutter code and never touches StreamBuilder, Riverpod, Provider or drift_flutter. For Flutter UI integration it stops and passes the task to the flutter-drift skill.

Source text

SKILL.md · MIT
---
name: dart-drift
description: >-
  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.
metadata:
  author: Stanislav [MADTeacher] Chernyshev
  version: "2.0"
---

# 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

1. 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.
2. 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_postgres` with `package:postgres`
     and enable the Postgres SQL dialect in `build.yaml`.
   - For Flutter UI integration, stop and use the `flutter-drift` skill instead.
3. Read only the reference files needed for the requested task.
4. Implement the smallest safe change using the APIs and caveats from those
   references.
5. 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 build` and `dart analyze`.
- After changing behavior, run the narrowest relevant `dart test` target. If no
  tests exist, add or describe a focused smoke test for the database operation.
- After migration changes, run `dart run drift_dev make-migrations` and the
  generated migration tests from the configured `test_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`, or `gen_random_uuid`.
- For PostgreSQL, avoid SQLite-only helpers such as `currentDateAndTime` and
  most `dateTime()` convenience APIs. Use `PgTypes.date`,
  `PgTypes.timestampWithTimezone`, `PgTypes.timestampNoTimezone`, and `now()`.
- 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.

© Stanislav [MADTeacher] Chernyshev · MIT · MADTeacher/mad-agents-skills

Similar skills

All skills for Data and databases →

From the same set10

flutter-adaptive-ui This skill guides agents through building adaptive Flutter interfaces for mobile and desktop screens. It bases layout changes on width constraints rather than OS checks. CX Codex +1 2,000installs flutter-architecture A skill that designs and reviews Flutter app architecture: layers, MVVM, feature-first layout, DI, and patterns like Result and Command. CX Codex +1 1,700installs flutter-testing A skill for writing, fixing and debugging Flutter tests: unit, widget and integration layers, mocks, golden checks. CX Codex +1 1,500installs flutter-networking A skill for Flutter network code: HTTP/REST, WebSocket, auth and token refresh, timeouts, retries, JSON parsing, caching. Useful when adding requests or chasing network errors. CX Codex +1 722installs flutter-drift Walks the agent through Drift persistence in Flutter: tables, queries, reactive streams, schema migrations and tests. Useful whether the app already has a local database or you are adding one. CX Codex +1 671installs flutter-navigation A skill that makes your coding agent handle Flutter navigation: Navigator, go_router, deep links, redirects and browser history. CX Codex +1 589installs flutter-internationalization Automates Flutter internationalization using gen-l10n and ARB files. Solves UI string extraction, RTL layout adjustments, and generated import errors. CX Codex +1 536installs agents-md-generator Writes and trims AGENTS.md at the repo root and in nested modules. Useful when agent instructions have grown bloated or contradict each other. CX Codex +1 377installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor