0

i'm full my db with this

(def fixtures [
  [:db/add 0 :system/group :all]

  {
  :product/name "Donut Keurig"
  :product/category "snack"
  :product/brand "Grocery&GourmetFood"
  :product/height "2.1"
  :product/width "3.2"
  :product/notes "The Original Donut Shop Keurig Single-Serve K-Cup Pods, Regular Medium Roast Coffee"
  }

  {
  :product/name "Ferrero Rocher Hazelnut Chocolates"
  :product/category "Candy"
  :product/brand "Candy&Chocolate"
  :product/height "3.4"
  :product/width "2"
  :product/notes "A tempting combination of smooth chocolaty cream surroiunding a whole hazelnut within a delciate, crisp wafer all enveloped in milk chocolate and finely chopped hazelnuts"
  }
  ])

(def conn (d/transact! conn u/fixtures))

but show me this error:

Uncaught Error: Assert failed: (conn? conn) at Function.datascript.core.transact_BANG_.cljs$core$IFn$_invoke$arity$3

Besides i want to show the result of the db like this:

(defmulti read om/dispatch)

(defmethod read :product/name
  [{:keys [state query]} _ _]
  {:value (d/q '[:find [(pull ?e ?selector) ...]
                 :in $ ?selector
                 :where [?e :product/name]]
            (d/db state) query)})

(defui product-view
  static om/IQuery
  (query [this] [{:product/name [:db/id :product/name]}])
  Object
    (render [this]
      (let [{:keys [product/name] :as entity}
            (get-in (om/props this) [:product/name ""])]
        (dom/tr nil
          (dom/td nil name)))))

(defui products-view
  static om/IQuery
  (query [this] [{:product/name [:db/id :product/name]}])
  Object
    (render [this]
      (dom/table #js {:className "table table-bordered"}
        (dom/thead nil
          (dom/tr #js {:className "row-garden"}
            (dom/th nil "Product Name")
            (dom/th nil "Category")
            (dom/th nil "Brand")
            (dom/th nil "Height")
            (dom/th nil "Width")
            (dom/th nil "Notes")))
        (dom/tbody
          (let [{:keys [product/name] :as entity}
            (get-in (om/props this) [:product/name ""])]
            (println conn)
             (dom/tr nil
              (dom/td nil name)))))))

(om/add-root!
  reconciler
  products-view
  (gdom/getElement "table-products"))

But doesn't work :(

Thanks!

2 Answers2

1

Author of DataScript here.

First, transact! returns transaction report, not a connection. It mutates content of conn passed in as an argument:

(def conn (d/create-conn schema))
...
(d/transact! conn u/fixtures)

Second, you can’t use dynamically-bound pull pattern in query. Use normal pull API:

(let [db     (d/db state)
      datoms (d/datoms db :aevt :product/name)
      eids   (map :e datoms)]
  (d/pull-many db query eids))

I can’t help you with Om.Next part, unfortunately. If there are any errors, I wouldn’t know.

Hope it helps.

Niki Tonsky
  • 1,327
  • 11
  • 19
0

It looks like you are not initializing the Datascript connection correctly. Please see the DataScript example solution in this question. Your code should follow this model:

(ns clj.core
  (:require [tupelo.core :as t] 
            [datascript.core :as d]
            [clojure.set :as set] ))
(t/refer-tupelo)

(def data
  [ {:type :x :local/id 1,   :obs/A "11",    :obs/value 2.0,    :obs/color "yellow"}
    {:type :x :local/id 2,   :obs/A "12",    :obs/value 4.0,    :obs/color "blue"}
    {:type :x :local/id 3,   :obs/A "13",    :obs/value 3.0,    :obs/color "green"}
    {:type :x :local/id 3,   :obs/A "15",    :obs/value 7.0,    :obs/color "red"} 

    {:type :y :local/id 2,   :obs/A "11",    :obs/value 7.0,    :obs/shape "square"}
    {:type :y :local/id 2,   :obs/A "13",    :obs/value 4.0,    :obs/shape "circle"}
    {:type :y :local/id 6,   :obs/A "15",    :obs/value 3.0,    :obs/shape "triangle"} ] )

(def conn (d/create-conn {}))
(d/transact! conn data)
 .....
Community
  • 1
  • 1
Alan Thompson
  • 29,276
  • 6
  • 41
  • 48