Fork me on GitHub
#datascript
<
2017-01-26
>
linuss09:01:46

Hey guys, I'm trying to achieve something, but I can't seem to get it right. I'm writing a small application to store and edit forms using Om.Next and DatasScript. I'm running DataScript in the backend to store the forms. In the front-end, I'd like to display a list of form id's, and when one is clicked/selected, the corresponding form. My problem is that I can't seem to query both all form ID's and all the data from a single form using the same pull syntax. To get all the id's, I have to do something like (d/q '[:find ?id :where [_ :form/id ?id]) (d/db conn)), while to get all the fields from a single form, I have to do something like (d/pull (d/db conn) '[*] <eid>)

danielstockton09:01:24

@linuss I think you can use a pull expression (d/q '[:find (pull ?id [*]) :where [_ :form/id ?id]) (d/db conn))

linuss09:01:20

I'm afraid not: this results in the error "Expected number of lookup ref for entity id"

linuss09:01:42

I can do (d/q '[:find (pull ?e [:form/id]) :where [?e :form/id]] (d/db conn)) though

linuss09:01:40

But, by using this way of querying, I can't get all the fields from a single form

danielstockton09:01:59

(d/q '[:find (pull ?e [:form/id]) :in $ ?id :where [?e :form/id ?id] (d/db conn) <your_form_id>) ?

linuss10:01:04

Ah, yeah, that works! However, it doesn't really solve my problem. The thing is is that I'd like to use the queries of my Om.Next components directly in DataScript. This https://github.com/omcljs/om/wiki/DataScript-Integration-Tutorial page seems to indicate that that should be possible without too much trouble, but I can't seem to figure it out in my case

linuss10:01:36

In the solutions above, I keep having to supply a where clause for the single form

danielstockton10:01:07

Well, you aren't far away from the :app/counter parser read method in that tutorial...

danielstockton10:01:39

Just to warn you, om.next doesn't really support datascript in my opinion (you'll have to live without set-query! anyway, which is quite difficult in any serious application). This isn't as clear as it should be in the documentation.

danielstockton10:01:53

The queries don't translate 1to1 either, you'll always have some parser code like in that tutorial to transform basic pull patterns into a proper query.

linuss10:01:17

Hm, okay. If it doesn't, then is there another way to persistently store data that works better with Om.Next?

danielstockton10:01:24

Anyway, probably want to move back to #om for these kind of discussions...

linuss10:01:37

Haha, I tried that first, they sent me here 🙂

danielstockton10:01:53

The default store is just an (atom {}) and om does some normalization magic.

danielstockton10:01:58

Yeah, that was me that sent you here 😛

linuss10:01:05

Oh, haha, right