tauri-plugin-sql
tauri-plugin-sql copied to clipboard
Support/parse nested json with serde_json::from_value
I'm playing with tauri-plugin-sql and thinking about moving my app (https://github.com/iohzrd/identia) to using it but I've noticed that columns that contain JS objects don't get parsed and are returned as strings.
It would be nice to automatically parse nested objects so that no extra parsing is required in JS land.
This is something I was able to accomplish using serde_json::from_value, as can be seen here. I'm happy to implement it myself and submit a pull request, but I figured I'd start a conversation, so we can come to the optimal solution. I.e. should we target BLOB, STRING etc...
pull request with simplest possible implementation: https://github.com/tauri-apps/tauri-plugin-sql/pull/92
After playing with it a bit more, I think the best way to proceed is to use serde_json::from_value for BLOB columns, and leave the rest as is. This way we can retain support for arrays, but also support other JSON objects.
tbh personally, i consider this out of scope and would just recommend using TEXT/VARCHAR (seems to be the commonly used default for json in sqlite) + JSON.parse in the frontend
@iohzrd I agree with @FabianLars ... I think the frontend being required to parse a string value is a good solution for now. I'm going to close this for now but if you really want this feature maybe you can setup a zoom call with me and we can discuss why this is worth doing.