Discussion:
Pull pattern for enums with Datomic 0.9.5078
Guillermo Winkler
2014-12-03 17:36:26 UTC
Permalink
Ok, already answered here

https://groups.google.com/forum/#!topic/datomic/hnWqKmbNAhE
Hi, I’m having some doubts regarding the results projected by the pull API when the schema has an enum value.
{:db/ident :post/status
:db/id #db/id [:db.part/db]
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
;;statuses
[:db/add #db/id[:db.part/user] :db/ident :status/draft]
[:db/add #db/id[:db.part/user] :db/ident :status/published]
When pulling all attributes are requested
(d/pull db [:*] 17592186045522)
Post status is projected as a datomic entity, and not as the keyword for the “enum value".
:post/status {:db/id 17592186045453}
If I request specifically the enumerated value as a reference.
(d/pull db [:*
{:post/status [:db/ident]
...}] 17592186045522)
The post/status field is properly solved.
:post/status {:db/ident :status/draft},
This doesn’t seem to be consistent with the results returned when using the d/entity API call
(:post/status (d/entity db 17592186045522))
=> :status/draft
There is a way to achieve consistency when using the pull api for “enum like” references?
With the current situation we need to have special consideration with the projected results if coming from one API or another.
Thanks
Guille
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
t***@gmail.com
2014-12-04 05:28:42 UTC
Permalink
I had the same problem and used postwalk and a provided list of refs:

(defn replace-ref-types [dbc refs m]
(clojure.walk/postwalk
(fn [arg]
(if (and (coll? arg) (refs (first arg)))
(update-in arg [1] (comp :db/ident (partial d/entity dbc) :db/id))
arg))
m))

(replace-ref-types db #{:post/status} (d/pull db [:*] 17592186045522))


Could probably make this smarter so it automatically checks if an attribute
is a ref and acts accordingly, but this should work for now.
-Zack
Post by Guillermo Winkler
Ok, already answered here
https://groups.google.com/forum/#!topic/datomic/hnWqKmbNAhE
Hi, I’m having some doubts regarding the results projected by the pull API
when the schema has an enum value.
{:db/ident :post/status
:db/id #db/id [:db.part/db]
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
;;statuses
[:db/add #db/id[:db.part/user] :db/ident :status/draft]
[:db/add #db/id[:db.part/user] :db/ident :status/published]
When pulling all attributes are requested
(d/pull db [:*] 17592186045522)
Post status is projected as a datomic entity, and not as the keyword for
the “enum value".
:post/status {:db/id 17592186045453}
If I request specifically the enumerated value as a reference.
(d/pull db [:*
{:post/status [:db/ident]
...}] 17592186045522)
The post/status field is properly solved.
:post/status {:db/ident :status/draft},
This doesn’t seem to be consistent with the results returned when using
the d/entity API call
(:post/status (d/entity db 17592186045522))
=> :status/draft
There is a way to achieve consistency when using the pull api for “enum
like” references?
With the current situation we need to have special consideration with the
projected results if coming from one API or another.
Thanks
Guille
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ethan Miller
2017-05-08 10:06:55 UTC
Permalink
Is this still a limitation of the pull api?
Post by t***@gmail.com
(defn replace-ref-types [dbc refs m]
(clojure.walk/postwalk
(fn [arg]
(if (and (coll? arg) (refs (first arg)))
(update-in arg [1] (comp :db/ident (partial d/entity dbc) :db/id))
arg))
m))
(replace-ref-types db #{:post/status} (d/pull db [:*] 17592186045522))
Could probably make this smarter so it automatically checks if an
attribute is a ref and acts accordingly, but this should work for now.
-Zack
Post by Guillermo Winkler
Ok, already answered here
https://groups.google.com/forum/#!topic/datomic/hnWqKmbNAhE
Hi, I’m having some doubts regarding the results projected by the pull
API when the schema has an enum value.
{:db/ident :post/status
:db/id #db/id [:db.part/db]
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
;;statuses
[:db/add #db/id[:db.part/user] :db/ident :status/draft]
[:db/add #db/id[:db.part/user] :db/ident :status/published]
When pulling all attributes are requested
(d/pull db [:*] 17592186045522)
Post status is projected as a datomic entity, and not as the keyword for
the “enum value".
:post/status {:db/id 17592186045453}
If I request specifically the enumerated value as a reference.
(d/pull db [:*
{:post/status [:db/ident]
...}] 17592186045522)
The post/status field is properly solved.
:post/status {:db/ident :status/draft},
This doesn’t seem to be consistent with the results returned when using
the d/entity API call
(:post/status (d/entity db 17592186045522))
=> :status/draft
There is a way to achieve consistency when using the pull api for “enum
like” references?
With the current situation we need to have special consideration with the
projected results if coming from one API or another.
Thanks
Guille
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...