datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
fenton 2019-01-11T20:04:55.022300Z

Why do lookup-refs not work as in the following:

(def conn1 (make-db
              [{:name {:db/unique :db.unique/identity}}]
              [{:name "Bob"}]))
  (d/entity (d/db conn1) [:name "Bob"])

fenton 2019-01-11T20:05:18.022500Z

#error {:message "Lookup ref attribute should be marked as :db/unique: [:name \"Bob\"]", :data {:error :lookup-ref/unique, :entity-id [:name "Bob"]}}

fenton 2019-01-11T20:06:06.022800Z

(defn make-db [schema data]
  (let [conn (d/create-conn)]
    (d/transact! conn (concat schema data))
    conn))

2019-01-11T20:52:47.023500Z

@fenton - The schema should not be [{:name {...}}], just rather just {:name {...}}.

fenton 2019-01-11T20:53:31.024200Z

...and should be in the (/d/create-conn) as opposed to in a (d/transact! conn ... too...

2019-01-11T20:54:19.024800Z

Correct

2019-01-11T20:54:27.025200Z

Datascript does not have dynamic schema

fenton 2019-01-11T20:54:30.025500Z

got it, confused by docs on this...

2019-01-11T20:54:36.025700Z

It's fixed at db/conn value creation

fenton 2019-01-11T20:54:44.026100Z

okay cool, phew! 🙂

2019-01-11T20:55:46.027300Z

In Datomic, the schema is live, and you update it by submitting transactions, so it's entirely possible you were lead to believe you could do this by having seen some Datomic documentation/code

fenton 2019-01-11T20:59:36.027700Z

yeah...for sure... i guess datascript documentation is a bit fragmented...