hasql-th
hasql-th copied to clipboard
How to deal with custom types?
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|]