Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ FROM dual;
:row-fn :sysdate
:identifiers identity})
;=> #inst "2014-09-30T07:30:06.764000000-00:00"

;;; With :as-arrays? you get ordered vectors instead of unordered maps.
;;; Useful if you want to preserve the column ordering of your SQL statement:
(find-older-than {:age 20} {:as-arrays? true})
;=> ([:person_id :name :age] [1 "Betty" 21] [2 "Betsy" 22] [3 "Becky" 23])
```

As with `clojure.java.jdbc` the default `:result-set-fn` is `doall`,
Expand Down
5 changes: 3 additions & 2 deletions src/yesql/generate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@

(defn query-handler
[db sql-and-params
{:keys [row-fn result-set-fn identifiers]
{:keys [row-fn result-set-fn identifiers as-arrays?]
:or {identifiers lower-case
row-fn identity
result-set-fn doall}
:as call-options}]
(jdbc/query db sql-and-params
:identifiers identifiers
:row-fn row-fn
:result-set-fn result-set-fn))
:result-set-fn result-set-fn
:as-arrays? as-arrays?))

(defn generate-query-fn
"Generate a function to run a query.
Expand Down
7 changes: 7 additions & 0 deletions test/yesql/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
:identifiers clojure.string/upper-case
:row-fn :TIME}))

;;; Check that :as-arrays? option returns a seq of ordered vectors instead of unordered maps
(expect [:time] (current-time-query {} {:result-set-fn first
:as-arrays? true}))

(expect java.util.Date (first (current-time-query {} {:result-set-fn second
:as-arrays? true})))

;;; Test comment rules.
(defquery inline-comments-query
"yesql/sample_files/inline_comments.sql"
Expand Down