This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-10
Channels
- # announcements (1)
- # babashka (44)
- # beginners (188)
- # calva (37)
- # chlorine-clover (28)
- # cider (12)
- # clj-kondo (40)
- # clojars (1)
- # clojure (323)
- # clojure-austin (7)
- # clojure-europe (20)
- # clojure-italy (4)
- # clojure-nl (16)
- # clojure-spec (7)
- # clojure-uk (37)
- # clojuredesign-podcast (1)
- # clojurescript (30)
- # cryogen (2)
- # cursive (30)
- # data-science (1)
- # datomic (26)
- # emacs (1)
- # events (1)
- # figwheel-main (13)
- # fulcro (89)
- # garden (1)
- # graalvm (20)
- # graphql (8)
- # jobs (1)
- # jobs-discuss (1)
- # joker (6)
- # kaocha (125)
- # lambdaisland (1)
- # meander (42)
- # off-topic (18)
- # pathom (3)
- # pedestal (6)
- # shadow-cljs (55)
- # spacemacs (21)
- # sql (18)
- # tools-deps (8)
- # uncomplicate (2)
- # vim (1)
- # yada (3)
Should you type hint in Datomic queries? For example:
(d/q
'[:find ?e ?mins
:where
[?e :my-date ?transition-date]
[(.toInstant ?transition-date) ?i]
[(.atZone ^java.time.Instant ?i (java.time.ZoneId/of "UTC")) ?zoned-dt]
[(.toLocalDateTime ?zoned-dt) ?local-dt]
[(.getMinute ?local-dt) ?mins]]
(d/db conn))
I might consider using a function of my own inside the query at this point. Something like (com.example.time/minutes ?transition-date)
.
(So generally, yes, unless it’s throwaway code or type inference figured out the type already)
Hi everyone, does using API Gateway HTTP Direct with Ions avoid any cold start up latency given it doesn’t involve a Lambda at all? Are there other latency trade-offs to consider? https://blog.datomic.com/2019/05/http-direct-for-datomic-cloud.html
hello! probably a datomic newbie situation here: i am not sure how to use (or if it is possible to use) a tuple attribute that models a natural composite key as the value of an attribute that is a ref. my situation is this: template-schema
[...
{:db/ident :template/id
:db/cardinality :db.cardinality/one
:db/valueType :db.type/uuid
:db/unique :db.unique/identity}
{:db/ident :template/name
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string}
{:db/ident :template/provider
:db/cardinality :db.cardinality/one
:db/valueType :db.type/ref}
{:db/ident :template/provider+name
:db/cardinality :db.cardinality/one
:db/valueType :db.type/tuple
:db/tupleAttrs [:template/provider :template/name]
:db/unique :db.unique/identity}
...]
infocard-schema
[...
{:db/ident :infocard/id
:db/cardinality :db.cardinality/one
:db/valueType :db.type/uuid
:db/unique :db.unique/identity}
{:db/ident :infocard/user-id
:db/cardinality :db.cardinality/one
:db/valueType :db.type/uuid}
{:db/ident :infocard/template
:db/cardinality :db.cardinality/one
:db/valueType :db.type/ref}
...]
i thought it would be possible to transact an infocard referring to an existing template like this:
(d/transact conn {:tx-data [#:infocard{...
:template [:template/provider+name [:provider/engage "test-template]]
...}]})
but when i do this the result is unable to resolve entity
. what am i doing wrong?Composite attrs are not meant to be transacted directly, but computed automatically (otherwise they can get out of sync with their values)
that said, I haven’t personally been able to use an identity composite ref attribute in any way other than explicitly asserting tempids for the composite value and all its components. It appears that tempid resolution to existing entities occurs before composites are computed, (at least the last time I checked). In practice this means identity composites are not useful for upserting, only guaranteeing uniqueness (carefully)
I’d welcome some clarification on whether this is considered by-design and what one should do if an identity composite key is desired
i my case i don’t assert the composite directly, the template already exists in the database and the composite was calculated by datomic itself.
after the template is there, i try to create an infocard referring to it but using the composite key as a unique id instead of the surrogate uuid because the composite key is what clients know.
(so my api receives the pair provider/name instead of the surrogate key when creating an infocard.)
and by making it an identity attribute that strongly suggests you mean for this to be upserting
so this is the first flaw. 🙂 what i’d like to do is to refer to the template by its composite key.
if you don’t want to assert it, use it as a lookup ref (which I think should work now but earlier versions were buggy about): {:db/id [:template/provider+name [:provider/engage "test-template]] …}
ah, let me try that.
Note using a lookup ref will fail if the entity doesn’t already exist, but your earlier transaction could succeed (if the lookups were resolved, that is)
what about queries? i should be able to fetch templates using :where [?e :template/provider+name [:provider/engage "test-template]]
, right?
looking at the transaction grammar (https://docs.datomic.com/cloud/transactions/transaction-data-reference.html#orge639385) it seems that [attr value] should be a valid entity identifier, that is why i used that form trying to transact the infocard.
I think that syntax works in queries, but maybe you have to use tuple
to assemble the value