-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
We really need builders for these model instances #154
Comments
@dgaedcke Thank you for your endorsement of Prisma ORM for Dart, for the two schemes you belong to:
Without changing the existing generator, all Inputs classes support fromJson for construction, you can use it. PS: As far as I know @jackstefansky @nikosportolos is experienced with this.
Regarding adding code to the generator to support this situation, we usually add the option
|
Perhaps, we have another option, adding configuration to the generator. Tells the generator to generate mutable accumulated member properties or final member properties. And this is the solution with the least modification, because we only need to change the inputs generator and refuse to add the |
@dgaedcke I create a separate branch for you, implementing mutable class member properties. You depend on it via git, make sure it's what you need. If yes, we release it as a new effect in the next version. |
@dgaedcke I created a scheme in the https://github.com/odroe/prisma-dart/tree/154-mutable-class-member-properties branch, you can confirm whether it is what you need by relying on it through pub's git . You can see #155 PR for details. Looking forward to your feedback. |
Thanks so much for the speedy response!! I like your solution of generating the models with or without "final" as a first step. But that really should be a temporary solution because the codebase really should have immutable values. Here's a good compromises for first step: so by running: my model classes will be be immutable, but my data-collector (create & update) classes are mutable. What do you think of that approach?? It would be even better, if the Create and Update classes has a fallible method (tryBuildModel) to convert into a model ... without sending to the DB ... something like this:
|
@dgaedcke I should understand what you said, what you need is a scheme like But now there is an incompatibility problem, If our generator adds Can we make a choice and let developers choose |
Maybe we need to create tools like Because Dart does not support type calculations. Generic support is also poor. |
It seems the "client different for each developer" problem can be solved by convention -- each development team can select their preferred approach. Also, I'm confused by your comment that Generic support is poor in Dart ... I've not found that to be true but it seems you are familiar with some design-pattern that I've never had to face. I have a 3rd compromise solution. How about: This would create another model structure as follows:
These shadow classes would not add a lot of size (only one class per DB table) but would give all of the flexibility I'm requesting!! Thanks so much for your engagement and support with this issue :-) |
for example:
Regarding the discussion of this issue, I think we need to collect feedback and solutions from more developers. Because this change is so big, it is almost a breaking change to the generator. I will pinned this issue and send a tweet to make sure more developers see it. https://twitter.com/odroeinc/status/1636222741295816704?s=20 |
Sounds great!! Thank you -- |
Yes!! Thank you. |
BTW ... if we need Union-Types in Dart, is there some reason that combining code-generation, generics and Built-Value (or Freezed) won't let you express anything you can express in TypeScript?? |
@medz Might also worth looking at https://pub.dev/packages/data_class_plugin. |
@dgaedcke Whether the Prisma engine is the GraphQL protocol or the experimental JSON protocol, a short type always has multiple structures. For example, UserWhereInput.age, it may be an int type of So the current Prisma ORM for Dart only selects the longest input type among them, because there are no Union-Types.
Developers who have experienced the 2.6 version seem to be aware that |
I'm keeping an eye on it, but I haven't tested it yet and don't know if it can generate code via cli. |
I wish we had more feedback from other developers on how best to address this need. |
@dgaedcke I agree that we should start simple and then address complex needs. Can you create a PR for this and write a model_example.dart in the project root that demonstrates what you need? Creating a PR helps us start implementing it. Of course, it would be nice if you could modify the generator. But it doesn't matter, you can start with the model example. I will do related coding work on your PR later. |
You can join our discord server https://discord.com/invite/r27AjtUUbV and we can chat more details. issue I feel as an update to the main guide and implementation. Minutiae we can communicate in discord. |
Every time I try to access your server, it asks me to "Claim Account" and every time I do so, it tells me my email is already registered, and won't let me proceed.... not sure what to do. I've been traveling and also had PW probs with DIscord! |
@medz I apologize for the slow review and bad experience. But know that you haven't been discriminated against. I am working alone on many projects and receive tons of notifications every day. It is not uncommon for one PR/issue to get lost in the sea. Freezed is a bit in a weird place for me atm too. Because Dart 3.0, a lot of the use-case for Freezed will be invalidated. So while I understand your frustration and apologize for it, please do not think that I discriminated against you. |
@rrousselGit Thank you for your reply, and I apologize for the misunderstanding. Perhaps it was because I received a lot of discrimination in open source work before, which made me very sensitive to this and caused this misunderstanding. Again very sorry. Also as an indie developer, I can understand how busy you are when maintaining multiple projects. Because I also have to deal with a lot of project codes every day. However, in my actual test, it is true that both I and the users of this project have encountered Also, I didn't really remove Freezed from my project because it was nice enough that I could write less boilerplate code, e.g. |
No worries. It is true that I was slow to reply after-all. And there are indeed some issues with Freezed. I don't have the time to work on it though. It appears to be not that common (considering the size of the project, I would've expected this issue to come-up a lot more often). I'll try to review/merge your toString PR when I have a bit of time though. |
In the new version (v4), I abandoned any JSON serialization tool and in the meantime I developed a tool like zod 👉 https://pub.dev/packages/ovo After the first v4 version is released, I will Start developing this feature. As a follow-up, I will create a separate PR to complete it at that time, which contains:
|
I often use the Prisma generated code on the CLIENT SIDE (talking directly to the DB) for prototyping and client demo's, to help them flush out their specs and requirements. For server code, it makes total sense that all the Model classes are immutable and must be constructed all-at-once (with all fields) from a client API request.
But on the client side, data is collected in pieces, across many screens, and I hate having to manually clone all the Prisma data structures so I have data-models on which to store user-input from the UI!!
So I'm having serious headaches using existing models to accumulate data across multiple forms. Due to all attributes being "final", we can't construct any of these generated models until ALL FIELDS (data properties) are available, and for complex flows (eg large tables), that takes many screens.
This means I'm having to pass loosely typed JSON maps (user form-input) along from screen to screen, or else I need to manually clone your generated table-models with NON-FINAL fields, so I have strongly typed entities to pass forward in my screen flow.
Can you either:
For example, built-value generates builder classes automatically for immutable models:
https://youtu.be/hNbOSSgpneI
Other than that, I'm really loving this tooling ... it's very well done!!
The text was updated successfully, but these errors were encountered: