-
Notifications
You must be signed in to change notification settings - Fork 2
05 progressive construction
At the beginning of this tutorial, I told you that add-ents
takes an potato db
as an argument:
(dc/add-ents {:schema potato-schema} {:post [{:count 1}]})
You may have wondered why don’t just pass in the potato-schema alone as the first argument, like this:
(dc/add-ents potato-schema {:post [{:count 1}]})
The reason the first argument to add-ents
is a potato db and not a potato
schema is so you can take the return value of add-ents
and pass it in as the
first argument to further calls to add-ents
:
(ns donut.datapotato-tutorial.05
(:require [donut.datapotato.core :as dc]))
(def potato-schema
{:user {:prefix :u}
:topic {:prefix :t
:relations {:owner-id [:user :id]}}})
(def potato-db
{:schema potato-schema})
(defn ex-01
[]
(let [potato-db-1 (dc/add-ents {:schema potato-schema} {:topic [{:count 1}]})
potato-db-2 (dc/add-ents potato-db-1 {:topic [{:count 1}
{:refs {:owner-id :hamburglar}}]})]
(dc/view potato-db-1)
(dc/view potato-db-2)))
(ex-01)
Additional calls to add-ents
are additive; they will never alter existing
ents, and will only add new ents. The first call, (dc/add-ents {:schema schema}
{:topic [{:count 1}]})
, produces a :topic
named :t0
referencing a :user
named :u0
:
That potato db is passed to the next call:
(dc/add-ents ent-db-1 {:topic [{:count 1}
{:refs {:owner-id :hamburglar}}]})
This creates two more topics:
![](../.gitbook/assets/progressive-1.png)
The default naming system picks up where it left off, giving the topic the names
:t1
and :t2
. :t1
references the existing user, :u0
, and :t2
references
a new user from the :refs
, :hamburglar
. When progressively generating an
ent-db, you can expect datapotato to behave as if all queries were passed as a
single query to a single call of add-ents
.
Everything you’ve learned up to this point has focused on generating an potato
db: you’ve learned a bit about how to use schemas and queries together to
concisely specify what ents to create. You’ve also learned how to customize the
relationships with the :refs
query option.
In the next couple sections, you’ll learn about how datapotato uses visitation to generate and insert business data.