honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
richiardiandrea 2018-05-04T17:15:38.000240Z

hello folks, as anybody been able to achive CREATE TABLE IF NOT EXISTS users with honeysql?

seancorfield 2018-05-04T17:17:58.000263Z

Why bother with HoneySQL for something so simple? java.jdbc has create-table-ddl and accepts :conditional? in its options to add IF NOT EXISTS.

seancorfield 2018-05-04T17:18:44.000385Z

Or does HoneySQL provide a DSL for the actual columns etc that you'd rather use over the java.jdbc "column specs"?

richiardiandrea 2018-05-04T17:19:16.000074Z

@seancorfield I am not on the JVM

richiardiandrea 2018-05-04T17:28:42.000137Z

I came up with this but it feels I can improve on it so seeking advice:

(defmethod sqlf/format-clause :if-not-exists [_ _]
  (str "IF NOT EXISTS "))

(-> (sqlph/create-table :events) (assoc :if-not-exists true) (sqlf/format))
"CREATE TABLE events IF NOT EXISTS "

seancorfield 2018-05-04T18:40:27.000619Z

I think IF NOT EXISTS has to come before the table name?

seancorfield 2018-05-04T18:41:02.000577Z

How are you executing the SQL if you're not on the JVM? Or are you just generating SQL and not executing it?

richiardiandrea 2018-05-04T18:45:25.000371Z

I am using postgres-node in Javascript

richiardiandrea 2018-05-04T18:45:33.000535Z

and you are right, the order is wrong there

seancorfield 2018-05-04T18:48:24.000251Z

I assume you're using the postgres helpers for HoneySQL? It seems like you'd need to overwrite/enhance this https://github.com/nilenso/honeysql-postgres/blob/932ca5113568407c3c9df480cfd0949fddc8e4ab/src/honeysql_postgres/format.clj#L130

seancorfield 2018-05-04T18:48:53.000721Z

The drop table clause doesn't support IF EXISTS either.

seancorfield 2018-05-04T18:49:44.000698Z

Basic HoneySQL doesn't support any DDL does it? I searched for create table and found it listed in the TODO section, not in the code?

richiardiandrea 2018-05-04T18:50:33.000168Z

it does support extending though, so I have actually modified honeysql-postgres

richiardiandrea 2018-05-04T18:50:40.000469Z

give me one sec

richiardiandrea 2018-05-04T19:06:24.000205Z

https://github.com/nilenso/honeysql-postgres/pull/18