diff --git a/deps.edn b/deps.edn index 72c3dbe5..f8320956 100644 --- a/deps.edn +++ b/deps.edn @@ -127,7 +127,8 @@ clj-stacktrace/clj-stacktrace {:mvn/version "0.2.8"} clojure-msgpack/clojure-msgpack {:mvn/version "1.2.1"} cli-matic/cli-matic {:git/url "https://github.com/l3nz/cli-matic.git", :git/sha "9cd53ba7336363e3d06650dbad413b6f8b06e471"} - aysylu/loom {:mvn/version "1.0.2"}} + aysylu/loom {:mvn/version "1.0.2"} + com.layerware/hugsql-core {:mvn/version "0.5.1"}} :classpath-overrides {org.clojure/clojure nil org.clojure/spec.alpha nil}} :clj-nvd diff --git a/test-resources/lib_tests/bb-tested-libs.edn b/test-resources/lib_tests/bb-tested-libs.edn index 2c4a7428..2f679fa9 100644 --- a/test-resources/lib_tests/bb-tested-libs.edn +++ b/test-resources/lib_tests/bb-tested-libs.edn @@ -108,4 +108,6 @@ clj-stacktrace/clj-stacktrace {:git-url "https://github.com/mmcgrana/clj-stacktrace", :test-namespaces (clj-stacktrace.repl-test clj-stacktrace.core-test), :git-sha "94dc2dd748710e79800e94b713e167e5dc525717"} clojure-msgpack/clojure-msgpack {:git-url "https://github.com/edma2/clojure-msgpack", :test-namespaces (msgpack.core-check msgpack.core-test), :git-sha "a4bca2cf064a87d9c4a564c634c6ebb65578dad5"} cli-matic/cli-matic {:git-url "https://github.com/l3nz/cli-matic.git", :test-namespaces (cli-matic.utils-test cli-matic.presets-test cli-matic.help-gen-test cli-matic.utils-convert-config-test cli-matic.utils-candidates-test cli-matic.core-test cli-matic.utils-v2-test), :git-sha "9cd53ba7336363e3d06650dbad413b6f8b06e471"} - aysylu/loom {:git-url "https://github.com/aysylu/loom", :test-namespaces (loom.test.network-simplex loom.test.label loom.test.alg-generic loom.test.compliance-tester loom.test.flow loom.test.alg loom.test.attr loom.test.graph loom.test.derived), :git-sha "d458f0c0dee9021983c64381b90a470f0178cc8e"}} + aysylu/loom {:git-url "https://github.com/aysylu/loom", :test-namespaces (loom.test.network-simplex loom.test.label loom.test.alg-generic loom.test.compliance-tester loom.test.flow loom.test.alg loom.test.attr loom.test.graph loom.test.derived), :git-sha "d458f0c0dee9021983c64381b90a470f0178cc8e"} + com.layerware/hugsql-core {:test-namespaces (hugsql.babashka-test)} +} diff --git a/test-resources/lib_tests/hugsql/babashka_test.clj b/test-resources/lib_tests/hugsql/babashka_test.clj new file mode 100644 index 00000000..90e20025 --- /dev/null +++ b/test-resources/lib_tests/hugsql/babashka_test.clj @@ -0,0 +1,14 @@ +(ns hugsql.babashka-test + (:require [babashka.fs :as fs] + [clojure.test :as t :refer [deftest is]] + [hugsql.core :as hugsql])) + +(def sql-file (fs/file (fs/parent *file*) "characters.sql")) +(hugsql/def-db-fns sql-file) +(hugsql/def-sqlvec-fns sql-file) + +(declare characters-by-ids-specify-cols-sqlvec) + +(deftest sqlvec-test + (is (= ["select name, specialty from characters\nwhere id in (?,?)" 1 2] + (characters-by-ids-specify-cols-sqlvec {:ids [1 2], :cols ["name" "specialty"]})))) diff --git a/test-resources/lib_tests/hugsql/characters.sql b/test-resources/lib_tests/hugsql/characters.sql new file mode 100644 index 00000000..5679b713 --- /dev/null +++ b/test-resources/lib_tests/hugsql/characters.sql @@ -0,0 +1,45 @@ +-- src/princess_bride/db/sql/characters.sql +-- The Princess Bride Characters + +-- :name create-characters-table +-- :command :execute +-- :result :raw +-- :doc Create characters table +-- auto_increment and current_timestamp are +-- H2 Database specific (adjust to your DB) +create table characters ( + id integer auto_increment primary key, + name varchar(40), + specialty varchar(40), + created_at timestamp not null default current_timestamp +) + +/* ...snip... */ + +-- A :result value of :n below will return affected rows: +-- :name insert-character :! :n +-- :doc Insert a single character returning affected row count +insert into characters (name, specialty) +values (:name, :specialty) + +-- :name insert-characters :! :n +-- :doc Insert multiple characters with :tuple* parameter type +insert into characters (name, specialty) +values :tuple*:characters + +/* ...snip... */ + +-- A ":result" value of ":1" specifies a single record +-- (as a hashmap) will be returned +-- :name character-by-id :? :1 +-- :doc Get character by id +select * from characters +where id = :id + +-- Let's specify some columns with the +-- identifier list parameter type :i* and +-- use a value list parameter type :v* for IN() +-- :name characters-by-ids-specify-cols :? :* +-- :doc Characters with returned columns specified +select :i*:cols from characters +where id in (:v*:ids)