-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #274 by adding aggregate-by-keys
Signed-off-by: Sean Corfield <[email protected]>
- Loading branch information
1 parent
10fd00a
commit 3042079
Showing
6 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,12 @@ These functions are described in more detail below. They are deliberately simple | |
|
||
If you prefer to write your SQL separately from your code, take a look at [HugSQL](https://github.com/layerware/hugsql) -- [HugSQL documentation](https://www.hugsql.org/) -- which has a `next.jdbc` adapter, as of version 0.5.1. See below for a "[quick start](#hugsql-quick-start)" for using HugSQL with `next.jdbc`. | ||
|
||
As of 1.3.next, `aggregate-by-keys` exists as a wrapper around `find-by-keys` | ||
that accepts the same options as `find-by-keys` and an aggregate SQL expression | ||
and it returns a single value (the aggregate). `aggregate-by-keys` accepts the | ||
same options as `find-by-keys` except that `:columns` may not be specified | ||
(since it is used to add the aggregate to the query). | ||
|
||
## `insert!` | ||
|
||
Given a table name (as a keyword) and a hash map of column names and values, this performs a single row insertion into the database: | ||
|
@@ -247,6 +253,26 @@ If you want to match all rows in a table -- perhaps with the pagination options | |
|
||
If no rows match, `find-by-keys` returns `[]`, just like `execute!`. | ||
|
||
## `aggregate-by-keys` | ||
|
||
Added in 1.3.next, this is a wrapper around `find-by-keys` that makes it easier | ||
to perform aggregate queries:: | ||
|
||
```clojure | ||
(sql/aggregate-by-keys ds :address "count(*)" {:name "Stella" | ||
:email "[email protected]"}) | ||
;; is roughly equivalent to | ||
(-> (sql/find-by-keys ds :address {:name "Stella" :email "[email protected]"} | ||
{:columns [["count(*)" :next_jdbc_aggregate_123]]}) | ||
(first) | ||
(get :next_jdbc_aggregate_123)) | ||
``` | ||
|
||
(where `:next_jdbc_aggregate_123` is a unique alias generated by `next.jdbc`, | ||
derived from the aggregate expression string). | ||
|
||
> Note: the SQL string provided for the aggregate is copied exactly as-is into the generated SQL -- you are responsible for ensuring it is legal SQL! | ||
## `get-by-id` | ||
|
||
Given a table name (as a keyword) and a primary key value, with an optional primary key column name, execute a query on the database: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters