Fork me on GitHub
#crux
<
2020-05-17
>
mmer14:05:43

Another question I have is about queries. In Sparql you can do an "s p o" However `(crux/q (crux/db db) '{:find [s p o] :where [[s p o]]})` Doe not seem to work with crux? Any ideas? Linked to this is the fact that I want to query with an argument being passed in the 'o' position.

refset14:05:01

Crux' indexes don't currently support variables in the attribute positions of triple clauses. The main justification being that in the vast majority of use-cases all attributes will be known ahead of time, but the benefits are significant in simplifying the query algorithm and minimising disk space. Therefore for certain inference-heavy domain use-cases Crux is probably not appropriate as things stand today. A workaround for doing ad-hoc exploration of data with the current functionality is to look at attribute-stats and generate queries based on that (though they may be slow!) We may well (optionally) support variable attributes in a future release but we have no immediate plans.

refset14:05:26

I hope that makes sense, but I would be keen to hear about your use-case anyway 🙂

Eric Ihli14:05:42

^ This is something I also tried once I started playing around with code, after having gone through the tutorials. I scanned the docs to confirm it wasn't supposed to work and never saw anything. Just another anecdotal data point for what newcomers experience.

👀 1
mmer14:05:24

Being able to get the attribute names associated with the data allows for creating table heading in UI and reports etc, without having to know them in advance.

mmer14:05:01

Linked with this I would like to know how to optionally return a value if it exists but nothing if it does not

mmer14:05:50

Or set a default when it does not exist

Eric Ihli16:05:02

Can getting the attribute names without knowing them in advance be done some other way? If you know the type of thing that you you want to report on, then you must know one of it's attributes. Since there are no "tables" you can't really use database introspection to dynamically get the names of columns of a table. It's not like you have a "user" table and a "cars" table, each with different columns. Each object that you model is defined by its attributes. So if you want to report on something, you must know at least the attribute that identifies what "type" it is. You could give each entity a "type" attribute. Then you don't need to know the other attributes ahead of time. You could write some shared reporting code that given a type would get all entities that have :data/type :user or :data/type :car and then generate column headers for your UI based on the set of attributes of each collection

Eric Ihli16:05:54

And {:find [s p o] :where [[s p o]]} would just return everything, yeah? Every entity must have a crux.db/id key, so that's almost the same thing as {:find [s] :where [[s :crux.db/id o]] :full-results? true} and then just getting the entity/attribute/value triplets from each result.

dvingo17:05:14

Vars in attribute position not being supported is mentioned here, but it isn't very prominent https://opencrux.com/docs#queries_datascript_differences

🙏 1
mmer19:05:29

Thanks you all

1