An interactive web app for learning Datomic Datalog.
The app serves a series of exercises. Each exercise includes an editable Datalog query that runs against a Datomic database populated with Pokemon data.
- http-kit - HTTP server
- Compojure - Routing
- Hiccup - HTML rendering from Clojure data structures
- Datomic - Database
- Datastar - Frontend reactivity
- Code Highlighter - Editable code blocks with syntax highlighting
Start the server:
clojure -X:runRun tests:
clojure -X:testBuild an uberjar:
clojure -T:build uberChapters are EDN files in resources/chapters/.
-
Create
resources/chapters/<slug>.edn. The slug becomes the URL (/<slug>):{:nav-title "My chapter" :content [:div [:h1 "My chapter"] [:p "Some text."] [:ui/runnable "pokemon" [:find ?name :where [?e :pokemon/name ?name]]] [:ui/try-tip [:p "Change the query above."]]]} -
Add the slug to
resources/chapters/chapters.edn. Its position sets the order in the nav. Files not listed there are not published.
:content is plain Hiccup. Four extra tags call functions:
| Tag | Renders |
|---|---|
[:ui/runnable dataset query & inputs] |
An editable query with Run and Reset buttons. Any inputs after the query are passed to its :in clause in order, after $. A vector of rules is the input for %. (as-of "Generation V"), (since "Generation V") and (history) are views of the database, see the Time travel chapter. |
[:ui/code query] |
A read-only code block from data, pretty-printed. |
[:ui/code lang string] |
A read-only code block from a string, shown as written. |
[:ui/try-tip hiccup] |
A highlighted "TRY" box. |
[:ui/value dataset query] |
The result of a scalar query, like [:find (count ?e) . :where [?e :pokemon/name _]], shown as text. Use it for any number in the text that comes from the data, so the text can't go stale when the data changes. |
In development the files are re-read on every request, so refreshing the browser shows your edits. clojure -X:test checks that every chapter loads and renders, and that every runnable query is allowed and executes.
fly deploy