mirror of
https://github.com/penpot/penpot.git
synced 2025-02-15 03:28:25 -05:00
🚧 Implement page history query using new sql builder.
This commit is contained in:
parent
efe94f8b44
commit
04464da1c8
1 changed files with 21 additions and 34 deletions
|
@ -11,6 +11,7 @@
|
||||||
[uxbox.db :as db]
|
[uxbox.db :as db]
|
||||||
[uxbox.util.spec :as us]
|
[uxbox.util.spec :as us]
|
||||||
[uxbox.services.core :as sv]
|
[uxbox.services.core :as sv]
|
||||||
|
[uxbox.util.sql :as sql]
|
||||||
[uxbox.util.time :as dt]
|
[uxbox.util.time :as dt]
|
||||||
[uxbox.util.blob :as blob]
|
[uxbox.util.blob :as blob]
|
||||||
[uxbox.util.uuid :as uuid]))
|
[uxbox.util.uuid :as uuid]))
|
||||||
|
@ -69,42 +70,28 @@
|
||||||
|
|
||||||
;; --- Query: Page History
|
;; --- Query: Page History
|
||||||
|
|
||||||
;; (def ^:private page-history-sql
|
(s/def ::page-id ::us/uuid)
|
||||||
;; "select ph.*
|
(s/def ::max ::us/integer)
|
||||||
;; from pages_history as ph
|
(s/def ::pinned ::us/boolean)
|
||||||
;; where ph.user_id = $1
|
(s/def ::since ::us/integer)
|
||||||
;; and ph.page_id = $2
|
|
||||||
;; and ph.version < $3
|
|
||||||
;; order by ph.version desc
|
|
||||||
;; limit $4")
|
|
||||||
|
|
||||||
;; (defn get-page-history
|
(s/def ::page-history
|
||||||
;; [{:keys [id page-id user since max pinned]
|
(s/keys :req-un [::page-id ::user]
|
||||||
;; :or {since Long/MAX_VALUE max 10}}]
|
:opt-un [::max ::pinned ::since]))
|
||||||
;; (let [sqlv [page-history-sql user page-id since
|
|
||||||
;; (let [sqlv (sql/get-page-history {:user user
|
|
||||||
;; :page id
|
|
||||||
;; :since since
|
|
||||||
;; :max max
|
|
||||||
;; :pinned pinned})]
|
|
||||||
;; (->> (db/fetch conn sqlv)
|
|
||||||
;; ;; TODO
|
|
||||||
;; (map decode-row))))
|
|
||||||
|
|
||||||
;; (s/def ::max ::us/integer)
|
(sv/defquery ::page-history
|
||||||
;; (s/def ::pinned ::us/boolean)
|
[{:keys [page-id user since max pinned] :or {since Long/MAX_VALUE max 10}}]
|
||||||
;; (s/def ::since ::us/integer)
|
(let [sql (-> (sql/from ["pages_history" "ph"])
|
||||||
|
(sql/select "ph.*")
|
||||||
;; (s/def ::page-history
|
(sql/where ["ph.user_id = ?" user]
|
||||||
;; (s/keys :req-un [::us/id ::user]
|
["ph.page_id = ?" page-id]
|
||||||
;; :opt-un [::max ::pinned ::since]))
|
["ph.version < ?" since]
|
||||||
|
(when pinned
|
||||||
;; (sv/defquery :page-history
|
["ph.pinned = ?" true]))
|
||||||
;; {:doc "Retrieve page history."
|
(sql/order "ph.version desc")
|
||||||
;; :spec ::page-history}
|
(sql/limit max))]
|
||||||
;; [params]
|
(-> (db/query db/pool (sql/fmt sql))
|
||||||
;; (with-open [conn (db/connection)]
|
(p/then (partial mapv decode-row)))))
|
||||||
;; (get-page-history conn params)))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Mutations
|
;; Mutations
|
||||||
|
|
Loading…
Add table
Reference in a new issue