From e207d69699e567a5fd535641877622ec97710416 Mon Sep 17 00:00:00 2001 From: Charles Fourdrignier Date: Sat, 19 Feb 2022 11:42:47 +0100 Subject: [PATCH] Refactoring des queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A la lecture de la documentation sur les "find specifications", on trouve de meilleures systèmes que "map first" et "ffirst" pour générer des résultats plus propres. + Fix de la pull query après lecture des "pull patterns" --- repl/introduce_datascript.clj | 6 ++++++ src/library_monkey/core.clj | 22 ++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/repl/introduce_datascript.clj b/repl/introduce_datascript.clj index 2880be7..4aae263 100644 --- a/repl/introduce_datascript.clj +++ b/repl/introduce_datascript.clj @@ -69,3 +69,9 @@ date))) (sort-by :nb-jours <) (clojure.pprint/print-table)) + +(d/q + '[:find (count ?b) . + :where + [?u :borrowings ?b]] + @conn) diff --git a/src/library_monkey/core.clj b/src/library_monkey/core.clj index ab738ce..7de1a55 100644 --- a/src/library_monkey/core.clj +++ b/src/library_monkey/core.clj @@ -64,21 +64,19 @@ (count (map first (d/q '[:find (pull ?r [:pseudo]) :where [?r :borrowings ?b]] - @conn))) + @conn)))) - ) (defn read-aggregates [conn] (hash-map - :count (ffirst - (d/q - '[:find (count ?b) - :where - [?u :borrowings ?b]] - @conn)) - :reports (map first (d/q '[:find (pull ?r [:pseudo :username :borrowings]) - :where [?r :borrowings ?b]] - @conn))) - ) + :count (d/q + '[:find (count ?b) . + :where + [?u :borrowings ?b]] + @conn) + :reports (d/q '[:find [(pull ?r [:pseudo :username + {:borrowings [:titre :date-de-retour :type-de-document]}]) ...] + :where [?r :borrowings ?b]] + @conn))) (def amiens-library (reify Library