mozilla / mentat

UNMAINTAINED A persistent, relational store inspired by Datomic and DataScript.
https://mozilla.github.io/mentat/
Apache License 2.0
1.65k stars 115 forks source link

Handle :db/ident and friends in cache application phase #578

Open rnewman opened 6 years ago

rnewman commented 6 years ago

Thanks to Schema, we know a bunch of things during algebrizing: a query like

[:find ?x :where [?x :db/ident :db/valueType]]

which currently translates to

SELECT DISTINCT `datoms00`.e AS `?x` FROM `datoms` AS `datoms00` WHERE `datoms00`.a = 1 AND `datoms00`.v = $v0
  Bindings:
    $v0 = Text(":db/valueType")

can instead be answered directly. So can

[:find ?valueType
 :in ?attr
 :where
 [?attr :db/valueType ?valueType]]

— that's also known via the schema without running SQL.

This makes it reasonable for dynamic callers to do most of their work through the query interface, rather than needing specialized access to Schema and the cache.