Fork me on GitHub
#datomic
<
2020-08-11
>
simongray13:08:01

How would you generally model something like inheritance of attributes from entities in an is_a relationship using datalog, e.g. modelling the class hierarchy found in OOP? The naïve solution would be to query for one entity’s parent and then fetch the parent’s attributes, repeating the process by looping through each entity’s parent entity and collecting any attributes found along the way until there is no parent. I was wondering if there is datalog pattern to do this in a single query - or if I need to run many successive queries using Clojure instead?

arohner13:08:44

I have a transaction that I want to commit iff an existing value hasn’t changed. i.e. [:db.cas eid ::foo bar bar] Is db.cas the best way to do that, or is there a better way?

dmarjenburgh13:08:20

@jake.shelby I have the same problem. It can't download com/datomic/java-io/0.1.19/java-io-0.1.19.pom from datomic-cloud. Problem occurs when trying to upgrade to com.datomic/ion {:mvn/version "0.9.48"}

marshall14:08:54

@jake.shelby @dmarjenburgh - We've released that missing dep; sorry about that and thanks for catching it

3
Jake Shelby16:08:43

Awesome thanks, working for me now:

~/ion-test-0.9.48                                                                                                                                                                                                             ⍉
▶ clojure
Downloading: com/datomic/java-io/0.1.19/java-io-0.1.19.pom from datomic-cloud
Downloading: com/datomic/java-io/0.1.19/java-io-0.1.19.jar from datomic-cloud
Clojure 1.10.1
user=>

Josh21:08:26

Hey there, I was testing what error I would get when I hit the https://docs.datomic.com/cloud/schema/schema-reference.html#:~:text=Strings%20are%20limited%20to%204096%20characters. (4096 chars) when I was surprised to find that transacting strings larger than 4096 characters does not result in an error. Is the Datomic cloud string size limit a soft limit? If so what other problems could I run into by storing strings larger than 4096 characters? Here’s a sample of the code I’m running

(ns user
  (:require
   [datomic.client.api :as d]))

(def db-name "test")

(def get-client
  "Return a shared client. Set datomic/ion/starter/config.edn resource
  before calling this function."
  #(d/client {:server-type :ion
              :region      "us-west-2"
              :system      "<system>"
              :endpoint    "<endpoint>"
              :proxy-port  8182}))

(defn get-conn
  "Get shared connection."
  []
  (d/connect (get-client) {:db-name db-name}))

(defn get-db
  "Returns current db value from shared connection."
  []
  (d/db (get-conn)))

(def schema
  [{:db/ident       :string
    :db/valueType   :db.type/string
    :db/cardinality :db.cardinality/one}])

(comment
  (d/create-database (get-client) {:db-name db-name})

  (d/transact (get-conn) {:tx-data schema})

  ;; test string limit
  (let [s         (apply str (repeat 10000 "a"))
        tx-report (d/transact (get-conn)
                              {:tx-data [{:db/id  "tempid"
                                          :string s}]})
        id        (get-in tx-report [:tempids "tempid"])
        stored-s  (:string (d/pull (get-db) '[*] id))]
    (println "s length in: " (count s))
    (println "s length out: " (count stored-s))
    (println "equal? " (= s stored-s)))
  ;; =>
  ;; s length in:  10000
  ;; s length out:  10000
  ;; equal?  true

Jake Shelby00:08:38

interesting … one thing I can think of that would still be limited is the index - are you still able to look up that entity using the value of that large string in a query?

Josh01:08:48

It seems so, this query returns the expected id

(d/q '[:find ?e
       :in $ ?s
       :where
       [?e :string ?s]]
       (get-db)
       s)