Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic map keys #35

Open
lilactown opened this issue Jan 30, 2024 · 1 comment
Open

Dynamic map keys #35

lilactown opened this issue Jan 30, 2024 · 1 comment

Comments

@lilactown
Copy link
Owner

Support something like

(p/pull
  (p/db
    [{:classroom/id "c1" :school [:school/id 1]}
     {:classroom/id "c2" :school [:school/id 1]}
     {:classroom/id "c3" :school [:school/id 2]}
     
     {:school/id 1
      :allocations {[:classroom/id "c1"] [[:course/id 1] [:course/id 2]]
                    [:classroom/id "c2"] [[:course/id 1]]}}
     {:school/id 2
      :allocations {[:classroom/id "c3"] [[:course/id 1] [:course/id 3]]}}

     {:course/id 1 :course/name "A"}
     {:course/id 2 :course/name "B"}
     {:course/id 3 :course/name "C"}])

  [{[:school/id 1] [{:allocations [{???? [:course/name]}]}]}])
;; => {[:school/id 1]
;;     {:allocations
;;      {[:classroom/id "c1"] [#:course{:name "A"} #:course{:name "B"}],
;;       [:classroom/id "c2"] [#:course{:name "A"}]}}}

We'd want to support this for joins and unions.

A few ideas:

  1. Use _ as the key, e.g. [{'_ [:course/name]}]
  2. Support some kind of regex a la spec, perhaps use spec itself. E.g. [{(s/spec (s/tuple keyword? string?)) [:course/name]}]
  3. Accept a predicate fn, such as [{(fn [x] (and (vector? x) (= :classroom/id (first x)))) [:course/name]}]
@lilactown
Copy link
Owner Author

Options 2 and 3 would require changes to the EQL parsing library to allow functions in the key position...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant