json-pointer-hasql-0.1.1: JSON Pointer extensions for Hasql

Safe HaskellNone
LanguageHaskell2010

JSONPointer.Hasql.Encoders

Description

Extension to the Hasql.Encoders module. Contains no conflicting symbols, so it can be imported under the same qualified name, e.g.:

import qualified Hasql.Encoders as Encoders
import qualified JSONPointer.Hasql.Encoders as Encoders

Synopsis

Documentation

textArrayFromJSONPointer :: Value JSONPointer Source

An encoder of JSON Pointer into the text[] type of Postgres.

Can be used to query the JSON columns, as in the following example:

selectOfJSONByJSONPointer :: Query JSONPointer (Maybe Data.Aeson.Value)
selectOfJSONByJSONPointer =
  statement sql encoder decoder True
  where
    sql =
      "select '{\"1\":[0,1,2,3]}'::jsonb #> $1"
    encoder =
      Encoders.value Encoders.textArrayFromJSONPointer
    decoder =
      Decoders.singleRow $
      Decoders.nullableValue Decoders.jsonb