Transact Data

Previously: you learned how to transact a schema into the database. This tutorial expects that you have a running REPL where you have already connected to the database "hello" and transacted the movie schema.

In the previous step, you learned how to transact schema data into the database. As was mentioned there, schema is just data, like any other data. So you will be unsurprised to learn that creating domain data is a very similar operation.

Once again, you will take advantage of the "transact" method of the Client library, which takes an active connection and a map of data. First, define your data, again storing it in a var first:

(def first-movies [{:movie/title "The Goonies"
                    :movie/genre "action/adventure"
                    :movie/release-year 1985}
                   {:movie/title "Commando"
                    :movie/genre "action/adventure"
                    :movie/release-year 1985}
                   {:movie/title "Repo Man"
                    :movie/genre "punk dystopia"
                    :movie/release-year 1984}])
=> #'user/first-movies

This is an example of the power of working directly with data – anything you might do to assemble a map of movie data could be substituted for the var first-movies. You can also pass that map to intermediate functions for cleaning/pre-processing before transacting.

Now that you have the movies ready to go, transact them into the database:

(d/transact conn {:tx-data first-movies})
  {:db-before {:database-id "58a47389-f1ab-4d81-85b6-715cecde9bac", 
               :t 1000, 
               :next-t 1001, 
               :history false}, 
   :db-after {:database-id "58a47389-f1ab-4d81-85b6-715cecde9bac", 
              :t 1001, 
              :next-t 1005, 
              :history false}, 
   :tx-data [ #datom[13194139534317 50 #inst "2017-02-15T19:28:52.270-00:00" 13194139534317 true] 
              #datom[17592186045422 63 "The Goonies" 13194139534317 true] 
              #datom[17592186045422 64 "action/adventure" 13194139534317 true] 
              #datom[17592186045422 65 1985 13194139534317 true] 
              #datom[17592186045423 63 "Commando" 13194139534317 true] 
              #datom[17592186045423 64 "action/adventure" 13194139534317 true] 
              #datom[17592186045423 65 1985 13194139534317 true] 
              #datom[17592186045424 63 "Repo Man" 13194139534317 true] 
              #datom[17592186045424 64 "punk dystopia" 13194139534317 true] 
              #datom[17592186045424 65 1984 13194139534317 true]], 
   :tempids {-9223301668109598138 17592186045422, -9223301668109598137 17592186045423, -9223301668109598136 17592186045424}}

Once again, the response you get back contains a :db-before and a :db-after. You can also see that it clearly lists out all the actual data that was added to the database in the :tx-data key.

So, now you have three movies in the database. Next you will learn how to query for them.