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:
parent
4705656d29
commit
a783a77404
1 changed files with 33 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
|||
(ns app.db
|
||||
(:require
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.config :as cfg]
|
||||
[app.metrics :as mtx]
|
||||
[app.util.data :as data]
|
||||
|
@ -31,6 +32,10 @@
|
|||
com.zaxxer.hikari.HikariConfig
|
||||
com.zaxxer.hikari.HikariDataSource
|
||||
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.PGobject))
|
||||
|
||||
|
@ -161,6 +166,26 @@
|
|||
[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
|
||||
[data]
|
||||
(org.postgresql.util.PGInterval. ^String data))
|
||||
|
@ -225,6 +250,14 @@
|
|||
(.setType "jsonb")
|
||||
(.setValue (json/write-str data))))
|
||||
|
||||
(defn pgarray->set
|
||||
[v]
|
||||
(set (.getArray ^PgArray v)))
|
||||
|
||||
(defn pgarray->vector
|
||||
[v]
|
||||
(vec (.getArray ^PgArray v)))
|
||||
|
||||
;; Instrumentation
|
||||
|
||||
(mtx/instrument-with-counter!
|
||||
|
|
Loading…
Add table
Reference in a new issue