-- src\app\credit\db\sql\creditdict.sql
-- :name insert-credit-dictdata :! :n
INSERT INTO corp_credit_dictdata
(:i*:cols)
VALUES
(:v*:vals)
(defn test
[& args]
(println (creditdict-db/insert-credit-dictdata-sqlvec {:cols ["id","parentid"] :vals ["1232323","45623"]})))
(defn test2
[& args]
(creditdict-db/insert-credit-dictdata {:cols ["id","parentid"] :vals ["1232323","45623"]}))
When are run test function print insert sql:
clj -X app.credit.core/test
Warning: environ value D:\C\java\jdk1.8.0_231 for key :java-home has been overwritten with D:\C\java\jdk1.8.0_231\jre
[2022-05-08 09:05:03.918] I app.db - Init database pool
[2022-05-08 09:05:03.950] I app.db - Set hugsql adapter
WARNING: test already refers to: #'clojure.core/test in namespace: app.credit.core, being replaced by: #'app.credit.core/test
[INSERT INTO corp_credit_dictdata
(id, parentid)
VALUES
(?,?) 1232323 45623]
When are run test2 print error:
WARNING: test already refers to: #'clojure.core/test in namespace: app.credit.core, being replaced by: #'app.credit.core/test
Execution error (ExceptionInfo) at hugsql.core/validate-parameters! (core.clj:83).
Parameter Mismatch: :cols parameter data not found.Look at the difference between https://www.hugsql.org/using-hugsql/def-db-fns and https://www.hugsql.org/using-hugsql/def-sqlvec-fns
The -sqlvec form produces a vector with SQL and parameter values. The other form expects to be given a database source/connection as the first argument.
Oh! I see it . thank you!