Closed 3rpse-ai closed 1 year ago
Glad you like it.
The code should be able to support non-nullable types. I believe it could be a bug and will look into it. Anyway, for ORM nullable type generally works better at the moment.
Currently @serializable is required. ORM generated code depends on it.
Will add the Optional package. This was added as part of upgrading Angel3 ORM to support null safety. It was used primary to return either 0 or 1 record. Returning Optional
object that wrap the result avoid the use of null
to represent no record found.
Thanks for the quick reply! Just out of curiosity: What is the benefit of using Optional
over just working with null in this context?
Cleaner code. It allows parseRow() to return non-nullable type instead nullable type.
I'm just trying Angel & the ORM out. I ran the builder on the book
model from the documentation here https://angel3-docs.dukefirehawk.com/guides/serialization
BookType get type;
I too get an error (on the fromMap
method)
type: map['type'] is BookType
? (map['type'] as BookType) ?? null
: (map['type'] is int
? BookType.values[map['type'] as int]
: null));
the type
property is not nullable but the generated code is treating it like it should be. It seems the bug is in the generator code somewhere.
These ORM null safety bugs are being addressed on bug-fix/orm-generator
branch. 3 new models have been added to angel_orm_test
package to cater to these use cases; asset.dart, boat.dart and bike.dart. DateTime type is also undergoing changes to support timezone properly. Support for precision and scale in numeric field is also being worked on.
For this use case, there are two ways of fixing it. First option is to return a default BookType
instance and second option is to use bang operator '!' since map can potentially return null. My preference is 2nd option as throwing exception on null assignment to non-nullable field seems more logical. This is similar issue with non nullable temporal field assignment. However, for temporal field, epoch time, 1970-01-01 00:00:00, can be used whenever null is encountered.
Resolved in angel3_orm_generator
6.2.0
Hi - I tried to make use of your orm package and after investigating a bit I have to say I really like the syntax!
However I face an issue (yet I am not sure if it is a bug or I am missing some info).
I followed your car example but the generated code does not seem to be handling the non-nullable types.
The problem is that the
parseRow
method in theCarQuery
class, as well as thefromMap
method in theCarSerializer
class throw errors, due to trying to assign potential null values.So my question being: do I miss anything? Should I just make everything nullable?
Besides that, for your info 2 more remarks regarding the package:
@serializable
annotation (hence the respective packages) the code generation does not work in this example. (Which is kinda understandable as it is generating the referenced class). Is there a way to use the package without serializable?My car file:
The generated file