Closed Achraf-cyber closed 2 months ago
Supadart already have static insert and update funtions but sometimes we need toJson method.
@Achraf-cyber Thanks for opening an issue. I think we don't need it as to insert or update we can just pass a Map<String, dynamic>
or List<Map<String, dynamic>>
directly in the insert and update. do you have any other use case for it?
A "toJson" method is useful for caching purpose. In my case. I want to serialize the data that I loaded from the database and store it in a local database like drift. I currently use hydrated_bloc to cache some data and hydrated_bloc required the cached object to have a "toJson" method. The only workaround I found is to create an extension on the autogenerated class. Please add a "toJson" method, it won't hurt. Thank you for creating such an amazing package.
Le ven. 23 août 2024, 21:04, mmvergara @.***> a écrit :
Supadart already have static insert and update funtions but sometimes we need toJson method.
@Achraf-cyber https://github.com/Achraf-cyber Thanks for opening an issue. I think we don't need it as to insert or update we can just pass a Map<String, dynamic> or List<Map<String, dynamic>> directly in the insert and update. do you have any other use case for it?
— Reply to this email directly, view it on GitHub https://github.com/mmvergara/supadart/issues/61#issuecomment-2307736232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUFBBDX56NO2UD5GGJHMZSTZS6ITRAVCNFSM6AAAAABNAM2A6WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXG4ZTMMRTGI . You are receiving this because you were mentioned.Message ID: @.***>
@Achraf-cyber
Map<String, dynamic> toJson() {
return {
'id': id,
if (colPoint != null) 'col_point': colPoint,
if (colPointArray != null) 'col_point_array': colPointArray,
if (colLine != null) 'col_line': colLine,
if (colLineArray != null) 'col_line_array': colLineArray,
if (colLseg != null) 'col_lseg': colLseg,
if (colLsegArray != null) 'col_lseg_array': colLsegArray,
if (colBox != null) 'col_box': colBox,
if (colBoxArray != null) 'col_box_array': colBoxArray,
if (colPath != null) 'col_path': colPath,
if (colPathArray != null) 'col_path_array': colPathArray,
if (colPolygon != null) 'col_polygon': colPolygon,
if (colPolygonArray != null) 'col_polygon_array': colPolygonArray,
if (colCircle != null) 'col_circle': colCircle,
if (colCircleArray != null) 'col_circle_array': colCircleArray,
};
}
It can be as simple as this right?
Yes this is very good. It will be a nice if there an option to activate or deactivate the toJson method generation. Thank you
@Achraf-cyber CLI now updated to 1.5.4, toJson method is now available.
About making it an option i will take note of that, im planning to restructure the generators file,
Thanks for the update.
Le sam. 24 août 2024, 06:54, mmvergara @.***> a écrit :
@Achraf-cyber https://github.com/Achraf-cyber CLI now updated to 1.5.4, toJson method is now available.
About making it an option i will take note of that, im planning to restructure the generators file,
— Reply to this email directly, view it on GitHub https://github.com/mmvergara/supadart/issues/61#issuecomment-2308142280, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUFBBDUHMF2ZRYMT7ACZHNDZTANX5AVCNFSM6AAAAABNAM2A6WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBYGE2DEMRYGA . You are receiving this because you were mentioned.Message ID: @.***>
Supadart already have static insert and update funtions but sometimes we need toJson method.