This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-27
Channels
- # announcements (2)
- # babashka (24)
- # beginners (116)
- # cider (7)
- # cljsrn (6)
- # clojure (38)
- # clojure-bay-area (4)
- # clojure-europe (3)
- # clojure-losangeles (1)
- # clojure-norway (10)
- # clojurescript (171)
- # datomic (16)
- # honeysql (3)
- # improve-getting-started (1)
- # introduce-yourself (2)
- # java (12)
- # malli (5)
- # membrane (2)
- # pedestal (3)
- # shadow-cljs (79)
- # spacemacs (6)
- # xtdb (10)
I have read the docs about transactions, and there's still something I cant wrap my head around. How can I make changes to existing entities based on a query? Or, retract multiple entities based on a query? For example, "increase by 10% the salary of all employees whose in the company for more than 3 years", and "retract all the products which are out of stock"
I think you're looking for transaction functions? https://docs.datomic.com/cloud/transactions/transaction-data-reference.html#Transaction%20Functions
> in particular they allow the data added in a transaction to be derived from the current value of the database.
Hi, the example queries the entity and then execute an update on that entity, which is not atomic (assume a race condition where the query verifies that the salary hasn't been increased yet). How can I execute a transaction like
update employees
set salary = salary*1.1,
increased_at = getdate()
where experience > 3 and
increased_at < dateadd(year, -1, getdate());
it doesn't feel right to add dedicated functions for validations, I'm sure I'm missing something hereperhaps :db/cas
(https://docs.datomic.com/cloud/transactions/transaction-functions.html#db-cas) is what you're looking for?
I have looked into that, but it works for a single entity. I guess I can create multiple cas in a single tx, but it still means that I have to separate the query and the mutation
so you create a transaction function which queries the current employees’ salaries and experience and emits new salaries for those who have enough experience
how would you write it? I'm struggling with understand where does the tx start (datomic execution) and where my code does
for cloud, see https://docs.datomic.com/cloud/transactions/transaction-functions.html#creating
With a transaction function, the transactor executes the function with the current db value, and applies the tx-data returned from that function immediately after. The transactor is single threaded, so nothing else is applied to the database during this time. Basically, changes in transaction functions are atomic.
Hey, Is there a triggering mechanism similar to PostgreSQL? I want to invoke a webhook based on certain insertions.
It's called the Transactor Report Queue. Here's a short blog post about it https://blog.datomic.com/2013/10/the-transaction-report-queue.html, and googling around for projects using it I found https://github.com/ivarref/yoltq/blob/e848610ac341db31b804644a7dfaaf98389469d5/src/com/github/ivarref/yoltq/report_queue.clj#L39