datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
tatut 2020-12-10T07:48:25.104400Z

In datomic cloud is it possible to use with-db in transaction function? It requires a connection but the tx fn is only passed a db value.

onetom 2020-12-11T06:40:54.113400Z

maybe you can call datomic.client.api/with on that db value you receive in the transaction function? I would be curious to know whether it works or not.

kenny 2020-12-15T16:59:19.120500Z

fyi, I just ran into this too 🙂 Created a question on ask.datomic https://ask.datomic.com/index.php/557/can-you-use-d-with-inside-a-cloud-transaction-function.

tvaughan 2020-12-10T19:23:31.107100Z

Is it possible to use an attribute predicate on a ref? If so, what would be passed to the predicate function? Our desire is to limit the reference based on a value of an attribute in the referenced entity. I think the answer is no, but we're not reading the documentation the same. We'd really appreciate a clarification, thanks

favila 2020-12-10T20:04:54.107200Z

You will get an entity ID and no database, so no, you cannot use an attr predicate for this

favila 2020-12-10T20:05:22.107400Z

you need :db/ensure to enforce something like this safely and atomically

tvaughan 2020-12-10T20:06:09.107600Z

Great. Thank you @favila

chicwayne 2020-12-10T20:40:56.107800Z

@favila, what if the entity ID returned consists of a single attribute/value pair with :db.unique/value, i.e. the related schema was purposely designed to have only one attribute with a unique value, would that change your answer in any way?

favila 2020-12-10T20:42:49.108Z

I’m not sure what you mean? entity id returned from what?

chicwayne 2020-12-10T20:44:39.108200Z

Maybe I'm misinterpreting what you meant by > You will get an entity ID

chicwayne 2020-12-10T20:46:19.108400Z

Can you elaborate?

chicwayne 2020-12-10T20:47:57.108600Z

I took it as the answer to @tvaughan question below. > If so, what would be passed to the predicate function?

favila 2020-12-10T20:50:19.108800Z

The contract for attribute predicates is (fn [v] ) => true (to allow) | anything-else (to reject), where v is the value that will be asserted/retracted. For refs, that value is a long representing an entity id

favila 2020-12-10T20:52:13.109Z

attribute predicates must decide to accept or reject based only on the value. without a database it can’t learn anything about what is asserted for the entity

chicwayne 2020-12-10T20:58:18.109200Z

Thanks @favila.