Last active
October 5, 2019 18:10
-
-
Save dustingetz/d962e8923f66ad77d6c44626a82e2867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; CRUD UI | |
{identity ; pass through query params, decoded from URL | |
[{:hfnet/domains ; virtual attribute, resolves to a collection queried | |
[(:domain/ident {:hf/a :domains/edit}) ; :hf/a means hyperlink to a detail view, not specified here | |
{:domain/fiddle-database | |
[:database/uri]}]} | |
{(hf/new $domains) ; allocates a tempid for a new entity to be created in database $domains | |
[:db/id | |
:domain/ident | |
{:domain/fiddle-database | |
[:database/uri]} | |
{(hf/new $domains :domain/fiddle-database) ; this new entity is attached to its parent entity | |
[:db/id]}]}] | |
nil ; no query params | |
[{:hfnet/database-options-list ; picklist query | |
[:db/id | |
:database/uri]}]} | |
; Queries | |
{:hfnet/domains | |
[:in $domains | |
:find (pull $domains ?domain [:db/id]) | |
:where | |
[$domains ?domain :domain/ident]] | |
:hfnet/database-options-list | |
[:in $domains | |
:find (pull $domains ?e [:db/id]) | |
:where | |
[$domains ?e :database/uri ?uri]] | |
:hfnet/another-query ; just an example of how server code eval might work | |
(->> (d/datoms (d/db *conn*) :avet :domain/ident %) | |
(map :e) | |
(map (partial d/entity db)))} | |
; Schema | |
[{:db/ident :database/uri, | |
:db/valueType :db.type/uri, | |
:db/cardinality :db.cardinality/one, | |
:db/unique :db.unique/identity, | |
:db/doc "Datomic connection URI"} | |
{:db/ident :domain/fiddle-database, | |
:db/valueType :db.type/ref, | |
:db/cardinality :db.cardinality/one, | |
:db/doc "Database to store your fiddles. It is probably also assigned a name above, so your fiddles can query it, for example to generate site maps."} | |
{:db/ident :domain/ident, | |
:db/valueType :db.type/string, | |
:db/cardinality :db.cardinality/one, | |
:db/unique :db.unique/identity, | |
:db/doc "Hyperfiddle Cloud subdomain."} | |
{:db/ident :domain.database/name, | |
:db/valueType :db.type/string, | |
:db/cardinality :db.cardinality/one, | |
:db/doc "Name of this database in Datomic query :in clause"}] | |
; Validation | |
(s/def :domain/fiddle-database (s/keys :req [:database/uri])) | |
; View progressive enhancement | |
(defmethod hf/render #{:domain/fiddle-database} | |
[ctx props] | |
[hfui/select ctx | |
{:options :hfnet/database-options-list | |
:option-label (comp str :database/uri)}]) |
Author
dustingetz
commented
Oct 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment