Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does Toucan support enumerated types? #80

Open
githorse opened this issue Mar 18, 2021 · 2 comments
Open

Does Toucan support enumerated types? #80

githorse opened this issue Mar 18, 2021 · 2 comments

Comments

@githorse
Copy link

@camsaul My postgres db has an enumerated type. I see this possible hack for making that work in java-jdbc, but that looks messy and possibly destroys the type safety of the enum in the first place (not clear). I can probably live with just strings here, but any advice on making enums work with Toucan?

@camsaul
Copy link
Member

camsaul commented Mar 19, 2021

Toucan doesn't support Postgres enums directly but it uses HoneySQL under the hood so you can do something like this

(defn- pg-enum [enum-type value]
  (reify
    honeysql.format/ToSql
    (to-sql [_]
      (honeysql.format/add-anon-param value)
      (format "?::\"%s\"" enum-type))))

Then you can use them in Toucan:

(db/select Birds :bird_type (pg-enum "bird_type" "toucan"))

@marksto
Copy link
Contributor

marksto commented Dec 21, 2021

I would suggest using a different approach that is idiomatic to the clojure.java.jdbc and does not require one to prepare query params each time for HoneySQL to understand them:
https://github.com/metabase/toucan/pull/89/files#diff-ef52c6468aae561cdf12e47e3ef10706d625572b4c6af3fc7967c845285593c6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants