Is there a plan for creating indices like:
@override
Set<Column> get index => {group, user};
There's nothing preventing us from declaring indices in Dart. However, we'd probably use a designated class for that, something like
class MyIndex extends Index<Users> { // Where Users is a Dart table
@override
Set<Column> get columns => {group, user};
}
That would allow users to override the name of the index or define a custom where clause.
@simolus3 could you please explain creating index in code in more detail.
Because I could not find such Index class as in your example. I could find only this.
@ycherniavskyi That was just an api suggestion, it's not implemented yet.
If you want to define an index without moor files, you could use something like this today:
class YourDatabase extends _$YourDatabase {
// ...
@override
Iterable<SchemaEntity> get allSchemaEntities {
return [
...super.allSchemaEntities,
Index('my_index', 'CREATE INDEX my_index ON ...'),
];
}
}
Aha, I see.
@simolus3 and thank you for your suggestion, I like it more than which I come with 馃槉:
class YourDatabase extends _$YourDatabase {
// ...
@override
MigrationStrategy get migration => MigrationStrategy(
onCreate: (m) async {
await m.createAll();
await m.createIndex(Index('my_index', 'CREATE INDEX my_index ON ...'));
},
// ...
);
}
Most helpful comment
There's nothing preventing us from declaring indices in Dart. However, we'd probably use a designated class for that, something like
That would allow users to override the name of the index or define a custom where clause.