honeysql

Can 2024-07-05T08:58:23.719999Z

Hello everyone!

(def format-params {:checking :strict                       
                    :params   {}                           
                    :pretty   true                          
                    :dialect  :postgresql})                

Can 2024-07-05T08:58:53.181419Z

I getting this error : (query! {:select [:*] :from [:web-user]}) Execution error (ExceptionInfo) at honey.sql/check-dialect (sql.cljc:1736). Invalid dialect: postgresql Any ideas why?

p-himik 2024-07-05T09:00:00.964619Z

Use :ansi instead of :postgresql.

Can 2024-07-05T09:02:41.031369Z

Can 2024-07-05T09:02:56.203699Z

When I delete :ansi it is working

p-himik 2024-07-05T09:04:37.270689Z

What is query!?

Can 2024-07-05T09:05:17.075329Z

(def fmt sql/format)

(defn execute! [q]
  (let [sql-string (fmt q #_format-params)]
    (println q)
    (println sql-string)
    (j/db-do-prepared conn-str sql-string)))

(defn query! [q]
  (let [sql-string (fmt q #_format-params)]
    (println q)
    (println sql-string)
    (j/query conn-str sql-string)))

p-himik 2024-07-05T09:09:50.438399Z

Ah, huh. When :dialect is set explicitly, :quoted true is also assumed, unless it's explicitly set to false or the dialect is :nrql. So you can either omit :dialect completely (`:ansi` is the default anyway), or add :quoted nil to the options.

Can 2024-07-05T09:14:36.727379Z

Ah ":quoted nil" fixed, thank you 🙂 I have a new journey now. I am learning to use HoneySQL to create a basic app. I have one more question: Is there a list that matches SQL types to Clojure types, like varchar to text, number int etc.? While trying to create complex tables getting strange errors 😄

p-himik 2024-07-05T09:16:12.853369Z

next.jdbc or whatever you're using instead of it would have such a list. If not in the docs, then in the impl. I imagine some of the mappings come from the underlying Java impl, specifically text and numbers are definitely at the Java level, built into JDK.

👀 1
Can 2024-07-05T09:18:15.578829Z

thanks for seperating time, good day 🙂

👍 1
seancorfield 2024-07-05T16:59:38.184989Z

All this is in the documentation, by the way.

seancorfield 2024-07-05T17:00:08.970719Z

If you have suggestions for improving the docs, feel free to create issues on GitHub.

seancorfield 2024-07-05T17:00:56.334949Z

Specifically, Getting Started lists the valid dialects: https://cljdoc.org/d/com.github.seancorfield/honeysql/2.6.1147/doc/getting-started?q=dialect#dialects

Can 2024-07-05T17:01:40.390189Z

Awesome thanks!

seancorfield 2024-07-05T17:02:16.472439Z

That section says "If you want to use a dialect and use the default quoting strategy (automatically quote any SQL entities that seem unusual), specify a :dialect option and set :quoted nil:" and then provides a bunch of examples of how :dialect and :quoted interact.