datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
Saurabh Sharan 2020-08-11T04:46:32.157900Z

A web-based clojurescript app that can listen for new changes in the database and update the UI without refreshing the page. (Similar to subscription queries in GraphQL)

Saurabh Sharan 2020-08-11T04:47:03.158100Z

@favila - interesting, do you know why that is? doesn't tx-range only give you previous transactions, and not new transactions as they occur?

favila 2020-08-11T12:00:09.160400Z

If you call tx-range repeatedly, you’re going to get new transactions as they occur (within your polling interval)

favila 2020-08-11T12:01:38.162400Z

Txrange t5000 to nil; that gives you up to say t5050, then call again txrange t5051 to nil, etc

simongray 2020-08-11T13:05:01.168800Z

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?

Joe Lane 2020-08-11T13:25:36.169400Z

@simongray https://github.com/cognitect-labs/onto may be a good reference for you.

simongray 2020-08-11T13:31:45.169600Z

Thanks!

arohner 2020-08-11T13:42:44.170800Z

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?

2020-08-11T13:50:20.171900Z

@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"}

marshall 2020-08-11T14:29:54.172600Z

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

2
Joe Lane 2020-08-11T14:30:51.172800Z

Hi @saurabh.sharan1, I found this talk very influential in how I talk about event driven systems. https://www.youtube.com/watch?v=STKCRSUsyP0 It should get you thinking about the different types of problems / solutions. I would actually follow @favila’s recommendation in the earlier thread, if you do, you could implement the "Event Notification" type of Event Driven Architecture. When you are notified of an event changing a given entity that you are subscribed to, re-query the information at that new T so that you are always querying against a consistent T, vs trying to process the deltas right out of the database and building an interpreter in the browser.

Jake Shelby 2020-08-11T16:46:43.173100Z

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=>

marshall 2020-08-11T16:46:57.173400Z

👍

Josh 2020-08-11T21:25:26.174Z

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