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

Nested pulls don't get correct datatype #34

Closed
mgerlach-klick opened this Issue Sep 27, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@mgerlach-klick
Contributor

mgerlach-klick commented Sep 27, 2018

If I have a :user/date and a :company/date and both are of type timestamptzand there are many users in a company, and I do a (q '[:pull [:company/date {:company/users [:user/date]}]]) then :company/date will be an instant, but :user/date a string.

I don't quite understand how you're doing the pull magic, but it seems like there's a final tree traversal that converts datatypes, or something like that, missing

@swlkr

This comment has been minimized.

Collaborator

swlkr commented Oct 3, 2018

Yeah it's interesting, I thought the extension to read json from postgres would handle this, but unfortunately, it does not.

Another option which I was kind of not wanting to do because I sort of already hacked up a solution using this is clojure.walk where I look for postgres date/time columns in schema.edn and parse dates to instants, manually.

Maybe I can figure out a way to extend the postgres driver to do this though.

@mgerlach-klick

This comment has been minimized.

Contributor

mgerlach-klick commented Oct 7, 2018

I stared at your code in https://github.com/coast-framework/coast/blob/master/src/coast/db/query.clj for a while and now have a general idea on how you do things (related, it would be super helpful if you put some docstrings on the namespaces that explain the general ideas of what's happening).

So yeah, if you're building a JSON object, you will always just get text. Postgres has no idea what text represents a date or a datetime, and converting them just by pattern-matching could lead to some awkward false-positives. I can't think of a way that doesn't involve a tree-walk either..

@swlkr swlkr closed this in b40b884 Oct 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment