korma/Korma — pull request #225 by scttnlsn (2014-04-23 17:52:56+00:00)
Title: Add reorder function

This pull-request adds a `reorder` function similar to the existing `order` function, however, it first clears any existing order clauses.

Example:

```clojure
(def query (-> (select* users)
(order :foo)
(order :bar)))

(exec (-> query
(reorder :created))
```

This results in the following SQL:

```sql
SELECT "users".* FROM "users" ORDER BY "users"."created" ASC
```

---

As another example, consider the case where we have a sorted base query that we'd like to return along with the total count. In the following case the `reorder` is actually necessary (otherwise the count query fails).

```clojure
(def query (-> (select* users)
(where {:username [= "foo"])
(order :created)))

(def results (-> query
(limit 10)
(offset 25)))

(def total (-> query
(aggregate (count :*) :total)
(reorder :total)))
```