Skip to content

How to add "implements" contracts to drift defined views? #2754

Closed Answered by Adam-Langley
Adam-Langley asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks @simolus3 for that suggestion.
I did actually find a way to achieve this:

Write a custom class which derives from the generated view - its sole purpose is to declare that the view implements certain contracts:

/// MyCustomDriftDslView is the view class generated by the .drift view sql
class MyCustomDriftDslViewWithContracts
    extends MyCustomDriftDslView
    implements WithSortOrderField, WithIsDefaultField {
  MyCustomDriftDslViewWithContracts(super.attachedDatabase);
}

Then manually attach the view to the database during construction:

class MyDatabase extends _$MyDatabase {
  MyDatabase(LazyDatabase lazy) : super(lazy);

  MyDatabase.from([QueryExecutor? executor]) : super(exe…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Adam-Langley
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