hello folks, as anybody been able to achive CREATE TABLE IF NOT EXISTS users
with honeysql?
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
.
Or does HoneySQL provide a DSL for the actual columns etc that you'd rather use over the java.jdbc
"column specs"?
@seancorfield I am not on the JVM
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 "
I think IF NOT EXISTS
has to come before the table name?
How are you executing the SQL if you're not on the JVM? Or are you just generating SQL and not executing it?
I am using postgres-node
in Javascript
and you are right, the order is wrong there
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
The drop table clause doesn't support IF EXISTS
either.
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?
it does support extending though, so I have actually modified honeysql-postgres
give me one sec