0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 16:18:11 -05:00

🎉 Add pgarray and pgpoint helpers to db namespace.

This commit is contained in:
Andrey Antukh 2020-10-20 17:29:09 +02:00 committed by Hirunatan
parent 4705656d29
commit a783a77404

View file

@ -10,6 +10,7 @@
(ns app.db (ns app.db
(:require (:require
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.config :as cfg] [app.config :as cfg]
[app.metrics :as mtx] [app.metrics :as mtx]
[app.util.data :as data] [app.util.data :as data]
@ -31,6 +32,10 @@
com.zaxxer.hikari.HikariConfig com.zaxxer.hikari.HikariConfig
com.zaxxer.hikari.HikariDataSource com.zaxxer.hikari.HikariDataSource
com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory
java.sql.Connection
java.sql.Savepoint
org.postgresql.jdbc.PgArray
org.postgresql.geometric.PGpoint
org.postgresql.util.PGInterval org.postgresql.util.PGInterval
org.postgresql.util.PGobject)) org.postgresql.util.PGobject))
@ -161,6 +166,26 @@
[v] [v]
(instance? PGInterval v)) (instance? PGInterval v))
(defn pgpoint?
[v]
(instance? PGpoint v))
(defn pgarray?
[v]
(instance? PgArray v))
(defn pgarray-of-uuid?
[v]
(and (pgarray? v) (= "uuid" (.getBaseTypeName ^PgArray v))))
(defn pgpoint
[p]
(PGpoint. (:x p) (:y p)))
(defn decode-pgpoint
[^PGpoint v]
(gpt/point (.-x v) (.-y v)))
(defn pginterval (defn pginterval
[data] [data]
(org.postgresql.util.PGInterval. ^String data)) (org.postgresql.util.PGInterval. ^String data))
@ -225,6 +250,14 @@
(.setType "jsonb") (.setType "jsonb")
(.setValue (json/write-str data)))) (.setValue (json/write-str data))))
(defn pgarray->set
[v]
(set (.getArray ^PgArray v)))
(defn pgarray->vector
[v]
(vec (.getArray ^PgArray v)))
;; Instrumentation ;; Instrumentation
(mtx/instrument-with-counter! (mtx/instrument-with-counter!