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
Improve encoding practices during saving #182
Comments
Field types:
Serialization types:
Execution order:
Developer should be mindful and take care of type / serialize clashes himself. If he use On worst case developer can always use:
|
everything sounds great! let's call that thing object (not stdobject/stdclass). Few notes:
Future:
|
Another note. If you use combination of type=array/object and serialize= then I think we shouldn't double-serialize if we can help it. I think we only need "json" serialize type.
etc. |
Currently when you save a field, it executes
typecastSaveField
that must convert PHP value into database-friendly value. For example for MongoDB it would convert date from DateTime into MongoDate, for SQL it would convert it into "STRING".In some cases we want to encode / serialize data. For exmaple we want to store "array" into a field or even some arbitrary data (could be array, could be string could be boolean). Also what about storing StdObject? Another case is storing binary data in base64? and what about encrypting data?
If you do not define type, then by definition AgileData will not perform any conversion, but that's not what we want.
I think there should be another mechanism to encode data.
the above would cause data to be
serialize()
d before it actually hits the database. Upon load the data will be un-serialized. Also we could define several serialization mechanisms:or
There are however few questions that stop me from implementing this:
Combining type and serialization
What if I want to use DateTime type and serialize it into SQL?
Unfortunately when used with SQL this would convert datetime into string first, then serialize string and then store. Not really what user migth have wanted. I think DateTime object should be serialized without typecasting.
On other hand, what abut this:
base64 can only store strings so attempting to serialize date will cause a problem. Would serialize be different depending on if we store inside Mondo or SQL ? It shouldn't be, right? Creating multiple 'serialize' / 'encode' etc parameters seems like an overkill already.
json_decode - should it use true/false?
json_encode / decode cannot distinguish between "StdClass" objects and arrays. So you would have to specify which one you want. Do we create 2 different serialization types because of that?
conflicting with types
Currently we have type "struct" that stores array as json. It does not really allow to store non-array values. I think it should be renamed into 'array' anyway, but tehn would 'struct' shore StdClass objects? what about storing scalar values?
The text was updated successfully, but these errors were encountered: