Fork me on GitHub
#datascript
<
2016-05-12
>
vinnyataide03:05:12

nothing, carry on

vinnyataide03:05:28

learning datomic right now 😛

fasiha03:05:23

Is … is this magic?: :find ?composition-entity (distinct ?radical) ?author-name does what I want: returns a seq of [id [list of radicals] author-name]

fasiha03:05:20

I feel like a noob again wondering how for loops work 🙃, because before, with just :find ?composition-entity ?radical ?author-name, DataScript returned a big fragmented set of [id single-radical author-name] vectors, and I thought I'd have to do a group-by outside the query. But throw in a distinct in there (I'm a big boy now, reading datomic docs) and I feel like the computer read my mind and gave me exactly what I wanted. Spooky.

fasiha07:05:52

How do I use transactor functions? I have a simple function that I want to call in a transaction, that for now just adds a new author with a given name: (defn my-trans-fn [db & [author-name]] [:db/add -1 :author/name (or author-name "test-1")]). I've tested this function in a non-transactional way like so: (d/transact! conn [(my-trans-fn nil "foo")]) and it inserts a new entity as expected. Now, I'd like to call this inside a proper transaction, but (d/transact! conn [[:db.fn/call my-trans-fn "bar"]]) doesn't seem to be valid?

fasiha07:05:24

Do I need to "load" the transactor function into the db, like with Datomic? Do I need to quote my-trans-fn somehow?

fasiha07:05:49

The error I get: Bad entity type at :db.fn/call, expected map or vector

fasiha07:05:03

And similar if I leave out a pair of brackets around that :db.fn/call

fasiha07:05:00

Holy cow, I magically landed on https://vimeo.com/114688970 at the right minute when Nikita started typing a transactor function! At 45:50 I see my problem: my function's returned vector needed another level of nesting, hmm