hugsql icon indicating copy to clipboard operation
hugsql copied to clipboard

Optional null parameters

Open jpmonettas opened this issue 5 years ago • 1 comments

Hi, thanks for the great lib!

Currently if my sql insert script is like

-- :name add-person
insert into table (id, name, address) values (:id, :name, :address) 

and everything but id accept nulls I'm forced to do

(add-person db {:id 1, :name nil, :address nil})

or I get a missing parameter error.

Is there a way of just calling it like :

(add-person db {:id 1})

Thanks!!

jpmonettas avatar Oct 16 '20 12:10 jpmonettas

You can try something like this:

-- :name add-person :<! :1
INSERT INTO table (:i*:fields)
VALUES :tuple:values RETURNING *;

then (add-person db {:fields [...] :values [...]})

alndvz avatar Jun 09 '22 11:06 alndvz