Fork me on GitHub

So I have a cardinality many value (ref actually, but never mind that), and I want to perform a query taking a list as input giving me of all entities that have at least those values in its cardinality many attribute. My problem is that when binding the input values to a list, Datomic does an ‘or’ on the values meaning that if I provide [:a :b] as input it will also give me entities having only 😛. So can I have the query treat the input with ‘and’ semantics somehow?


Just to make it a bit more specific, I have a template entity which can contain some fields. I want to query for templates having a number of fields (though they can have more). The following query threats the inputs as ‘or’ where I would like ‘and’:

(d/q '[:find [?e ...]
            :in $ [?ids ...]
            [?e :template/field ?fields]
            [?fields :template.field/id ?ids]
      db [101 102])


if i transact 'bob likes cheese' and that fact already exists, is any transaction created that reaffirms this fact?


for example, if at tx1 bob tells me that he likes cheese, and then at tx2 alice tells me that bob likes cheese


i want some auditing capabilities that can not only tell me that bob told me he likes cheese at tx1 but also that alice reaffirmed that bob likes cheese at tx2


How do I find all the datoms transacted in a tx?

(d/q '[:find ?e ?a ?v ?tx ?added :in $ ?tx :where [?e ?a ?v ?tx ?added]] (rdb) 13194153065948)

datomic.impl.Exceptions$IllegalArgumentExceptionInfo: :db.error/insufficient-binding Insufficient binding of db clause: [?e ?a ?v ?tx ?added] would cause full scan


that obviously doesn't seem to work 🙂


I guess (first (-> conn d/log (d/tx-range 13194153065948 nil))) works


@pesterhazy: Yep, that’s how.


repl-based helpers for inspecting an entity's history ^^ @casperc


@danielstockton: If the datom being transacted is identical in the second transaction, it will result in an empty transaction generated. You could use transaction metadata to indicate that the transaction was issued by a different user (i.e. ‘alice said’ in transaction #2), however the transaction itself won’t be associated with the ‘bob likes cheese’ fact. If you need to track that information as well, you’ll want to model that directly (possibly also as transaction metadata). The reified transactions talk here: provides some more detail on using transaction metadata for provenance tracking.


@casperc: This is essentially the same question as was asked by @bhagany yesterday. Binding using the collection form (…) will run the query on each element of the collection and return the union of those results. To ask “and” questions your list of ids need to be provided in the same tuple, using the tuple binding form ( Each id will have its own individual datalog clause and the default behavior of multiple clauses in a query is “And”.


thanks @marshall, pretty much what i had thought


Is there any particular recommended docs for taking existing nested data and turning it into datoms? I’m currently doing it semi-manually — it’s fine, but it feels like there should be an easier way


in particular, I’m trying to put swagger API specs in datomic to query them


@lvh You can transact nested data as maps if it matches your schema. You have to create entity IDs for any map that isn't a component nested under another map.


Oh, cool! That'll definitely save me a bunch of time, I'll just go in and add appropriate namespaced keywords


@lvh reference docs at describe what forms of nesting are allowed


Looks like I will still have to mangle the data somewhat since e.g. paths/status codes aren’t very useful keys:


Yes. For cases like that, my usual pattern is: - every function returns a vector of valid transaction data - (vec (concat ...)) things together to build the full transaction


- create tempids in the "parent" and pass them to a "child constructor"


Also, some parameters/definitions are inline, some of them are defined at the top level (so e.g. you don’t have to repeat how your limit query parameter works each time)


Ah; I saw something earlier like {:widget/manufacturer [:manufacturer/e-mail “"]} ; are idents on insertion a Datascript-only feature, or would those work too?


I’m wading through a whole bunch of links and tutorials and they don’t always specify


I’m glad that I’m going in the right direction because I did in fact have:

(->> (concat (operations swagger))
                         (map (fn [m] (assoc m :swagger/api (:info swagger))))
in my code already 😄

Alex Miller (Clojure team)20:07:31

@stuartsierra: how about (into [] cat […]) instead of (vec (concat …))


@alexmiller: I have that defined as concatv 🙂

Alex Miller (Clojure team)20:07:38

:) I just enjoy putting things into my cat


Is there a recommended way for describing, uh, … overlays? I have a high-level default, which specific components lower in the hierarchy can override it seems the two options are: 1. propagate the default to the leaves 2. walk the graph until you find the default In particular, is there a standard way of writing e.g. fns that produce clauses that go in where, or do you need to concat in that case?


I don’t know if my description makes any sense


in my specific case, apis have operations, apis produce and consume mime types (e.g. application/json); individual operations can claim to produce e.g. application/xml in addition to json


also, are attributes generally spelled in the singular if they have cardinality many?