hasql-th icon indicating copy to clipboard operation
hasql-th copied to clipboard

How to deal with custom types?

Open sir4ur0n opened this issue 1 year ago • 5 comments

Hi, I have several PostgreSQL custom types, e.g.:

CREATE TYPE foo AS ENUM ('foo', 'bar', 'baz');

How is one supposed to handle these with hasql-th please? Currently if I just type e.g. SELECT x :: foo, I get this error:

No codec exists for type: foo

It might also be nice to document it for future users :sweat_smile: :pray:

Ideally, one could register custom codecs, so that the SQL code can be used interchangeably in Haskell or directly in an SQL editor/PSQL. E.g.:

instance HasqlThCodec Foo where
  sqlTypeName = "foo"
  encode Foo{..} = -- ...
  decode .. = Foo {..}

getFoo = [maybeStatement|SELECT x :: foo from foos|]

sir4ur0n avatar Apr 17 '23 12:04 sir4ur0n