Installed function return value as attribute value

Hi,

New Datomic user here. I’ve searched but can’t find a definitive answer to this one. We have installed a simple Java function that simply checks that the 3 items passed in are equivalent and returns a boolean. As a test, we would like to have the result of this function stored as a value for an attribute of an entity as we are storing it. This is essentially a case of due diligence/proof-of-concept for us.

Here’s the function source (as simple as it is):
String source = “return (v1.equals(v2) && v2.equals(v3));”

This is installed and works great with a simple invoke() call.

However, what we wanted to try is something like this:

[ [ :db/add "test-id" :test/bool [ :test/func 1 1 1 ] ] ]
// or:
[ [ :db/add "test-id" :test/bool ( :test/func 1 1 1 ) ] ]
// or even:
[ { :db/id "test-id" :test/bool [ :test/func 1 1 1 ] } ]

(we have tried several different syntaxes all with the same (or similar) result:

:db.error/wrong-type-for-attribute Value [:test/func, 1, 1, 1] is not a valid :bool for attribute :test/bool

I’m assuming we are doing something very wrong … or this is not something that is possible. Are we tilting at windmills?

TIA.

You can’t call a function inside another transaction statement but you can call your function as a separate statement. The result of function is treated then as a statement to be executed in the same trasansaction.

(d/transact conn {
             :tx-data [
[:test/func 1 1 1]
]})

whereas your function :test/func should return a list: [ :db/add "test-id" :test/bool <result of comparing> ]

So it looks as replacing of [:test/func 1 1 1] by the result returned from :test/func

Thanks @nikolayandr . This confirms my suspicion that any function we install that is to used in a transaction is required to be a transaction function as defined in the Datomic docs. It wasn’t clear to me whether this was an obligation or not. This clarifies things for us.

Thx again.

(Off to find more windmills. :slight_smile: )