Idiomatic Clojure builder for the PostgREST API.
Builds a request map via thread-first, then execute runs it through
supabase.core.http and returns either a response or an anomaly.
(require '[supabase.core.client :as sc]
'[supabase.postgrest :as pg])
(def client (sc/make-client "https://abc.supabase.co" "anon-key"))
;; SELECT
(-> (pg/from client "users")
(pg/select "*")
(pg/eq "active" true)
(pg/order "created_at")
(pg/limit 10)
(pg/execute))
;; INSERT
(-> (pg/from client "users")
(pg/insert {:email "a@b.com"})
(pg/execute))
;; UPDATE filtered
(-> (pg/from client "users")
(pg/eq "id" 42)
(pg/update {:name "Jane"})
(pg/execute))
;; DELETE filtered
(-> (pg/from client "users")
(pg/eq "id" 42)
(pg/delete)
(pg/execute))
;; RPC
(-> (pg/rpc client "my_function" {:arg 1})
(pg/execute))
See sub-namespaces for the full API:
supabase.postgrest.filters — eq / gt / like / contains / and / or / not / ...supabase.postgrest.query — select / embed / insert / upsert / update / delete / rpc / aggregationssupabase.postgrest.transform— order / limit / range / single / csv / explain / returning / ...supabase.postgrest.encode — pg-array / pg-range / pg-bool / ->iso (type coercion helpers)Idiomatic Clojure builder for the PostgREST API.
Builds a request map via thread-first, then `execute` runs it through
`supabase.core.http` and returns either a response or an anomaly.
## Quick start
(require '[supabase.core.client :as sc]
'[supabase.postgrest :as pg])
(def client (sc/make-client "https://abc.supabase.co" "anon-key"))
;; SELECT
(-> (pg/from client "users")
(pg/select "*")
(pg/eq "active" true)
(pg/order "created_at")
(pg/limit 10)
(pg/execute))
;; INSERT
(-> (pg/from client "users")
(pg/insert {:email "a@b.com"})
(pg/execute))
;; UPDATE filtered
(-> (pg/from client "users")
(pg/eq "id" 42)
(pg/update {:name "Jane"})
(pg/execute))
;; DELETE filtered
(-> (pg/from client "users")
(pg/eq "id" 42)
(pg/delete)
(pg/execute))
;; RPC
(-> (pg/rpc client "my_function" {:arg 1})
(pg/execute))
See sub-namespaces for the full API:
- `supabase.postgrest.filters` — eq / gt / like / contains / and / or / not / ...
- `supabase.postgrest.query` — select / embed / insert / upsert / update / delete / rpc / aggregations
- `supabase.postgrest.transform`— order / limit / range / single / csv / explain / returning / ...
- `supabase.postgrest.encode` — pg-array / pg-range / pg-bool / ->iso (type coercion helpers)(execute req)Runs the built request. Returns {:status :body :headers} or an
anomaly enriched with PostgREST error metadata.
Runs the built request. Returns `{:status :body :headers}` or an
anomaly enriched with PostgREST error metadata.(execute-async req)Async variant of execute. Returns a CompletableFuture resolving to
the same value execute would, with PostgREST error enrichment applied.
The future is cancellable: (future-cancel fut) aborts the in-flight
request (see supabase.core.http/execute-async). Wire it to a core.async
channel or any external cancel signal:
(let [fut (-> (pg/from c "big_table") (pg/select "*") (pg/execute-async))]
;; on some signal:
(future-cancel fut))
Async variant of [[execute]]. Returns a `CompletableFuture` resolving to
the same value [[execute]] would, with PostgREST error enrichment applied.
The future is cancellable: `(future-cancel fut)` aborts the in-flight
request (see `supabase.core.http/execute-async`). Wire it to a core.async
channel or any external cancel signal:
(let [fut (-> (pg/from c "big_table") (pg/select "*") (pg/execute-async))]
;; on some signal:
(future-cancel fut))(from c table)Starts a builder bound to table. Returns a request map you can
thread through filters / verbs / transforms before calling execute.
Returns an anomaly if the client is invalid.
Starts a builder bound to `table`. Returns a request map you can thread through filters / verbs / transforms before calling `execute`. Returns an anomaly if the client is invalid.
(schema req new-schema)Override the schema used for THIS request only. Defaults to the
client's :db :schema.
Override the schema used for THIS request only. Defaults to the client's `:db :schema`.
(with-custom-media-type req media-type)Override the accept header via a media-type keyword.
Valid keys: :default, :csv, :json, :openapi, :postgis,
:pgrst-plan, :pgrst-object, :pgrst-array.
Override the accept header via a media-type keyword. Valid keys: `:default`, `:csv`, `:json`, `:openapi`, `:postgis`, `:pgrst-plan`, `:pgrst-object`, `:pgrst-array`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |