I am using Hugsql with Clojure to access Postgresql db. Some of my database tables have optional columns - for a simple example, consider the "users" table with various address columns - address1, address2, city, etc.
When I write the Hugsql query specification for “update”, I don’t know what values will be present on the card that I am transmitting. Therefore, if I write a request:
-- :name update-user! :! :n UPDATE users set firstname = :firstname, address1 = :address1 where id = :id
but pass the user card
(update-user! {:id "testuser" :firstname "Bartholamew"})
an exception is thrown. I expect it to create something like
UPDATE users SET firstname='Bartholamew', address1=NULL where id='testuser'
I looked at the source of Hugsql - it calls a function (validate-parameters) that throws an exception that I cannot see. I am sure that I am missing something obvious: this does not seem like an unusual requirement, and I do not want to write a separate SQL query for each possible combination of additional columns.
Is there a way to deal with missing parameters that I am missing? Am I abusing a database by having extra columns?
source share