Fork me on GitHub
#datomic
<
2022-02-25
>
Andrej Golcov10:02:50

Hi, One more question, related to my previous question. We have parent-child relations in datomic, something like:

[
 { :rootId "1" :childIds [{:childType "a" :childId "2"} {:childType "b" :childId "3"}]}
 { :rootId "2" :childIds [{:childType "b" :childId "4"}}
]
IOW, root entity references child enitity. Child entity has a type ("a", "b" in the example above) Q: how I can query all root entities with child entities of specific type (e.g. "a") or nil/defaultValue if there is not such childType (kind of outer join). For example above, I need the following rows:
rootId - childIdOfTypeA
"1" - "a"
"2" - nil/orSomeDefaultValue
thanks

zendevil.eth16:02:18

when I’m fetching a datomic entity, is there a way to get the timestamp of the transaction too?

enn16:02:21

which transaction?

zendevil.eth16:02:22

(def first-movies [{:movie/title "The Goonies"
                    :movie/genre "action/adventure"
                    :movie/release-year 1985}
                   {:movie/title "Commando"
                    :movie/genre "action/adventure"
                    :movie/release-year 1985}
                   {:movie/title "Repo Man"
                    :movie/genre "punk dystopia"
                    :movie/release-year 1984}])
(d/transact conn {:tx-data first-movies})
I can get entities:
(def all-movies-q '[:find ?e 
                    :where [?e :movie/title]])
(d/q all-movies-q db)
gives:
[[17592186045418] [17592186045419] [17592186045420]]
But what about the time when the entity was created?

Lennart Buit16:02:13

although, getting stuff from the history is slower than from the present

favila16:02:58

> But what about the time when the entity was created?

favila16:02:07

“creation” has an application-defined meaning

favila16:02:49

You could ask for the time an entity id was minted (i.e. a tempid in tx-data was replaced with a new entity id), but that’s likely not meaningful to the application except with a pile of assumptions. You can do this because the “T” part of the entity id interleaves with the T of the transaction entity

favila16:02:06

(although I’m not sure this is true in cloud--I’ve heard rumors it isn’t)

Lennart Buit16:02:13

(This is the concept being referred to: https://vvvvalvalval.github.io/posts/2017-07-08-Datomic-this-is-not-the-history-youre-looking-for.html, you shouldn’t use the history for your applications core functionality. You could use it for auditing purposes)

zendevil.eth16:02:13

just the time of the entity tx, is there a way to get it by default? If not what’s the idiomatic way to store the entity time?

zendevil.eth16:02:41

does :db/txInstant exist by default?

favila16:02:45

> If not what’s the idiomatic way to store the entity time?

favila16:02:56

make an attribute, and write the appropriate time

favila16:02:19

> does :db/txInstant exist by default

favila16:02:30

it always exists, but only on the transaction entity

souenzzo15:02:56

@U01F1TM2FD5 you have one "modified date" for each attribute/value in the entity

zendevil.eth16:02:28

Is there a way to ensure that when I’m transacting an entity, that certain attributes exist in the tx and others don’t, or is it something that should be checked in the application level?

Lennart Buit16:02:48

you can assert that attributes are present

Lennart Buit16:02:06

but; I believe that to only be positive, so only that an entity has certain attributes; not that it cannot have others

Lennart Buit16:02:50

(like how maps are ‘open’ in clojure as well, intentionally)

favila16:02:48

The entity predicate can do anything it wants, including check that an attribute is not asserted.

favila16:02:38

but without writing code, entity specs can only require that an attribute is asserted

Lennart Buit16:02:56

I stand corrected, I was talking about the required attribute feature

Lone Ranger18:02:40

I have a really old .h2 datomic database file that I need to recover some data from. We have a pro on-prem license. Is there any way I can access that without having to build a special purpose project with datomic free?

Lone Ranger18:02:15

Just to close the loop: I used this docker: https://github.com/alexanderkiel/datomic-free and attached the data directory as a volume, then I was able to use

(d/get-database-names "datomic:")
to get the name of the databases and recover the data

JohnJ21:02:00

you can use the dev mode storage in datomic pro