Fork me on GitHub
#asami
<
2021-06-28
>
Mattias20:06:53

I’m interested in trying Asami and would be interested in knowing some typical setups. Haven’t worked with in-memory only databases much, so… do you import from disk/DB (or wherever) on start and go from there, or what is a typical usecase? 🙂

quoll20:06:07

At work we load from a whole lot of JSON or EDN

quoll20:06:17

For in-memory stores, when I’m saving a lot of data, I’ll do an export-data to a file, and import-data when I restart

Mattias20:06:00

Thanks, great 🙂 So, haven’t looked but is there built-in import/export functionality?

Mattias20:06:23

Btw, read most of you background articles. Fascinating and a great read. Thanks for sharing so much, really interesting! 😄

quoll20:06:31

thank you

Mattias20:06:00

For loading from JSON, XML or other messy files, that would be regular parsing and a lot of transacts, right?

quoll20:06:19

I haven’t tried from XML, but so long as you have a seq of objects it’s fine

quoll20:06:47

You can insert statements (triples) easily enough, but we tend to not do that. Instead we go with objects. These are deconstructed into triples, and they all go in together in a transaction

quoll20:06:31

Here’s a copy paste from a session I was using on Friday…

quoll20:06:07

(require '[asami.core :as d]) 
(require '[cheshire.core :as json]) 
(require '[ :as io]) 
(def bundle-dir (io/file "/data/bundle")) 
(def bundles (map (comp json/parse-stream io/reader) (.listFiles bundle-dir))) 
(def tx2 @(d/transact conn {:tx-data bundles})) 

quoll20:06:42

That was Clojure (not ClojureScript) of course

quoll20:06:22

each file in the bundle directory held a single map object, and it was several MB of data

quoll21:06:51

To load triples, I tend to just write them as edn, and load them that way. e.g. triples.edn

[[#a/n[123] :type :person]
 [#a/n[123] :first-name "Betty"]
 [#a/n[123] :last-name "Rubble"]
 [#a/n[123] :spouse #a/n[124]]
 [#a/n[123] :child #a/n[125]]
 [#a/n[124] :type :person]
 [#a/n[124] :first-name "Barney"]
 [#a/n[124] :last-name "Rubble"]
 [#a/n[124] :spouse #a/n[123]]
 [#a/n[124] :child #a/n[125]]
 [#a/n[125] :type :person]
 [#a/n[125] :first-name "Bam-Bam"]
 [#a/n[125] :last-name "Rubble"]]
(require '[clojure.edn :as edn])
(def data (edn/read-string (slurp "triples.edn")))
(def tx @(d/transact conn {:tx-triples data})) 

Mattias21:06:49

Fantastic, thank you so much. This helps me get going without (as much) stumbling around first… 👍😊

quoll21:06:08

Maybe I should write a wiki page with the above

Mattias21:06:08

Please do. 🙂