ismyhc on Nostr: I haven't used value transformers before. Im going to look into them though. Right ...
I haven't used value transformers before. Im going to look into them though.
Right now I have a handful of models that I create from events as they come in, then store them into SwiftData, but that code is getting overly complicated. So before I dig too deep Im experimenting with something that may or may not work.
Instead of having all these different SwiftData models, Im simply storing a single model for the event. Almost as it would be stored on a relay. One addition to the model is that I serialize the tags into a single special formatted string since trying to use a predicate on nested arrays might get messy.
The idea is that this keeps my data model more simple as well as code path where I store these events.
Then I will use the queries to map the stored event's into their more detailed object where needed.
The unknown I have now is if doing this will cause too much overhead on the UI. I just don't know yet, but my code is early enough that I can try it and if it works as I hope it does it simplifies the code around this a lot.
Published at
2024-07-31 14:04:45Event JSON
{
"id": "5c9e373ff7826f6b4328060e20bdbf9e5e523de82e5dc8c436f7ec4a19555fb8",
"pubkey": "c5cfda98d01f152b3493d995eed4cdb4d9e55a973925f6f9ea24769a5a21e778",
"created_at": 1722434685,
"kind": 1,
"tags": [
[
"e",
"2b1dda78cb6d202f113e6f924e12fbea90676ff7b27321ebb4f545a3773d43fd",
"wss://relay.nostr.bg/all",
"root"
],
[
"e",
"d3a212ebed48464c7500e240c360d3638a76aecebbbda74b78e5eb86aa0a4a9f",
"wss://relay.nostr.bg/all",
"reply"
],
[
"p",
"c5cfda98d01f152b3493d995eed4cdb4d9e55a973925f6f9ea24769a5a21e778"
],
[
"p",
"2779f3d9f42c7dee17f0e6bcdcf89a8f9d592d19e3b1bbd27ef1cffd1a7f98d1"
]
],
"content": "I haven't used value transformers before. Im going to look into them though.\n\nRight now I have a handful of models that I create from events as they come in, then store them into SwiftData, but that code is getting overly complicated. So before I dig too deep Im experimenting with something that may or may not work.\n\nInstead of having all these different SwiftData models, Im simply storing a single model for the event. Almost as it would be stored on a relay. One addition to the model is that I serialize the tags into a single special formatted string since trying to use a predicate on nested arrays might get messy.\n\nThe idea is that this keeps my data model more simple as well as code path where I store these events.\n\nThen I will use the queries to map the stored event's into their more detailed object where needed.\n\nThe unknown I have now is if doing this will cause too much overhead on the UI. I just don't know yet, but my code is early enough that I can try it and if it works as I hope it does it simplifies the code around this a lot.",
"sig": "17e8374631cd3c7321f65face69781fed59153e861b995c99250fac218b088e5b4612a71f9dbe356bb156606ef606a998b0e5dcff8820d8f84980c2a168d3c75"
}