3 Differences from Datomic
Thom edited this page 2018-08-22 19:38:37 -07:00

fulltext

The fulltext function in Datomish supports sets of attributes or the special keyword :any.

To do a fulltext search that matches page titles or excerpts:

[(fulltext $ #{:page/title :page/excerpt} "something") [[?page]]]

To match any attribute at all:

[(fulltext $ :any "something") [[?entity]]]

Query inputs, ordering, and limits

<q supports binding values, specifying ordering conditions, and limiting the number of returned results.

Aggregates can be used as an ordering clause: for an aggregate expression like (max ?date), the ordering column is _max_date. In ClojureScript this is a keyword (:_max_date); in JS it's a string.

ClojureScript:

(d/<q
  db
  '[:find ?page ?url ?title ?excerpt
    :in $ ?time
    :where
    [?save :save/page ?page]
    [?save :save/savedAt ?instant]
    [(> ?instant ?time)]
    [?page :page/url ?url]
    [(get-else $ ?save :save/title "") ?title]
    [(get-else $ ?save :save/excerpt "") ?excerpt]]
  {:limit limit
   :inputs {:time 1234567890}
   :order-by [[:instant :desc]]})

JS:

await db.q(
    `[:find ?url (max ?date)
      :in $
      :where
      [?page :page/url ?url]
      [?page :page/visitedAt ?date]]`,
    {"limit": 2, "order-by": [["_max_date", "desc"]]});

Simple schema

Datomish's JS API exposes a simple schema interface through db.ensureSchema. This accepts input with simplified string keys and values, like this:

{
  "name": "pages",
  "attributes": [
    {"name":         "page/url",
     "type":         "string",
     "cardinality":  "one",
     "unique":       "identity",
     "doc":          "A page's URL."},
    {"name":         "page/title",
     "type":         "string",
     "cardinality":  "one",
     "fulltext":     true,
     "doc":          "A page's title."},
    {"name":         "page/content",
     "type":         "string",
     "cardinality":  "one",
     "fulltext":     true,
     "doc":          "A snapshot of the page's content. Should be plain text."},
  ]
}

Lookup Refs

There's a small syntactic difference with how lookup refs are indicated in EDN. Where in Datomic they will be indicated as [:namespace/attr value], in Mentat they are represented as (lookup-ref :namespace/attr value).

This may be fixed in a future version of Mentat, see issue https://github.com/mozilla/mentat/issues/392.