You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not necessarily, I mean the serialized version would still probably be a list, but an iterator can be much more than just a list. It could add value to be able to use an iterator on the class rather than a list and it shouldn't be too hard to implement.
Working method:
In separate PRs for each type, first, add it so that it can be sent and received from an endpoint. After that, we can consider adding support for it in the model definition. But this will be a case-by-case decision.
A few questions / comments about the remaining types to be implemented.
Iterable
What would be the expectations of when to read the iterator? Personally I would've started out with consuming the iterator once when creating the model class. That means it would only ever be consumed once (per model class), and internally (to the model class and database) it could just behave like a List<T>.
We could of course also retain the Iterable itself on the model class, but then we might get different values at different points (depending on how it/what is implemented), or succeed once and fail another time (e.g. when saving it to the database vs. sending the seemingly "same" model to the client afterwards).
num
Would you go for double precision in the database here, or some more specific type like decimal with a higher precision, such that we could best map all possible numeric Dart types?
How important would it be to retain the original "source" type when round-tripping under the hood? I wonder if a 3.0 (double) might not become a 3 (int). But maybe that would be fine, as people who opted into this more flexible type will just be OK treating it as 3 (num) all the time.
Record
This should be fine overall, I'll just have to dig into how we handle the case when the framework things "the type of this field has changed".
I think we would need to be a lot more flexible at that stage then, to e.g. allow additions of null positional and/or named parameters.
E.g. going from ({int id, String name}) to ``({int id, String name, String? phone})` should be allowed in my opinion.
Set
(Ordered) Sets seem like a good type for relations, but initially I left it out, as the creation case seems tricky given that we don't have object equality on the models. Once we have an ID from the database, we could ensure that an item is present no more than once. But this would probably become quite a big undertaking overall.
I don't think we should resolve the iterable to a list. If the developer wants that behavior it would be perfectly fine to use a list as a type instead and resolve any iterable before assigning. I believe the use-case here is specifically to have the flexibility an iterable brings, with the risk of having inconsistent behavior.
Num
Couldn't we store it as a string and encode it with type? That would allow us to always restore the type that was actually saved in the field. And since the developer has specified num instead of a specific type, I would expect them to be fine with the potential performance when serializing/deserializing.
I don't think we should resolve the iterable to a list.
@SandPod Suppose we have an Iterable<T> on the model, I agree that we could keep this around as long as the model is alive. But when creating the same model from the database or receiving it from the network, I think it'd have to backed by a List<T> as we don't know what other type the user would want to use.
In any case I would probably defer this until someone comes up with a practical example that would benefit from this, as personally I think we're well covered with Set & List (incl. the ability that one can switch between them (at least if they don't contain any duplicates)).
Couldn't we store it as a string and encode it with type?
That sounds feasible. We'd just have to look into whether we can retain any of the database filter operations. That is also still outstanding for BigInt (serialized as string) where you currently can not sort/filter numerically.
Noting down some decisions from a discussion between @tp and me.
We will support Iterable with specific types in the model. We believe the biggest usecase for this, as opposed to using a Set or List is that developers would like to assign generators to their models on the server or client side.
These generators should be resolved uniquely for each serialization; this allows the result of a generator to be easily passed through serialization.
When consistent result is desired, a Set or List should be used instead.
Activity
vlidholt commentedon Feb 5, 2024
Iterable is more or less covered by List, no?
Isakdl commentedon Feb 6, 2024
Not necessarily, I mean the serialized version would still probably be a list, but an iterator can be much more than just a list. It could add value to be able to use an iterator on the class rather than a list and it shouldn't be too hard to implement.
In any case the above types are the ones we do not support that the Google maintained package: https://pub.dev/packages/json_serializable supports.
SandPod commentedon Jan 15, 2025
Working method:
In separate PRs for each type, first, add it so that it can be sent and received from an endpoint. After that, we can consider adding support for it in the model definition. But this will be a case-by-case decision.
Isakdl commentedon Jan 15, 2025
@SandPod Database support also needs to be considered even if they just map to an existing database type.
Add support for `Uri` database storage
Add support for `Uri` database storage
tp commentedon Feb 3, 2025
A few questions / comments about the remaining types to be implemented.
IterableWhat would be the expectations of when to read the iterator? Personally I would've started out with consuming the iterator once when creating the model class. That means it would only ever be consumed once (per model class), and internally (to the model class and database) it could just behave like a
List<T>.We could of course also retain the
Iterableitself on the model class, but then we might get different values at different points (depending on how it/what is implemented), or succeed once and fail another time (e.g. when saving it to the database vs. sending the seemingly "same" model to the client afterwards).numWould you go for
double precisionin the database here, or some more specific type likedecimalwith a higher precision, such that we could best map all possible numeric Dart types?How important would it be to retain the original "source" type when round-tripping under the hood? I wonder if a
3.0 (double)might not become a3 (int). But maybe that would be fine, as people who opted into this more flexible type will just be OK treating it as3 (num)all the time.RecordThis should be fine overall, I'll just have to dig into how we handle the case when the framework things "the type of this field has changed".
I think we would need to be a lot more flexible at that stage then, to e.g. allow additions of
nullpositional and/or named parameters.E.g. going from
({int id, String name})to ``({int id, String name, String? phone})` should be allowed in my opinion.Set(Ordered)
Sets seem like a good type forrelations, but initially I left it out, as the creation case seems tricky given that we don't have object equality on the models. Once we have an ID from the database, we could ensure that an item is present no more than once. But this would probably become quite a big undertaking overall.Support `Set` field type on the protocol
SandPod commentedon Feb 11, 2025
A couple of responses to the questions above.
Iterable
I don't think we should resolve the iterable to a list. If the developer wants that behavior it would be perfectly fine to use a list as a type instead and resolve any iterable before assigning. I believe the use-case here is specifically to have the flexibility an iterable brings, with the risk of having inconsistent behavior.
Num
Couldn't we store it as a string and encode it with type? That would allow us to always restore the type that was actually saved in the field. And since the developer has specified
numinstead of a specific type, I would expect them to be fine with the potential performance when serializing/deserializing.tp commentedon Feb 17, 2025
@SandPod Suppose we have an
Iterable<T>on the model, I agree that we could keep this around as long as the model is alive. But when creating the same model from the database or receiving it from the network, I think it'd have to backed by aList<T>as we don't know what other type the user would want to use.In any case I would probably defer this until someone comes up with a practical example that would benefit from this, as personally I think we're well covered with Set & List (incl. the ability that one can switch between them (at least if they don't contain any duplicates)).
That sounds feasible. We'd just have to look into whether we can retain any of the database filter operations. That is also still outstanding for
BigInt(serialized asstring) where you currently can not sort/filter numerically.SandPod commentedon Feb 18, 2025
Noting down some decisions from a discussion between @tp and me.