CosmicMind / Graph

Graph is a semantic database that is used to create data-driven applications.
http://cosmicmind.com
MIT License
873 stars 72 forks source link

Feature Request: Make Entity conforming to Codable or offer a #144

Closed karstengresch closed 6 years ago

karstengresch commented 6 years ago

Hi all, especially Daniel :)

I'm in a need including Entity vars in a struct that conforms to Codable (as of Swift 4).

Not sure if that makes sense in regards to the Graph API philosophy, but to me, that'd be useful as I wouldn't need to remodel the Entity's structure.

Thanks for Graph anyway - what a decent piece of great software!

Best wishes,

Karsten

daniel-jonathan commented 6 years ago

Hey @karstengresch :)

Happy that you are enjoying Graph. Are you talking about the Swift 4.2 dynamic properties so you don't have to access the API using subscripting? If so, the second I heard about this update... I was like "finally".

OrkhanAlikhanov commented 6 years ago

@danieldahan I think he wants us to make Entity type conform to Codable. This great idea because swift structs with Codable get implicit conformance by the compiler without any need for explicitly conformance to Codable by the developer if and only if all struct members conform to Codable.

karstengresch commented 6 years ago

@danieldahan @OrkhanAlikhanov Thanks for your replies - @OrkhanAlikhanov is right: I just think of conformance to Codable.

This would e.g. allow putting an Entity object into a Codable conformant struct (part of a larger data model) that gets locally persisted as a replacement for UserDefaults.

Not sure if this makes sense for you @danieldahan ?

Best wishes,

Karsten

daniel-jonathan commented 6 years ago

@karstengresch Yes it does. I think this should be doable. Let's leave this request up for now and tackle it within the next week, @OrkhanAlikhanov. Thank you!

OrkhanAlikhanov commented 6 years ago

@karstengresch in what cases would you use Entity as Codable? Can you elaborate more on your above example?

daniel-jonathan commented 6 years ago

Base solution is here https://github.com/CosmicMind/Graph/pull/152#pullrequestreview-146460462, although, we have more we would like to add feature wise. We will make a new issue to articulate the new issues.

karstengresch commented 6 years ago

@OrkhanAlikhanov, @danieldahan - thanks for making this happen! You guys really rock.

@OrkhanAlikhanov regarding your question: I started using Codable instead of UserDefaults and want to integrate an entire Graph as part of a struct which then is persisted via Codable and synchronized via CloudKit.

Of course I'm aware there's GraphJSON w/ serialization and Graph w/ built-in CloudKit support, but in my case the entire struct with it's different nested elements would hardly be manageable for me w/ Graph. Makes sense?

Anyway - @OrkhanAlikhanov thank you so much for your pull request and @danieldahan to let it get into the code base!

daniel-jonathan commented 6 years ago

@karstengresch Keep the great requests/questions coming and we will work to improve our products :) Thank you!