Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reorder function #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions src/korma/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@
[query field & [dir]]
(update-in query [:order] conj [field (or dir :ASC)]))

(defn reorder
"Clear all order clauses then add an ORDER BY clause to a select, union,
union-all or intersect query.
field should be a keyword of the field name, dir is ASC by default.

(reorder query :created :asc)"
[query field & [dir]]
(order (assoc query :order []) field dir))

(defn values
"Add records to an insert clause. values can either be a vector of maps or a
single map.
Expand Down
7 changes: 7 additions & 0 deletions test/korma/test/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@
"SELECT \"users\".* FROM \"users\""
(select users (where {})))))

(deftest order-reorder
(sql-only
(is (= "SELECT \"users\".* FROM \"users\" ORDER BY \"users\".\"created\" DESC"
(select users
(order :updated)
(reorder :created :DESC))))))

(deftest with-many
(with-out-str
(dry-run
Expand Down