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

craftybones15:07:42

How do I go about declaring a tuple of instants?

craftybones15: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}
                                                 ]})

craftybones15: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: 

craftybones15: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

craftybones17:07:22

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

craftybones17: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”

💯 3
ghadi17:07:29

what do the dates represent?

marshall17:07:34

vs. card/many

marshall17:07:45

yeah, what @ghadi said 🙂

craftybones17: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?

craftybones17:07:38

Often, not necessarily, there might be rest days etc

craftybones17: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

craftybones17:07:41

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

craftybones17:07:20

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

craftybones17:07:27

Interesting…

ghadi17:07:33

no I mean:

craftybones17: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"]

ghadi17:07:13

not a tuple, just card-many

craftybones17:07:17

Right. Got it

craftybones17:07:27

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

craftybones17: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

craftybones17:07:48

I had a question around composite tuples.

craftybones17:07:22

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

craftybones17:07:31

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

craftybones17:07:39

Assume that the two teams are actually db/ref

craftybones17:07:03

It is likely each of the teams have thousands of entries

craftybones17:07:19

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

ghadi17:07:25

what is the query?

craftybones17: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

craftybones17:07:13

yeah, that’s mostly it

ghadi17:07:30

matches don't span days, I assume

ghadi17:07:36

unless cricket

3
ghadi17:07:09

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

craftybones17: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 🙂

craftybones17:07:38

Thanks a ton mate.

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.

jaret17:07:23

They have a very helpful slack community

jaret17:07:34

but no clojure programmers that I could find 😞

craftybones17: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!

craftybones17:07:49

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

craftybones17:07:07

the PG era is a bit too R for me

jaret17:07:30

Who do you follow?