Fork me on GitHub
#datomic
<
2019-08-21
>
Lone Ranger12:08:36

I thought I remembered somewhere in the documentation that you can add a docstring to a transaction. Did I hallucinate that?

marshall13:08:57

Sure. You can put any attr (including :db/doc ) on a transaction entity

marshall13:08:07

{:db/id "datomic.tx" :db/doc "my transaction doc""}

Lone Ranger16:08:54

can you do that in list form too or just map form?

marshall16:08:30

[:db/add "datomic.tx" :db/doc "my transaction data"]

Lone Ranger00:08:27

aha, ty sir!!!

ivana13:08:25

Hello! get-else works with cardinality-one attributes only? how can I chek if my cardinality-many attribute has at least one value or not, without disappearing rows with this attr is not setted?

ivana13:08:26

trick with (or [?o :order/my-cardinality-many-attribute ?x] [?o :db/id ?x])works, but it made multiple lines on many values in attribute

marshall14:08:38

@ivana you could use the missing? predicate

marshall14:08:51

Amd a similar or trick

ivana14:08:14

yes, but how can I get all missing and non-missing attr rows just with a chek of missing and without a multiplication lines?

benoit14:08:31

@ivana It's not clear what query you're trying to write. Your or clause above will return all the entities in your database because of [?o :db/id ?x], is it really what you want?

ivana14:08:43

I want simply to check (!) if this entity have at least one value in its card-many attr or not - with the same entity lines as they are.

ivana14:08:53

F.e. I have 2 entities, one with 10 values in many attr, and one with 0. I want 2 rows with bollean flag

ivana14:08:57

Not 11 lines, not 1 line. Just 2 - as a real amount of my entity

benoit14:08:24

There might be a simpler approach but something like this could work:

[:find ?o ?has-many-attr
         :where
         [?o :other/attr]
         (or (and [?o :order/my-cardinality-many-attribute]
                  [(ground true) ?has-many-attr])
             (and [(missing? $ ?o :order/my-cardinality-many-attribute)]
                  [(ground false) ?has-many-attr]))]

👍 4
ivana14:08:23

thanks, I'l try it

ivana14:08:55

for the first impression it is exactly what I need, thanks alot! I'l play with it in a real queries

deadghost15:08:53

Datomic does not accept nil attribute values. If I have an entity

{:foo/id 101
 :foo/code :FOO
 :foo/type "bar"}
and I want to update it like so:
(d/transact conn [{:foo/id 101
                   :foo/code :LOL
                   :foo/type nil}])
it will throw an Exception. If I exclude the nil attribute:
(d/transact conn [{:foo/id 101
                   :foo/code :LOL}])
:foo/type will remain "bar". :foo/type seems like it needs to be explicitly retracted. I'm currently using the method detailed in https://matthewboston.com/blog/setting-null-values-in-datomic/ to do nil updates. It's a red flag that I need to handroll something to do this type of update and it suggests I am not doing things in the correct way. Another approach would be a full retract and insert but I get the feeling there are unexpected behaviors I have not thought about with that approach. How are you all approaching this?

ghadi15:08:13

You do not need to reassert the whole entity - just retract the part that is no longer true

4
ghadi15:08:56

Without even reading that article it is probably misconceived

eoliphant17:08:09

yeah it I think misses the point. entities are sets of arbitrarily related attributes, not tables, this takes some getting used to but it’s far more powerful once you get the hang of it. And the example of “So what if we need to set a value to null?“, isn’t really. This

(datomic/q '[:find ?id ?firstname ?lastname
             :in $
             :where
             [?id :user/firstname ?firstname]
             [?id :user/lastname ?lastname]]
           (datomic/db conn))
should be more like this:
(datomic/q '[:find ?id (pull ?e [:user/firstname :user/lastname])
             :in $ 
             :where
             [?id :user/firstname]
             ; - or perhaps -
             [?id :user/id]
           ]
           (datomic/db conn))
No need to ‘simulate null’, and you keep the clean semantics of simply retracting :user/lastname. Also ‘matching for values’ is less efficient (though probably not a big deal in this trivial case), as the engine has to do work to match each ‘clause’. to the extent possible, let your where do the selecting, then just pull what you need in terms of values

eoliphant17:08:37

also, the edit-or-create-user-txnexample seems to conflate empty strings with null/nil. Now that may be desired behavior in certain circumstances, but “” is not nil/null/“not present”, even in a traditional say relational db. Also, figuring out retracts is pretty trivial. a set/difference on the keys of the incoming update and an existing entity will give you that directly. “” as nil, if necessary can be tacked on with filter prior to the diff

m0smith22:08:42

Calling cast/even from wihtin CIDE results in a StackOverflowError

m0smith22:08:04

Execution error (StackOverflowError) at cider.nrepl.middleware.out/print-stream$fn (out.clj:93). Has anyone else seen this?

andrew.sinclair23:08:24

Is there a function in the Peer api that allows a user to programmatically determine the transactor’s port?

andrew.sinclair23:08:52

We are using the map uri, with a cassandra callback, so port is not present in the uri.

m0smith23:08:21

(ns bug-demo (:require [datomic.ion.cast :as cast])) (cast/initialize-redirect "/tmp/hamster") (cast/event {:msg "ShouldNotCauseAStackOverflowErrorInCider"})