honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
yenda 2021-04-14T11:38:44.189400Z

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

yenda 2021-04-15T08:40:15.191700Z

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

👍 1
orestis 2021-04-14T12:56:16.189800Z

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 $$;

orestis 2021-04-14T12:56:54.190700Z

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.

yenda 2021-04-14T17:48:36.190800Z

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

2021-04-14T19:43:44.191100Z

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

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