Skip to content
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

Implement serialization/deserialization of fields #4

Open
mitar opened this issue Mar 3, 2014 · 1 comment
Open

Implement serialization/deserialization of fields #4

mitar opened this issue Mar 3, 2014 · 1 comment

Comments

@mitar
Copy link
Member

mitar commented Mar 3, 2014

The most typical use case which we are not yet supporting is serialization/deserialization of fields. So that in JavaScript instances fields are represented by some other value than what is stored in the database. For example, one use case is to store timestamps as Date objects, but use momentjs objects in JavaScript instances.

This is something which is traditionally done by providing custom field types, which know how to serialize/deserialize to and from the database. So we could have a DatetimeField, which would store timestamp as Date object into the database, when it would get it as moment value, and when reading from the database, it would convert Date to moment.

Similarly we can then also implement references (which are just a special case of this), so that users can simply assign some referenced object, and PeerDB makes sure to extract _id and store only that (and any configured fields) into the database. And in the other direction (which is currently already supported as a special case.)

@mitar
Copy link
Member Author

mitar commented Dec 1, 2014

Probably the best approach here would be that fields modify how document is serialized by EJSON. So that fields provide a decoupled way to augment EJSON serialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant