-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repl-session code to show how Datomic entity API works
- Loading branch information
Showing
2 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,23 +14,6 @@ | |
(db/transact [[:db/retractEntity 17592186045468]])) | ||
(user/conn) | ||
|
||
(db/transact [{:user/email "[email protected]" | ||
:user/handle "laurence.chen" | ||
:user/name "Laurence"}]) | ||
|
||
(db/q | ||
'[:find | ||
[(pull ?e [*]) ...] | ||
:where | ||
[?e :user/email]] | ||
(db/db)) | ||
|
||
(def session-eid 17592186045438) | ||
|
||
(db/transact [{:db/id session-eid | ||
:session/participants 17592186045458}]) | ||
|
||
(first (:session/participants (db/entity session-eid))) | ||
;; Test transact participants | ||
|
||
(def req {:identity {:user/email "ddd"} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(ns repl-sessions.init-db | ||
"Prepare some testing data to transact into db for testing" | ||
(:require | ||
[co.gaiwan.compass.db :as db] | ||
[datomic.api :as d])) | ||
|
||
;; Utility | ||
|
||
(defn query-session [] | ||
(db/q | ||
'[:find | ||
[(pull ?e [*]) ...] | ||
:where | ||
[?e :session/title "Opening Keynote (TBD)"]] | ||
(db/db))) | ||
|
||
(defn participants [] | ||
(db/q | ||
'[:find | ||
[(pull ?e [*]) ...] | ||
:where | ||
[?e :user/email]] | ||
(db/db))) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Test Setup Begin | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
;; write participants into the database | ||
(db/transact [{:user/email "[email protected]" | ||
:user/handle "laurence.chen" | ||
:user/name "Laurence"} | ||
{:user/email "[email protected]" | ||
:user/handle "sunnyplexus" | ||
:user/name "Arne"}]) | ||
|
||
;; get the session eid | ||
(def session-eid (:db/id (first (query-session)))) | ||
|
||
;; get the eids of participants | ||
(def p-eids (mapv :db/id (participants))) | ||
|
||
(def tx-data (mapv (fn [x] {:db/id session-eid | ||
:session/participants x}) p-eids)) | ||
|
||
;; relate the pariticipants to the session | ||
(db/transact tx-data) | ||
|
||
;; Simulate the entity access in the frontend | ||
(def session-entity (db/entity session-eid)) | ||
|
||
;; Get the first participant's name from the session entity | ||
(-> session-entity | ||
:session/participants | ||
first | ||
:user/name) | ||
|
||
;; Demonstrate the behaviors of Datomic Entity | ||
|
||
(type session-entity) | ||
;; => co.gaiwan.compass.db.munged-entity | ||
|
||
(type (-> session-entity | ||
:session/participants | ||
first)) | ||
;; => co.gaiwan.compass.db.munged-entity |