Fork me on GitHub
#datomic
<
2020-07-07
>
ivar.refsdal12:07:07

Trying to retract a non-existing entity does not fail in 0.9.5951 and later. Is that intentional? Here is my code:

@(d/transact conn [#:db{:ident :order/id, :cardinality :db.cardinality/one, :valueType :db.type/string, :unique :db.unique/identity}])
@(d/transact conn [[:db/retractEntity [:order/id "missing"]]])
; no error in 0.9.5951 (and later)
; error in 0.9.5930:
; datomic.impl.Exceptions$IllegalArgumentExceptionInfo: :db.error/not-an-entity Unable to resolve entity: [:order/id "missing"]
; java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: :db.error/not-an-entity Unable to resolve entity: [:order/id "missing"]
Thanks!

souenzzo12:07:24

## Changed in 0.9.6021

* Fix: Prevent a rare scenario where retracting non-existent entities
  could prevent future transactions from succeeding.

souenzzo12:07:31

(maybe related)

ivar.refsdal09:07:38

Maybe. But the change of behaviour already happened in 0.9.5951, so I'm not sure 0.9.6021 would affect that

srijayanth15:07:42

How do I go about declaring a tuple of instants?

srijayanth15:07:11

(d/transact conn {:tx-data [{:db/ident :foo/bar
                                                  :db/valueType :db.type/tuple
                                                  :db/tupleType :db.type/instant
                                                  :db/cardinality :db.cardinality/one}
                                                 ]})

srijayanth15:07:43

And then when I insert, I did the following:

(d/transact conn {:tx-data [{:foo/bar [#inst "2020-10-10"]}]})

souenzzo16:07:31

As @ghadi pointed: https://docs.datomic.com/cloud/schema/schema-reference.html#tuples

A tuple is a collection of 2-8 scalar values, represented in memory as a Clojure vector. There are three kinds of tuples: 

srijayanth15:07:51

It says its an invalid tuple value

ghadi16:07:23

need to be length 2-8 IIRC

ghadi16:07:12

you sent in a one-ple

srijayanth17:07:22

Ah! Such a silly error! Thanks. So how do I model something that might have a range of 1 to 5 dates?

srijayanth17:07:35

as a many cardinality?

marshall17:07:42

no, you can use a tuple

marshall17:07:50

nil is legal in tuples

ghadi17:07:24

I would want to understand the semantics before modeling it

marshall17:07:27

but i’d only use a tuple if the 1-5 things “go together”

ghadi17:07:29

what do the dates represent?

marshall17:07:34

vs. card/many

marshall17:07:45

yeah, what @ghadi said 🙂

srijayanth17:07:56

The dates represent a range of dates on which a certain tournament occurred. The tournament may range anywhere from 1 to 6 days

ghadi17:07:23

contiguous dates?

srijayanth17:07:38

Often, not necessarily, there might be rest days etc

srijayanth17:07:16

I could obviously simply date range it and say :date/from :date/to

ghadi17:07:24

that's one option

ghadi17:07:41

another is a card-many instant with all the dates enumerated

srijayanth17:07:41

But, the tuple can also preserve order which might become important when querying, potentially

srijayanth17:07:20

You mean have the date as a {:db/ident #inst “some date” }

srijayanth17:07:27

Interesting…

ghadi17:07:33

no I mean:

srijayanth17:07:55

so just :tournament/date has 1-6 values

ghadi17:07:04

:tourney/dates [#inst "2020-07-01" #inst "2020-07-05" #inst "2020-07-07"]

srijayanth17:07:08

yeah. Got it

ghadi17:07:13

not a tuple, just card-many

srijayanth17:07:17

Right. Got it

srijayanth17:07:27

yeah, that’s certainly an option. That’s what I was wondering.

srijayanth17:07:37

Cool. I’ll figure it out. Thanks for the help

ghadi17:07:45

dates are comparable - so the ordering concern shouldn't matter

srijayanth17:07:48

I had a question around composite tuples.

srijayanth17:07:22

so let us say I have a match played between two teams on certain dates

srijayanth17:07:31

does it make sense to turn this into a composite tuple?

srijayanth17:07:39

Assume that the two teams are actually db/ref

srijayanth17:07:03

It is likely each of the teams have thousands of entries

srijayanth17:07:19

I could potentially query thousands of matches that are of specific teams

ghadi17:07:25

what is the query?

srijayanth17:07:03

give me the final score of all matches played between two teams in a given date range

ghadi17:07:50

[:find (pull ?match [:match/score])
:where 
[?match :participating/team ?t1]
[?match :participating/team ?t2]
[?match :tourney/dates ?d]
[(>= ?d ?start-date)]
[(<= ?d ?end-date)]]

ghadi17:07:12

with ?t1 ?t2 ?start-date and ?end-date as inputs

srijayanth17:07:13

yeah, that’s mostly it

ghadi17:07:30

matches don't span days, I assume

ghadi17:07:36

unless cricket

srijayanth17:07:39

they don’t

ghadi17:07:09

@jaret (on the Datomic team) and I are big NBA fans 🙂

srijayanth17:07:32

Ah. There’s no easy place for easy open NBA data. ESPN took their API down

ghadi17:07:34

anyways, I gotta run 🙂

srijayanth17:07:38

Thanks a ton mate.

jaret17:07:30

@srijayanth I was using https://www.mysportsfeeds.com/ for NBA data

jaret17:07:04

admittedly the project I was using it on was OK with stale data from last season, but they have live subscriptions. Not sure what your budget is.

srijayanth17:07:08

@jaret - thanks

jaret17:07:23

They have a very helpful slack community

jaret17:07:34

but no clojure programmers that I could find 😞

srijayanth17:07:49

If you’re on the datomic team, that puts you on the east coast….Knicks fan?

jaret17:07:12

Oh god no! furthest thing from it. I am a Pacers fan!

srijayanth17:07:49

Ah. The late 90s teams of the Pacers were really good. Early 2000s too.

srijayanth17:07:07

the PG era is a bit too R for me

jaret17:07:30

Who do you follow?