Wrap app:
(funcall lack/middleware/postmodern:*lack-middleware-postmodern*
*app*
:pools `((:pool-id :mydb
:database "mydb"
:username "myuser"
:host "localhost"
:use-binary t
:application-name "myapp"
:query-log ,(when (developmentp)
*standard-output*)
:max-open-count 12
:timeout 4000
:idle-timeout 30000)))
Lack Builder:
(lack:builder
(:postmodern :pools `((:pool-id :mydb
:database "mydb"
:username "myuser"
:password nil
:host "localhost"
:use-binary t
:application-name "myapp"
:query-log ,(when (developmentp)
*standard-output*)
:max-open-count 12
:max-idle-count 3
:timeout 5000
:idle-timeout 40000)
(:pool-id :otherdb
:database "otherdb"
:username "foo"
:password "abcxyz"
:host "localhost"
:use-binary t)))
*app*)
Once you have a pool configured, you can call macro WITH-POSTMODERN
from your application to checkout a connection from the specified pool:
(with-postmodern (:mydb)
(assert (= 1 (pomo:query "select 1" :single))))
POOL-ID
: required; unique name of the pool, a keywordPOOL-NAME
: optional; passed through to theANYPOOL:MAKE-POOL
as theNAME
parameter, defaulting to "postmodern-[downcased-pool-id]" if not providedMAX-OPEN-COUNT
: optional; passed through toANYPOOL:MAKE-POOL
(default: 10)MAX-IDLE-COUNT
: optional; passed through toANYPOOL:MAKE-POOL
(default 3)TIMEOUT
: optional; passed through toANYPOOL:MAKE-POOL
(default: 3000)IDLE-TIMEOUT
: optional; passed through toANYPOOL:MAKE-POOL
(default: 60000)PING
: optional; allows providing a custom ping function toANYPOOL:MAKE-POOL
. If you provide your own ping function, this is not passed through toANYPOOL:MAKE-POOL
directly, instead it bindsPOSTMODERN:*DATABASE*
for you and then calls the provided functionDATABASE
: required; the name of the PostgreSQL databaseUSERNAME
: required; the name of the PostgreSQL userPASSWORD
: optional; the password for the PostgreSQL userHOST
: required; the PostgreSQL hostPORT
: optional; the PostgreSQL port, passed through toPOSTMODERN:CONNECT
keyword arguments when non-nil (default: 5432)USE-SSL
: optional; passed through toPOSTMODERN:CONNECT
keyword arguments when non-NILUSE-BINARY
: optional; passed through toPOSTMODERN:CONNECT
keyword arguments when non-NILSERVICE
: optional; passed through toPOSTMODERN:CONNECT
keyword arguments when non-NILAPPLICATION-NAME
: optional; passed through toPOSTMODERN:CONNECT
keyword arguments when non-NILQUERY-LOG
: optional;POSTMODERN::*QUERY-LOG*
is bound to the provided valueSCHEMA-PATH
: optional;POSTMODERN::*SCHEMA-PATH*
is bound to the provided valueSSL-CERTIFICATE-FILE
: optional;CL-POSTGRES:*SSL-CERTIFICATE-FILE*
is bound to the provided valueSSL-KEY-FILE
: optional;CL-POSTGRES:*SSL-KEY-FILE*
is bound to the provided valueSSL-ROOT-CA-FILE
: optional;CL-POSTGRES:*SSL-ROOT-CA-FILE*
is bound to the provided valueON-TOO-MANY-OPEN-CONNECTIONS
: optional; function called fromHANDLER-BIND
handler forANYPOOL:TOO-MANY-OPEN-CONNECTION
error before returning a 503 response; may be useful for sending a notification or some other purpose
See the Postmodern documentation for further details related to the connection parameters. Also you can check out the source for function POSTMODERN:CONNECT
to see the default values for the keyword parameters.
Run tests:
(asdf:test-system :foo.lisp.lack-middleware-postmodern)
The tests assume that the "postgres" superuser is configured for passwordless authentication.
Not in Quicklisp, so clone the repository to "local-projects/".
- John Newton ([email protected])
Copyright (c) 2024 John Newton
Apache-2.0