Last active
February 12, 2016 18:20
-
-
Save grzm/3d17f353224ce329855f 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
(ns om-tutorial.X-Query-Exercises | |
(:require-macros | |
[cljs.test :refer [is]]) | |
(:require [om.next :as om] | |
[om-tutorial.queries.query-editing :as qe] | |
[devcards.core :as dc :refer-macros [defcard defcard-doc deftest]])) | |
(def bird-db | |
{:birds/by-id {1 {:bird/id 1 :bird/name "Robin"} | |
2 {:bird/id 2 :bird/name "Blackbird"} | |
3 {:bird/id 3 :bird/name "Big Bird"}} | |
:birds [[:birds/by-id 1] | |
[:birds/by-id 2] | |
[:birds/by-id 3]] | |
:observations [{:bird [:birds/by-id 2] | |
:observation/at #inst "2016-02-10T19:00-05:00"} | |
{:bird [:birds/by-id 1] | |
:observation/at #inst "2016-02-10T18:00-05:00"}]}) | |
(def desired-ui-data | |
{:birds [{:bird/id 1 :bird/name "Robin"} | |
{:bird/id 2 :bird/name "Blackbird"} | |
{:bird/id 3 :bird/name "Big Bird"}] | |
:observations [{:bird {:bird/id 2 :bird/name "Blackbird"} | |
:observation/at #inst "2016-02-10T19:00-05:00"} | |
{:bird {:bird/id 1 :bird/name "Robin"} | |
:observation/at #inst "2016-02-10T18:00-05:00"}]}) | |
(defcard bird-db-example | |
" | |
Query editor for bird-db | |
" | |
qe/query-editor | |
{:query "[{:birds [:bird/id :bird/name]} | |
{:observations [{:bird [:bird/id :bird/name]} | |
:observation/at]}]" | |
:query-result {} | |
;; observed results | |
;; {:birds [{:bird/id 1 :bird/name "Robin"} | |
;; {:bird/id 2 :bird/name "Blackbird"} | |
;; {:bird/id 3 :bird/name "Big Bird"}] | |
;; :observations [{} {}]} | |
:db bird-db | |
:id "query-example-1"} | |
{:inspect-data false}) | |
(deftest bird-db-query-test | |
"Trying to figure out normalization with augmented/composite components" | |
(is (= {:birds [{:bird/id 1 :bird/name "Robin"} | |
{:bird/id 2 :bird/name "Blackbird"} | |
{:bird/id 3 :bird/name "Big Bird"}] | |
:observations [{:bird {:bird/id 2 :bird/name "Blackbird"} | |
:observation/at #inst "2016-02-10T19:00-05:00"} | |
{:bird {:bird/id 1 :bird/name "Robin"} | |
:observation/at #inst "2016-02-10T18:00-05:00"}]} | |
(om/db->tree [{:birds [:bird/id :bird/name]} | |
{:observations [{:bird [:bird/id :bird/name]} :observation/at]}] | |
bird-db bird-db)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment