Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto increment type should not have @required in generated class #68

Closed
robbyrahmana opened this issue Jul 9, 2019 · 1 comment
Closed

Comments

@robbyrahmana
Copy link

No description provided.

@simolus3
Copy link
Owner

simolus3 commented Jul 9, 2019

Hi, the generated data classes are meant to hold a full row, as it appears in the table, so all non-nullable fields will be @required, even if they have default values.
When you only want to insert or update some of the columns (e.g. use the default / auto-increment values for everything else), you can use the generated Companion classes (see the changelog at 1.5 for details). Here's an example where the id would be required but is omitted because of the default value:
https://github.com/simolus3/moor/blob/01db5e2afcaf206782307c4d307389c4b54d1428/moor_flutter/example/lib/bloc.dart#L63-L66
Introducing another class might seem unnecessarily complicated at first, but allows us to cleanly separate between "I want to set this column to null when inserting" and "I want to use the default value", which we couldn't do by implicitly setting the field to null.

I'm closing this for now, but please feel free to reply if you have any more questions.

@simolus3 simolus3 closed this as completed Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants