fixes #530 by supporting :using-gin in :create-index
Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
parent
bab4ce4bd5
commit
2c6bf85f7f
4 changed files with 19 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
* 2.6.next in progress
|
||||
* Address [#531](https://github.com/seancorfield/honeysql/issues/531) and [#527](https://github.com/seancorfield/honeysql/issues/527) by adding tests and more documentation for `:composite`; fix bug in `set-dialect!` where clause order is not restored.
|
||||
* Address [#530](https://github.com/seancorfield/honeysql/issues/530) by adding support for `:using-gin` to `:create-index`.
|
||||
* Address [#529](https://github.com/seancorfield/honeysql/issues/529) by fixing `:join` special syntax to support aliases and to handle expressions the same way `select` / `from` etc handle them (extra `[...]` nesting).
|
||||
* Add example of mixed `DO UPDATE SET` with `EXCLUDED` and regular SQL expressions.
|
||||
* Improve exception message when un-`lift`-ed JSON expressions are used in the DSL.
|
||||
|
|
|
|||
|
|
@ -141,6 +141,14 @@ user=> (sql/format (h/create-index [:unique :another-idx :if-not-exists] [:fruit
|
|||
["CREATE UNIQUE INDEX IF NOT EXISTS another_idx ON fruit (color, LOWER(appearance))"]
|
||||
```
|
||||
|
||||
`USING GIN` index creation is also possible using the keyword `:using-gin` after
|
||||
the table name (or the symbol `using-gin`):
|
||||
|
||||
```clojure
|
||||
user=> (sql/format {:create-index [:my-idx [:fruit :using-gin :appearance]]})
|
||||
["CREATE INDEX my_idx ON fruit USING GIN (appearance)"]
|
||||
```
|
||||
|
||||
### rename-table
|
||||
|
||||
Used with `:alter-table`,
|
||||
|
|
|
|||
|
|
@ -1267,10 +1267,14 @@
|
|||
(defn- format-create-index [k clauses]
|
||||
(let [[index-spec [table & exprs]] clauses
|
||||
[pre entity ine & more] (destructure-ddl-item index-spec (str (sql-kw k) " options"))
|
||||
[using & exprs] (if (= :using-gin (first exprs))
|
||||
exprs
|
||||
(cons nil exprs))
|
||||
[sqls params] (format-expr-list exprs)]
|
||||
(into [(str/join " " (remove empty?
|
||||
(-> ["CREATE" pre "INDEX" ine entity
|
||||
"ON" (format-entity table)
|
||||
(when using (sql-kw using))
|
||||
(str "(" (str/join ", " sqls) ")")]
|
||||
(into more))))]
|
||||
params)))
|
||||
|
|
|
|||
|
|
@ -980,7 +980,12 @@
|
|||
(is (= ["CREATE UNIQUE INDEX IF NOT EXISTS my_column_idx ON my_table (my_column)"]
|
||||
(sql/format (create-index [:unique :my-column-idx :if-not-exists] [:my-table :my-column]))))
|
||||
(is (= ["CREATE INDEX my_column_idx ON my_table (LOWER(my_column))"]
|
||||
(sql/format (create-index :my-column-idx [:my-table :%lower.my-column]))))))
|
||||
(sql/format (create-index :my-column-idx [:my-table :%lower.my-column])))))
|
||||
(testing "PostgreSQL extensions (USING GIN)"
|
||||
(is (= ["CREATE INDEX my_column_idx ON my_table USING GIN (my_column)"]
|
||||
(sql/format {:create-index [:my-column-idx [:my-table :using-gin :my-column]]})))
|
||||
(is (= ["CREATE INDEX my_column_idx ON my_table USING GIN (my_column)"]
|
||||
(sql/format (create-index :my-column-idx [:my-table :using-gin :my-column]))))))
|
||||
|
||||
(deftest join-with-alias
|
||||
(is (= ["SELECT * FROM foo LEFT JOIN (populatons AS pm INNER JOIN customers AS pc ON (pm.id = pc.id) AND (pm.other_id = pc.other_id)) ON foo.fk_id = pm.id"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue