Skip to content

Commit 25e508b

Browse files
committed
go back to using the real honeysql
a release was made which includes the necessary multimethod for the new distinct-on functionality to work.
2 parents d005fa2 + 153d775 commit 25e508b

File tree

7 files changed

+86
-22
lines changed

7 files changed

+86
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.6
2+
- Add ILIKE, NOT ILIKE
3+
- ADD EXCEPT and EXCEPT ALL
4+
- Fix query-values priority
5+
16
## 0.2.5
27
- Adds if-exist in drop table
38

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,44 @@ Currently honeysql-postgres supports the following postgres specific clauses:
2323
- rename column
2424
- insert-into-as
2525
- pattern matching (ILIKE and NOT ILIKE)
26+
- except (and except-all)
2627

2728
## Index
2829

29-
- [Usage](https://github.com/nilenso/honeysql-postgres#usage)
30-
- [Leiningen](https://github.com/nilenso/honeysql-postgres#leiningen)
31-
- [Maven](https://github.com/nilenso/honeysql-postgres#maven)
32-
- [repl](https://github.com/nilenso/honeysql-postgres#repl)
33-
- [Breaking Change](https://github.com/nilenso/honeysql-postgres#breaking-change)
34-
- [upsert](https://github.com/nilenso/honeysql-postgres#upsert)
35-
- [insert into with alias](https://github.com/nilenso/honeysql-postgres#insert-into-with-alias)
36-
- [over](https://github.com/nilenso/honeysql-postgres#over)
37-
- [create view](https://github.com/nilenso/honeysql-postgres#create-view)
38-
- [create table](https://github.com/nilenso/honeysql-postgres#create-table)
39-
- [drop table](https://github.com/nilenso/honeysql-postgres#drop-table)
40-
- [alter table](https://github.com/nilenso/honeysql-postgres#alter-table)
41-
- [pattern matching](https://github.com/nilenso/honeysql-postgres#pattern-matching)
42-
- [SQL functions](https://github.com/nilenso/honeysql-postgres#sql-functions)
43-
- [License](https://github.com/nilenso/honeysql-postgres#license)
30+
- [Usage](#usage)
31+
- [Leiningen](#leiningen)
32+
- [Maven](#maven)
33+
- [repl](#repl)
34+
- [Breaking Change](#breaking-change)
35+
- [upsert](#upsert)
36+
- [insert into with alias](#insert-into-with-alias)
37+
- [over](#over)
38+
- [create view](#create-view)
39+
- [create table](#create-table)
40+
- [drop table](#drop-table)
41+
- [alter table](#alter-table)
42+
- [pattern matching](#pattern-matching)
43+
- [except](#except)
44+
- [SQL functions](#sql-functions)
45+
- [License](#license)
4446

4547
## Usage
4648

4749
### Leiningen
4850
```clj
49-
[nilenso/honeysql-postgres "0.2.5"]
51+
[nilenso/honeysql-postgres "0.2.6"]
5052
```
5153
### Maven
5254
```xml
5355
<dependency>
5456
<groupId>nilenso</groupId>
5557
<artifactId>honeysql-postgres</artifactId>
56-
<version>0.2.5</version>
58+
<version>0.2.6</version>
5759
</dependency>
5860
```
5961
### repl
6062
```clj
61-
; Note that `honeysql-postgres.format` and `honeysql-postgres.helpers`
63+
; Note that `honeysql-postgres.format` and `honeysql-postgres.helpers`
6264
; must be required into the project for the extended features to work.
6365
(require '[honeysql.core :as sql]
6466
'[honeysql.helpers :refer :all]
@@ -181,6 +183,17 @@ The `ilike` and `not-ilike` operators can be used to query data using a pattern
181183
sql/format)
182184
=> ["SELECT * FROM products WHERE name NOT ILIKE ?" "%name%"]
183185
```
186+
### except
187+
188+
```clj
189+
190+
(sql/format
191+
{:except
192+
[{:select [:ip]}
193+
{:select [:ip] :from [:ip_location]}]})
194+
=> ["SELECT ip EXCEPT SELECT ip FROM ip_location"]
195+
```
196+
`except-all` works the same way as `except`.
184197

185198
### SQL functions
186199
The following are the SQL functions added in `honeysql-postgres`

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{:deps {honeysql {:git/url "https://github.com/jkk/honeysql" :sha "be203e9086808c47ab7e42520950db0bfd9efcc1" :exclusions [org.clojure/clojurescript]}}}
1+
{:deps {honeysql {:mvn/version "0.9.5" :exclusions [org.clojure/clojurescript]}}}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@honeysql/honeysql-postgres",
3-
"version": "0.2.4",
3+
"version": "0.2.6",
44
"license": "EPL-1.0",
55
"homepage": "https://github.com/nilenso/honeysql-postgres",
66
"repository": {

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject b-ryan/honeysql-postgres "0.2.6"
1+
(defproject nilenso/honeysql-postgres "0.2.6"
22
:description "PostgreSQL extension for honeysql"
33
:url "https://github.com/nilenso/honeysql-postgres"
44
:license {:name "Eclipse Public License"

src/honeysql_postgres/format.cljc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(ns ^{:doc "Extension of the honeysql format functions specifically for postgreSQL"}
22
honeysql-postgres.format
33
(:require [honeysql.format :as sqlf :refer [fn-handler format-clause format-modifiers]] ;; multi-methods
4-
[honeysql-postgres.util :as util]))
4+
[honeysql-postgres.util :as util]
5+
[clojure.string :as string]))
56

67
(def ^:private custom-additions
78
{:create-table 10
@@ -26,6 +27,8 @@
2627
"Determines the order that clauses will be placed within generated SQL"
2728
(merge {:with 30
2829
:with-recursive 40
30+
:except 45
31+
:except-all 45
2932
:select 50
3033
:insert-into 60
3134
:update 70
@@ -208,6 +211,14 @@
208211
(defmethod format-clause :insert-into-as [[_ [table-name table-alias]] _]
209212
(str "INSERT INTO " (sqlf/to-sql table-name) " AS " (sqlf/to-sql table-alias)))
210213

214+
(defmethod format-clause :except [[_ maps] _]
215+
(binding [sqlf/*subquery?* false]
216+
(string/join " EXCEPT " (map sqlf/to-sql maps))))
217+
218+
(defmethod format-clause :except-all [[_ maps] _]
219+
(binding [sqlf/*subquery?* false]
220+
(string/join " EXCEPT ALL " (map sqlf/to-sql maps))))
221+
211222
(override-default-clause-priority)
212223

213224
(defmethod format-modifiers :distinct-on [[_ & fields]]

test/honeysql_postgres/postgres_test.cljc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,41 @@
221221
(where [:not-ilike :name "%name%"])
222222
sql/format)))))
223223

224+
(deftest values-except-select
225+
(testing "select which values are not not present in a table"
226+
(is (= ["VALUES (?), (?), (?) EXCEPT SELECT id FROM images" 4 5 6]
227+
(sql/format
228+
{:except
229+
[{:values [[4] [5] [6]]}
230+
{:select [:id] :from [:images]}]})))))
231+
232+
233+
(deftest select-except-select
234+
(testing "select which rows are not present in another table"
235+
(is (= ["SELECT ip EXCEPT SELECT ip FROM ip_location"]
236+
(sql/format
237+
{:except
238+
[{:select [:ip]}
239+
{:select [:ip] :from [:ip_location]}]})))))
240+
241+
242+
(deftest values-except-all-select
243+
(testing "select which values are not not present in a table"
244+
(is (= ["VALUES (?), (?), (?) EXCEPT ALL SELECT id FROM images" 4 5 6]
245+
(sql/format
246+
{:except-all
247+
[{:values [[4] [5] [6]]}
248+
{:select [:id] :from [:images]}]})))))
249+
250+
251+
(deftest select-except-all-select
252+
(testing "select which rows are not present in another table"
253+
(is (= ["SELECT ip EXCEPT ALL SELECT ip FROM ip_location"]
254+
(sql/format
255+
{:except-all
256+
[{:select [:ip]}
257+
{:select [:ip] :from [:ip_location]}]})))))
258+
224259
(deftest select-distinct-on
225260
(testing "select distinct on"
226261
(is (= ["SELECT DISTINCT ON(\"a\", \"b\") \"c\" FROM \"products\" "]

0 commit comments

Comments
 (0)