Fork me on GitHub
#datomic
<
2017-03-28
>
wei00:03:26

is there a version of db.fn/cas that is a nop instead of throwing an exception? my use case is for upserting entities, I’d like to add a uuid if the entity is new, but not change the existing uuid if an entity exists. looking for an elegant way to do this

zane00:03:04

That'd be pretty easy to write!

augustl09:03:09

without an execption, your entire tx would have to return nil in order to be no-op, so afaik you would need to write a db function that wraps your entire transaction

augustl09:03:58

i.e. [:myCas e a v [list of other facts]] so that if your fact e a v is a no-op you won't return the list of other facts either

augustl09:03:24

execptions for control flow in functional programs? 🙂

brett13:03:29

@marshall I figured out my problem. My :tx-data wasn’t in a vector, it was just a map. The error message wasn’t helpful :cognitect.anomalies/message “Server Error” It’d be nice if the spec caught this and returned a help message telling a vector was required.

marshall14:03:28

glad you figured it out. I’ll pass along the feedback about the error

timgilbert16:03:27

Hey, just noticed a typo on the datomic training videos page, under "part II": > Stu also covers the topics of Datomic databses, entities, and schema http://www.datomic.com/training.html

marshall17:03:20

@timgilbert Thanks - Ill fix it!

wei17:03:29

@augustl what if it just adds the same fact again if it exists? so more like upsert than cas

augustl18:03:39

Well, if you have N facts and one call to your own cas fn, if your own fn just returns nil it won't affect the other facts