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

Convert field-IDs to clojure keywords on :firestore/get #31

Open
rbrother opened this issue Dec 8, 2018 · 4 comments
Open

Convert field-IDs to clojure keywords on :firestore/get #31

rbrother opened this issue Dec 8, 2018 · 4 comments

Comments

@rbrother
Copy link

rbrother commented Dec 8, 2018

Thanks for excellent library, very useful and elegant! :-)

When I save data { :first "mike", :last "thompson"} with :firestore/add and then later read it with :firestore/get, the result is { "first" "mike", "last" "thompson"} ie. the keys have changed to strings.

I understand that firestore does not support keywords and needs to convert them to strings, but perhaps when reading data back from firestore your library could convert all keys in maps to keywords? I can do this myself, but you can consider if it might be ok to do it on lbrary level.

@deg
Copy link
Owner

deg commented Dec 9, 2018 via email

@gabrielsimoes
Copy link
Contributor

I think I simply implemented the most general way possible (using strings instead of keywords, as there might be someone who prefers to use strings). I think there is a way to just pass a flag at initialization, and that flag could be checked at the time of converting JS objects to "Clojure".

@rbrother
Copy link
Author

Thanks for your quick replies! I will look at the codebase and see if I can implement a flag for retaining keywords in keys as suggested. I noticed the similar problem (though less common) is for map values that are keywords and also converted to strings. I have less problem with switching to use strings instead if keywords as the values of maps in my app, but for keys it's more important.

Another possibility instead of a flag would be to store :abc as ":abc" i.e. store a colon as sign of a keyword and then restore that string back to keyword. This would work well for both keys and values. Might of course break things as well, so better test it out.

@shen-tian
Copy link
Contributor

shen-tian commented Feb 4, 2019

Sounds like this is a more general question of what to do with the (lossy) conversion of clojure data structures to JSON and back again.

This does the conversion back:

(js->clj (.data doc (clj->SnapshotOptions snapshot-options))))

Changing it to (js->clj ... :keywordize-keys true) should do the trick.

What's worth notting is that within the library, the realtime database does keywordize-keys, so follows a different convention than firestore, which is confusing.

I'd suggest a initialisation time flag be introduced to enable keywordizing behaviour, leaving the default as is. Perhaps a future major release could change the defaults to be consistent.

Will try to do a PR this week, life allowing :)

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

4 participants