;; copyright (c) 2022-2024 sean corfield, all rights reserved (ns honey.sql.pg-ops "Register all the PostgreSQL JSON/JSONB operators and provide convenient Clojure names for those ops. In addition, provide names for the PostgreSQL regex operators as well. For the eleven that cannot be written directly as symbols, use mnemonic names: hash for #, at for @, and tilde for ~. For the six of those that cannot be written as keywords, invoke the `keyword` function instead. Those latter eight (`at>`, ` ->> -]) (:require [honey.sql :as sql])) #?(:clj (set! *warn-on-reflection* true)) ;; see https://www.postgresql.org/docs/current/functions-json.html (def -> "The -> operator for accessing nested JSON(B) values as JSON(B). Ex.: ```clojure (sql/format {:select [[[:->> [:-> :my_column \"kids\" [:inline 0]] \"name\"]]]}) ; => [\"SELECT (my_column -> ? -> 0) ->> ?\" \"kids\" \"name\"] ``` Notice we need to wrap the keys/indices with :inline if we don't want them to become parameters." :->) (def ->> "The ->> operator - like -> but returns the value as text instead of a JSON object." :->>) (def hash> "The #> operator extracts JSON sub-object at the specified path." :#>) (def hash>> "The #>> operator - like hash> but returns the value as text instead of JSON object." :#>>) (def at> "The @> operator - does the first JSON value contain the second?" (keyword "@>")) (def ) (sql/register-op! :->>) (sql/register-op! :#>) (sql/register-op! :#>>) (sql/register-op! at>) (sql/register-op!