Fork me on GitHub
#honeysql
<
2021-04-14
>
yenda11:04:44

Is anyone using postgres enums with honeySQL? So far the only way I found to make it work was to use either [:inline "enumValue"] or (types/as-other "enumValue"), in both cases the downside is that it involves modifying the query arguments, and keywords can't be used without an extra step to turn them into strings

dcj19:04:44

Could you write your own helper to handle the keyword conversion for you? e.g.

(defn clj-pg-enum
  [kw]
  [:inline (name kw)])

yenda08:04:15

yes that is what I have

(defn enum [k]
  (types/as-other (name k)))
I wouldn't recommend the inline solution it's not the same, with as-other it's a ? in your prepared statement, with inline it's part of it

👍 3
orestis12:04:16

I've added casts in the enum definition:

DO $$ BEGIN
  CREATE TYPE idea_state AS ENUM ('draft', 'publish');
  CREATE CAST (varchar AS idea_state) WITH INOUT AS ASSIGNMENT;
EXCEPTION
  WHEN duplicate_object THEN null;
END $$;

orestis12:04:54

But I was recently told that postgres enums are dangerous because you cannot add new values without dropping the enum, which is difficult to do when you already have data that point to the enum.

yenda17:04:36

https://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/ what you were told is not correct, adding is easy, updating is only since 9.6 and removing involves renaming / creating a new one / migrating