-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
I'll do more on this but wanted to start a thread in case you have feedback
Here's vaguely what I had in mind for supporting recursion.
Few notes:
- Basic premise is "one query per nested collection". That may involve more queries than joining but should be more efficent in terms of data transferred. Not sure that's what you want which is fine... I don't mind being told this is a bad idea.
- Each query needs to be given a where clause which filters the possible records to those needed. Options are: use original query as subquery
WHERE id in (query)or pass in idsWHERE id in [ids] - The method signature might be a bit complex. Aimed to work with the om parser but it's incomplete.
(defn pull-all
[{:keys [db-state query] :as env} resource {:keys [where]}]
(let [db-config (:config db-state)
expanded-relations (expand-relations query resource db-state)
{:keys [has-many belongs-to]} (group-by :relation-type expanded-relations)
query (build-query resource where belongs-to db-state)
collection (db-query (:config db-state) query)
collection (distinct collection)]
(loop [has-many (seq has-many)
ret (collection-with-associations collection resource expanded-relations db-state)]
(if-not (nil? has-many)
(let [rel (first has-many)
res (-> rel :being-added :resource)
;subq (assoc query :select [:id])
subq (mapv :id collection)
subc (pull-all env res {:where [[:id :in subq]]})
ret (stitch-up ret res subc)]
(recur (next has-many) ret))
ret))))That's really pseudocode
- needs to handle
querycontaining keys and maps (for joins) - need to implement stitch-up
Metadata
Metadata
Assignees
Labels
No labels