No matching definitions.

postgres/notify

src/postgres/notify.tur
defn

notify-listen

(notify-listen [conn :int channel :cstr] :ptr<void>)

subscribe to asynchronous notifications on a channel.

connconnection handle
channelchannel name to listen on

(ok 0) on success; (err 0) on failure.

(notify-listen conn "my_channel")

Since: PG3

defn

notify-unlisten

(notify-unlisten [conn :int channel :cstr] :ptr<void>)

unsubscribe from asynchronous notifications on a channel.

connconnection handle
channelchannel name to stop listening on

(ok 0) on success; (err 0) on failure.

(notify-unlisten conn "my_channel")

Since: PG3

defn

notify-poll

(notify-poll [conn :int] :ptr<void>)

poll for a pending notification without blocking.

connconnection handle

(ok notif-handle) if a notification is available; (ok 0) if none pending; (err 0) if PQconsumeInput fails. Use notification-channel and notification-payload to read the notif-handle. The handle is a PGnotify* owned by libpq; free it with PQfreemem after reading.

(let [r (notify-poll conn)]
    (if (ok? r)
      (let [n (ok-val r)]
        (if (!= n 0)
          (println (notification-channel n))
          nil))
      (println "poll error")))

Since: PG3

defn

notification-channel

(notification-channel [n :int] :cstr)

return the channel name of a PGnotify notification.

nnotification handle (ok-val from notify-poll when non-zero)

Channel name as :cstr (valid until PQfreemem is called on n).

(notification-channel notif)  ; => "my_channel"

Since: PG3

defn

notification-payload

(notification-payload [n :int] :cstr)

return the payload string of a PGnotify notification.

nnotification handle (ok-val from notify-poll when non-zero)

Payload as :cstr (valid until PQfreemem is called on n); "" if none.

(notification-payload notif)  ; => "hello"

Since: PG3

Internal definitions
__ok-- create an ok result wrapping integer value v.
__err-- create an err result wrapping integer error value e.
__listen-sql-- build "LISTEN channel" as a heap-allocated cstr.
__unlisten-sql-- build "UNLISTEN channel" as a heap-allocated cstr.
__pq-exec-raw-- execute SQL with no params; returns 1 on success, 0 on failure.
__pq-consume-input-- call PQconsumeInput; returns 1 on success, 0 on error.
__pq-notifies-- call PQnotifies; returns PGnotify* as :int (0 if none pending).