-
-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default implementation for serialize #30
Comments
I'm pretty sure Mirror doesn't work on Linux because it relies on the Objective-C runtime. But we should double check. |
Hmm, that would be a pity. I'll google it. |
I haven't found any definitive answer yet in Apple documentation, but so far I've seen some stuff that seems to suggest that you don't need Obj-C runtime for this. @tannernelson would you by any chance have a linux vm on your computer which you use to test your code? If so, could you just try to compile that function on that vm? I guess that would be the surest way to answer that question. |
Looks like at least getting the names of the properties works actually on my Linux box. class Test {
var prop = ""
init() { }
}
let test = Test()
let m = Mirror(reflecting: test)
print(m)
for c in m.children {
print(c)
} prints
So we could potentially do this. My concern would be how to differentiate properties that should be stored in the database from ones that shouldn't. Such as computed properties or others. |
That's why we need another class that is aware of the database schema. And I thought somebody was already working on that, right? And then the developers just need to follow the convention that they mirror table field names exactly in their entity property names. Which is a good practice anyway, I think. |
So |
Yes, at least in the sense that it would have at least all the properties that match the database table columns. But of course the Entity is allowed to have more properties, like computed ones. |
Things have changed a bit since this issue was made, so let's revisit it once I merge the refactor of Fluent that works with both SQLite and Mongo. |
https://github.com/Zewo/reflection It does work under Linux. Both reading as well as writing. |
I would personally opt to leave reflection out of it. For me, reflection is a debugging tool that will likely be inconsistent to rely on. I recognize it's a little bit more work up front, but safety is one of the things we want to encourage and utilize in Swift. With good mappers, this is usually very minimal and the user has to decode from data to object either way. |
We tried reflection but it was very inconsistent like logan said. Let's wait for Swift 4 when we will have an improved Mirror class. |
The only reason I'm suggesting this is because I believe we can implement this functionality ourselves, without requiring the creator of any
Entity
to implement it. I already wrote some code to do this.Now we just need some method of determining which columns need to be extracted. But I think someone was already working on a SchemaBuilder and such right? #18
What do you guys think? My preference is to require as little as possible in the
Entity
protocol. If I could also implement afunc unserialize(serialized: [String:Value?]) -> Entity
then I would, but unfortunately that's not possible without turning every Entity into an NSObject.The text was updated successfully, but these errors were encountered: