DriftDatabase class

Use this class as an annotation to inform the generator that a database class should be generated using the specified DriftDatabase.tables.

To write a database class, first annotate an empty class with DriftDatabase and run the build runner using dart pub run build_runner build. Drift will have generated a class that has the same name as your database class, but with _$ as a prefix. You can now extend that class and provide a QueryExecutor to use drift:

import 'package:drift/drift.dart';
import 'package:drift_flutter/drift_flutter.dart';

@DriftDatabase(tables: [...])
class MyDatabase extends _$MyDatabase { // _$MyDatabase was generated
  MyDatabase(): super(driftDatabase(name: 'path.db'));
}

For more information on getting started with drift, which also describes options for using drift outside of Flutter apps, see the getting started section in the documentation.

Constructors

DriftDatabase({List<Type> tables = const [], List<Type> views = const [], List<Type> daos = const [], Map<String, String> queries = const {}, Set<String> include = const {}})
Use this class as an annotation to inform the generator that a database class should be generated using the specified DriftDatabase.tables.
const

Properties

daos List<Type>
Optionally, the list of daos to use. A dao can also make queries like a regular database class, making is suitable to extract parts of your database logic into smaller components.
final
hashCode int
The hash code for this object.
no setterinherited
include Set<String>
Defines the .drift files to include when building the table structure for this database. For details on how to integrate .drift files into your Dart code, see the documentation.
final
queries Map<String, String>
Optionally, a list of named sql queries. During a build, drift will look at the defined sql, figure out what they do, and write appropriate methods in your generated database.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tables List<Type>
The tables to include in the database
final
views List<Type>
The views to include in the database
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited