greg-rychlewski
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 · GitHub
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:
-
Text search functions requiring OIDs: Error interpolating `ts_vector` Ecto - is this a bug?. It avoids the double casting
oid::text::regconfig. -
Extensions that don’t have a binary protocol version. For example,
ltreedidn’t have a binary protocol under somewhat recently -
Using Postgrex directly instead of Ecto and preferring the text versions of certain types (i.e. UUID): pass uuid as string by OleMchls · Pull Request #271 · elixir-ecto/postgrex · GitHub
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:
- 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;.
- Define a custom type module, as needed by Postgrex
Postgrex.Types.define(MyApp.PostgrexTypes, [PostgrexTextExt], [])
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









