Skip to content

How to index a column using Drift? #2041

Answered by simolus3
TinhHuynh asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, at the moment this is not directly possible with a high-level Dart API. You can write the CREATE INDEX statement manually and add it to your database like this:

  @override
  List<DatabaseSchemaEntity> get allSchemaEntities => [
        ...super.allSchemaEntities,
        _myIndex,
      ];

  final Index _myIndex =
      Index('my_index', 'CREATE INDEX my_index ON foo (bar, baz)');

Added like this, the index will be created automatically when the database is created. You can also create it manually with migrator.create(_myIndex) in a schema migration.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TinhHuynh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants