mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 00:26:37 +02:00
feat(backend): upgrade suricatta
This commit is contained in:
parent
1873b94fa7
commit
3c066ffce2
6 changed files with 253 additions and 50 deletions
|
@ -36,11 +36,7 @@
|
|||
{:http-server-port (lookup-env env :uxbox-http-server-port 6060)
|
||||
:http-server-debug (lookup-env env :uxbox-http-server-debug true)
|
||||
:http-server-cors (lookup-env env :uxbox-http-server-cors "http://localhost:3449")
|
||||
:database-username (lookup-env env :uxbox-database-username nil)
|
||||
:database-password (lookup-env env :uxbox-database-password nil)
|
||||
:database-name (lookup-env env :uxbox-database-name "uxbox")
|
||||
:database-server (lookup-env env :uxbox-database-server "localhost")
|
||||
:database-port (lookup-env env :uxbox-database-port 5432)
|
||||
:database-uri (lookup-env env :uxbox-database-uri "jdbc:postgresql://127.0.0.1/uxbox")
|
||||
:media-directory (lookup-env env :uxbox-media-directory "resources/public/media")
|
||||
:media-uri (lookup-env env :uxbox-media-uri "http://localhost:6060/media/")
|
||||
:assets-directory (lookup-env env :uxbox-assets-directory "resources/public/static")
|
||||
|
|
|
@ -6,18 +6,20 @@
|
|||
|
||||
(ns uxbox.db
|
||||
"Database access layer for UXBOX."
|
||||
(:require [mount.core :as mount :refer (defstate)]
|
||||
[promesa.core :as p]
|
||||
[hikari-cp.core :as hikari]
|
||||
[executors.core :as exec]
|
||||
[suricatta.core :as sc]
|
||||
[suricatta.proto :as scp]
|
||||
[suricatta.types :as sct]
|
||||
[suricatta.transaction :as sctx]
|
||||
[uxbox.config :as cfg])
|
||||
(:import org.jooq.TransactionContext
|
||||
org.jooq.TransactionProvider
|
||||
org.jooq.Configuration))
|
||||
(:require
|
||||
[executors.core :as exec]
|
||||
[hikari-cp.core :as hikari]
|
||||
[mount.core :as mount :refer (defstate)]
|
||||
[promesa.core :as p]
|
||||
[suricatta.core :as sc]
|
||||
[suricatta.impl :as si]
|
||||
[suricatta.proto :as sp]
|
||||
[uxbox.config :as cfg])
|
||||
(:import
|
||||
org.jooq.Configuration
|
||||
org.jooq.TransactionContext
|
||||
org.jooq.TransactionProvider
|
||||
))
|
||||
|
||||
;; --- State
|
||||
|
||||
|
@ -26,22 +28,11 @@
|
|||
:idle-timeout 600000
|
||||
:max-lifetime 1800000
|
||||
:minimum-idle 10
|
||||
:maximum-pool-size 10
|
||||
:adapter "postgresql"
|
||||
:username ""
|
||||
:password ""
|
||||
:database-name ""
|
||||
:server-name "localhost"
|
||||
:port-number 5432})
|
||||
:maximum-pool-size 10})
|
||||
|
||||
(defn get-db-config
|
||||
[config]
|
||||
(assoc connection-defaults
|
||||
:username (:database-username config)
|
||||
:password (:database-password config)
|
||||
:database-name (:database-name config)
|
||||
:server-name (:database-server config)
|
||||
:port-number (:database-port config)))
|
||||
(assoc connection-defaults :jdbc-url (:database-uri config)))
|
||||
|
||||
(defn create-datasource
|
||||
[config]
|
||||
|
@ -58,15 +49,15 @@
|
|||
"Asynchronous transaction handling."
|
||||
{:internal true}
|
||||
[ctx func]
|
||||
(let [^Configuration conf (.derive (scp/-config ctx))
|
||||
^TransactionContext txctx (sctx/transaction-context conf)
|
||||
(let [^Configuration conf (.derive (sp/-config ctx))
|
||||
^TransactionContext txctx (si/transaction-context conf)
|
||||
^TransactionProvider provider (.transactionProvider conf)]
|
||||
(doto conf
|
||||
(.data "suricatta.rollback" false)
|
||||
(.data "suricatta.transaction" true))
|
||||
(try
|
||||
(.begin provider txctx)
|
||||
(->> (func (sct/context conf))
|
||||
(->> (func (si/make-context conf))
|
||||
(p/map (fn [result]
|
||||
(if (.data conf "suricatta.rollback")
|
||||
(.rollback provider txctx)
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.util.time
|
||||
(:require [suricatta.proto :as proto]
|
||||
(:require [suricatta.proto :as sp]
|
||||
[suricatta.impl :as si]
|
||||
[cognitect.transit :as t])
|
||||
(:import java.time.Instant
|
||||
java.sql.Timestamp))
|
||||
|
@ -36,22 +37,17 @@
|
|||
;; Persistence Layer Conversions
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(extend-protocol proto/IParamType
|
||||
(extend-protocol sp/IParam
|
||||
Instant
|
||||
(-render [self ctx]
|
||||
(if (proto/-inline? ctx)
|
||||
(str "'" (.toString self) "'::timestamptz")
|
||||
"?::timestamptz"))
|
||||
(-param [self ctx]
|
||||
(si/sql->param "{0}::timestamptz" (.toString self))))
|
||||
|
||||
(-bind [self ctx]
|
||||
(when-not (proto/-inline? ctx)
|
||||
(let [stmt (proto/-statement ctx)
|
||||
idx (proto/-next-bind-index ctx)
|
||||
obj (Timestamp/from self)]
|
||||
(.setTimestamp stmt idx obj)))))
|
||||
|
||||
(extend-protocol proto/ISQLType
|
||||
(extend-protocol sp/ISQLType
|
||||
Timestamp
|
||||
(-convert [self]
|
||||
(.toInstant self))
|
||||
|
||||
java.time.OffsetDateTime
|
||||
(-convert [self]
|
||||
(.toInstant self)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue