drift_dev
2.35.3, released 12 days ago by simonbinder.eu
Generates Dart database code from Drift table definitions as a dev‑dependency.
What it does
Drift_dev provides the build‑runner generator that reads your Drift table classes and emits type‑safe Dart code for queries, data classes, and schema verification. It also offers utilities for schema validation and migration support.
AI-written summary of version 2.35.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are using the drift package to work with SQLite and want compile‑time generated query helpers.
- You need automatic handling of SQL naming conflicts and schema verification during development.
Skip it when
- You only need runtime database access without code generation.
- You are not using drift or prefer a pure‑SQL approach.
Strengths
- Seamless integration with build_runner and the drift ecosystem
- Supports latest analyzer, cli_util, and build versions
- Handles reserved Dart keywords and SQL column name conflicts automatically
Weaknesses
- Requires a build step, adding compile time to the workflow
- Only a dev‑dependency; no runtime functionality on its own
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 25
Add drift_dev to dev_dependencies, ensure build_runner is present, then run `flutter pub run build_runner build` or watch mode.
```dart
import 'package:drift/drift.dart';
import 'package:drift_dev/moor_generator.dart'; // generated part
part 'app_database.g.dart';
@DriftDatabase(tables: [Users])
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(_openConnection());
@override
int get schemaVersion => 1;
}
// Run `flutter pub run build_runner build` to generate app_database.g.dart
```Alternatives
Packages that do the same job and could replace drift_dev.
- widgetbook_annotation
Annotations for widgetbook_generator to build Flutter widgets in isolation.
80Compare - built_value_generator
Generates immutable value types, enum classes, and JSON serializers for Dart.
82Compare - pigeon
Type-safe code generator for communication between Flutter and host platforms.
90Compare - json_serializable
Automatically generate code for converting Dart classes to and from JSON.
94Compare
Works with
Packages commonly used together with drift_dev: ones it builds on, ones built on it, and its own family.
- analyzerdrift_dev depends on itPerforms static analysis of Dart code for tool integration and embedding.
- yamldrift_dev depends on itA Dart library for parsing YAML documents into Dart data structures.
- pub_semverdrift_dev depends on itVersions and version constraints implementing pub's versioning policy.
- package_configdrift_dev depends on itRead and write Dart package configuration files.
- iodrift_dev depends on itUtilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.
- dart_styledrift_dev depends on itProvides an API and CLI to format Dart source code automatically.
- source_spandrift_dev depends on itStandard representation for source code locations, spans, and human-friendly error messages.
- json_annotationdrift_dev depends on itProvides annotations for json_serializable to generate JSON (de)serialization code.