-
Notifications
You must be signed in to change notification settings - Fork 366
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
Add Code Generation for json_serializable #3080
Comments
I agree with the idea that it should be easier to combine different builders with drift - putting a cheap form of json serialization into drift by default was my lazy workaround because they're not that easy to combine, but I consider that to be a big design flaw in drift. However, I think the end realization is that users need to have full control over all builders, and the problem is generating APIs instead of implementations. In drift, you define the table structure in your sources, and then drift generates the row classes and companions (or models, which are really part of a public API then). I think this is fundamentally flawed somewhat, and making drift generate The way things should work is that users define the public models / APIs they want to use, an drift wires up all the boring things in the implementation. This is what we have with @JsonSerializable()
@DriftTable()
class User {
@PrimaryKey(autoIncrement: true)
final int id;
final String name;
final DateTime birthday;
@TypeConverter.enumText()
final StatusType status;
} Obviously we can't turn the whole library inside out right now, but I still think something like that can form a better model because users control the parts that they see. I'm not sure if it's worth it to explore this approach with the current |
Thank you @simolus3 for your prompt response. A api similar to Android's Room library would be great. It looks clean and organized. The Drift documentation (code below) explains the process of creating a table and implementing JsonSerializable using two different class names, "user" and "users." Is there a way to use the same class name for both JsonSerializable data classes and the drift tables?
thank you |
Great package! I really love what you're creating here!
Currently, to use json_serializable and/or freezed, developers have to write duplicate code: one for the Users class and another for the User class. For example:
It would be fantastic if this code could be generated using build_runner.
I am willing to contribute to implementing this feature and creating a PR if someone can provide guidance or pointers on how to get started.
Thank you!
The text was updated successfully, but these errors were encountered: