Fork me on GitHub
#datomic
<
2018-12-28
>
rboyd00:12:17

besides datomic console, are there any notable tools to analyze/report on my database? specifically I'd like to understand how my db is growing or which entities account for the most used storage

dogenpunk20:12:18

Could someone explain to me how to transact entities with components using the client API? I seem to have a critical hole (or two) in my understanding.

dogenpunk20:12:19

{:db/ident :booking/rrule
 :db/cardinality :db.cardinality/one
 :db/valueType :db.type/ref
 :db/isComponent true}
{:db/ident  :rrule/frequency
    :db/cardinality :db.cardinality/one
    :db/valueType :db.type/long}

dogenpunk20:12:13

When I try transacting

{:booking/rrule {:rrule/frequency 1}}
I get errors re: tempids as only value

dogenpunk20:12:42

But when I transact

{:booking/rrule {:rrule/frequency 1 :_booking tempid}}
I get fault anomalies when I try to pull :booking/rrule attributes

marshall20:12:08

what is the schema for :rrule/attr

dogenpunk20:12:50

Ok, I looked that over and thought that

{:booking/rrule {:rrule/frequency 1}}
would work, however, I keep getting “tempid used only as value” errors

dogenpunk20:12:58

Do components have to be wrapped in a vector even if :db.cardinality/one?

marshall20:12:09

I don’t believe so

dogenpunk20:12:52

Or are components required to have unique ids aside from :db/id?

marshall20:12:08

try adding :db/id "foo" to the inner entity

dogenpunk20:12:31

Should “foo” refer to the parent :booking entity tempid?

marshall20:12:35

it shouldn’t “need it” but i’m wondering if there is an edge case here

marshall20:12:41

no, a random tempid

marshall20:12:57

do you have a parent entity tempid?

marshall20:12:26

if that’s a truncated ^ version of your transaction, can you share the full thing please?

dogenpunk20:12:02

Here’s the full transaction:

{:booking/duration "PT1H", :booking/recur-set {:recur-set/rdate [], :recur-set/exdate [], :db/id "bar"}, :booking/student 60842575434612841, :booking/studio 16958867346817130, :booking/dtstart #inst "2015-04-06T21:30:00.000-00:00", :db/id "de92a84f-257c-47b9-bb14-6059bc534c4f", :booking/rrule {:rrule/frequency 1, :rrule/interval :rrule.interval/weeks, :db/id "foo"}, :booking/dtend #inst "2015-04-06T22:30:00.000-00:00", :booking/status :booking.status/scheduled, :booking/instructor 41539549297377384}

marshall20:12:35

and :booking/duration is db.type string?

marshall20:12:52

rrule and recur-set are cardinality 1?

dogenpunk20:12:21

If I remove :booking/rrule and :booking/recur-set the transaction succeeds

marshall20:12:42

if you leave either one it is still an issue?

dogenpunk20:12:57

Yes, I have to remove both

dogenpunk20:12:48

If I replace the :db/id in the recur-set and rrule with the parent db/id it succeeds, but then I get faults when querying those attributes

marshall20:12:13

try making them “unnested” for testing:

marshall20:12:40

{:booking/duration "PT1H", 
 :booking/recur-set "bar", 
 :booking/student 60842575434612841, 
 :booking/studio 16958867346817130, 
 :booking/dtstart #inst "2015-04-06T21:30:00.000-00:00", 
 :db/id "de92a84f-257c-47b9-bb14-6059bc534c4f", 
 :booking/rrule "foo", 
 :booking/dtend #inst "2015-04-06T22:30:00.000-00:00", 
 :booking/status :booking.status/scheduled, 
 :booking/instructor 41539549297377384}
 {:recur-set/rdate [], :recur-set/exdate [], :db/id "bar"}
 {:rrule/frequency 1, :rrule/interval :rrule.interval/weeks, :db/id "foo"}

dogenpunk20:12:46

(let [{:keys [instructor student studio dtstart dtend duration status rrule recur-set]} booking-two
        booking "baz"
        tx-booking #:booking{:instructor instructor
                             :student    student
                             :studio     studio
                             :dtstart       (java.util.Date/from dtstart)
                             :dtend         (java.util.Date/from (t/>> dtstart duration))
                             :duration      (.toString duration)
                             :status        ((fnil keyword "booking.status" "scheduled") "booking.status" status)
                             :db/id         booking
                             :recur-set "bar"
                             :rrule "baz"}]
    (d/transact conn {:tx-data [tx-booking
                                {:rrule/frequency 1
                                 :rrule/interval :rrule.interval/weeks
                                 :db/id "baz" }
                                {:recur-set/rdate []
                                 :recur-set/exdate []
                                 :db/id "bar"}]}))
Execution error (ExceptionInfo) at datomic.client.api.async/ares (async.clj:56).
tempid used only as value in transaction

dogenpunk20:12:13

Just to be sure:

(d/transact conn {:tx-data [{:booking/duration "PT1H", 
 :booking/recur-set "bar", 
 :booking/student 60842575434612841, 
 :booking/studio 16958867346817130, 
 :booking/dtstart #inst "2015-04-06T21:30:00.000-00:00", 
 :db/id "de92a84f-257c-47b9-bb14-6059bc534c4f", 
 :booking/rrule "foo", 
 :booking/dtend #inst "2015-04-06T22:30:00.000-00:00", 
 :booking/status :booking.status/scheduled, 
 :booking/instructor 41539549297377384}
 {:recur-set/rdate [], :recur-set/exdate [], :db/id "bar"}
 {:rrule/frequency 1, :rrule/interval :rrule.interval/weeks, :db/id "foo"}]})
Execution error (ExceptionInfo) at datomic.client.api.async/ares (async.clj:56).
tempid used only as value in transaction

marshall20:12:15

i would try leaving one of the 2 components in (rrule or recur-set) and then remove one attr at a time from it

marshall20:12:20

see if you can narrow it to a specific one

marshall20:12:32

this is almost always caused by either type mismatch or cardinality issue

dogenpunk20:12:12

Ok, makes sense. I’ll see if I can get a minimal case

dogenpunk20:12:42

But, nesting a map for a component like this is supported?

marshall20:12:51

it should be

marshall20:12:54

i’m testing it also

dogenpunk21:12:31

Ok, this works:

(d/transact conn {:tx-data [{:booking/duration "PT1H", 
 :booking/student 60842575434612841, 
 :booking/studio 16958867346817130, 
 :booking/dtstart #inst "2015-04-06T21:30:00.000-00:00", 
 :db/id "de92a84f-257c-47b9-bb14-6059bc534c4f", 
 :booking/dtend #inst "2015-04-06T22:30:00.000-00:00", 
 :booking/status :booking.status/scheduled, 
 :booking/instructor 41539549297377384}
                                                             {:recur-set/rdate [], :recur-set/exdate [], :db/id "de92a84f-257c-47b9-bb14-6059bc534c4f", }
                                                             {:rrule/frequency 1, :rrule/interval :rrule.interval/weeks, :db/id "de92a84f-257c-47b9-bb14-6059bc534c4f", }]})

marshall21:12:34

(def client (d/client cfg))
(d/list-databases client {})
(d/create-database client {:db-name "marshall-test"})
(def conn (d/connect client {:db-name "marshall-test"}))

(def schema [;; person
             {:db/ident       :person/email
              :db/valueType   :db.type/string
              :db/unique      :db.unique/identity
              :db/cardinality :db.cardinality/one}
             {:db/ident       :person/name
              :db/valueType   :db.type/ref
              :db/cardinality :db.cardinality/one
              :db/isComponent true}
             ;; name
             {:db/ident       :name/first
              :db/valueType   :db.type/string
              :db/cardinality :db.cardinality/one}
             {:db/ident       :name/last
              :db/valueType   :db.type/string
              :db/cardinality :db.cardinality/one}])

(d/transact conn {:tx-data schema})

(def data [{:person/email ""
            :person/name {:name/first "Marshall"}}])


(d/transact conn {:tx-data data})
{:db-before {:database-id "fdeaa432-a7c5-4df3-8259-766ec206974d", :db-name "marshall-test", :t 4, :next-t 5, :type :datomic.client/db}, :db-after {:database-id "fdeaa432-a7c5-4df3-8259-766ec206974d", :db-name "marshall-test", :t 5, :next-t 6, :type :datomic.client/db}, :tx-data [#datom[13194139533317 50 #inst "2018-12-28T21:12:14.808-00:00" 13194139533317 true] #datom[10106710882517060 64 "" 13194139533317 true] #datom[10106710882517060 65 10106710882517061 13194139533317 true] #datom[10106710882517061 66 "Marshall" 13194139533317 true]], :tempids {"datomic.temp-1000005" 10106710882517061}}

marshall21:12:44

@dogenpunk ^ seems to work fine

ronny21:12:26

Could somebody help howto setup datomic cloud lambdas and logging?

ronny21:12:38

I tried lambda-logging together with clojure.tools.logging but I don’t find any documentation howto bring it to work.

dogenpunk23:12:06

@marshall Thanks, I’ll dig in more.