PostgrexTextExt: Text Extensions for Postgrex

Hi,

I’ve created a small helper library called PostgrexTextExt. It allows users to enable text protocol encoding/decoding in Postgrex for any PostgeSQL data type they choose, even if Postgrex doesn’t currently support it.

Github: GitHub - greg-rychlewski/postgrex_text_ext
Hex: PostgrexTextExt — PostgrexTextExt v0.1.0

I created it based on some edge cases I saw while helping with Ecto over the past year. In particular, it seems like it helps in the following cases:

I started off wanting to make an extension just for OIDs, but then I realized with very little effort you can make it work for any type.

How it’s used:

  1. Specify the data types in your configuration
  config :postgrex_text_ext,
    type_names: ["regconfig", "ltree"],
    type_outputs: ["range_out"]

There are 2 levels of granularity: type name and type output. These correspond to the typname and typoutput columns in the pg_type system catalog.

A list of type names and outputs is provided here. You may also use the pg_type system catalog: SELECT typname, typoutput FROM pg_type;.

  1. Define a custom type module, as needed by Postgrex
Postgrex.Types.define(MyApp.PostgrexTypes, [PostgrexTextExt], [])
1 Like