qpdb / mentat

A persistent, relational store inspired by Datomic and DataScript.
https://mentat.rs/
Apache License 2.0
52 stars 2 forks source link

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

Open gburd opened 4 years ago

gburd commented 4 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.