Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
Sean Corfield 2024-01-06 11:38:45 -08:00
parent d0193d3c10
commit 2e34a9f4ea
No known key found for this signature in database
4 changed files with 23 additions and 7 deletions

View file

@ -1,6 +1,7 @@
# Changes
* 2.5.next in progress
* Fix [#518](https://github.com/seancorfield/honeysql/issues/518) by moving temporal clause before alias.
* Implemented `CREATE INDEX` [#348](https://github.com/seancorfield/honeysql/issues/348) via PR [#517](https://github.com/seancorfield/honeysql/pull/517) [@dancek](https://github.com/dancek).
* 2.5.1103 -- 2023-12-03

View file

@ -825,7 +825,7 @@ user=> (sql/format {:select [:username]
user=> (sql/format {:select [:u.username]
:from [[:user :u :for :system-time :from [:inline "2019-08-01 15:23:00"] :to [:inline "2019-08-01 15:24:00"]]]
:where [:= :u.id 9]})
["SELECT u.username FROM user AS u FOR SYSTEM_TIME FROM '2019-08-01 15:23:00' TO '2019-08-01 15:24:00' WHERE u.id = ?" 9]
["SELECT u.username FROM user FOR SYSTEM_TIME FROM '2019-08-01 15:23:00' TO '2019-08-01 15:24:00' AS u WHERE u.id = ?" 9]
```
> Note: the actual formatting of a `:from` clause is currently identical to the formatting of a `:select` clause.

View file

@ -568,6 +568,8 @@
(format-temporal temporal))]
(-> [(str sql
(when sql''
(str " " sql''))
(when sql'
(str (if as
(if (and (contains? *dialect* :as)
@ -575,9 +577,7 @@
" "
" AS ")
" ")
sql'))
(when sql''
(str " " sql'')))]
sql')))]
(into params)
(into params')
(into params'')))))
@ -2383,7 +2383,13 @@
(sql/format {:select [[:column-name :'some-alias]]
:from :b
:order-by [[[:alias :'some-alias]]]})
;; this was an earlier (and incorrect!) workaround for temporal queries:
(sql/format {:select :f.* :from [[:foo [:f :FOR :SYSTEM-TIME]]] :where [:= :f.id 1]})
;; this is the correct way to do it:
(sql/format {:select :f.* :from [[:foo :f :for :system-time]] :where [:= :f.id 1]})
(sql/format {:select [:u.username]
:from [[:user :u :for :system-time :from [:inline "2019-08-01 15:23:00"] :to [:inline "2019-08-01 15:24:00"]]]
:where [:= :u.id 9]})
(sql/format {:using [[:source [:= :table.id :source.id]]]})
;; #389 -- ONLY for from/join etc:
@ -2402,6 +2408,12 @@
(sql/register-clause! :overriding-system-value
(fn [_ _] ["OVERRIDING SYSTEM VALUE"])
:values)
(sql/format-expr-list [:foo/id] {:drop-ns false})
(sql/format-expr-list [:foo/id] {:drop-ns true})
(sql/format-expr-list [:'foo/id] {:drop-ns true})
(sql/format-expr-list [(keyword "foo/foo/id")] {:drop-ns false})
(sql/format-expr-list [(keyword "foo/foo/id")] {:drop-ns true})
(sql/format {:insert-into :foo :values [{:foo/id 1}]})
(sql/format {:insert-into :foo :values [{:id 1}] :overriding-system-value true})
(sql/format {:insert-into [{:overriding-value :system}
[:transport :t] [:id :name]]

View file

@ -1055,7 +1055,7 @@ ORDER BY id = ? DESC
(is (= ["SELECT \"A\"\"B\""] (sut/format {:select (keyword "A\"B")} {:dialect :oracle}))))
(deftest issue-407-temporal
(is (= ["SELECT f.* FROM foo AS f FOR SYSTEM_TIME ALL WHERE f.id = ?" 1]
(is (= ["SELECT f.* FROM foo FOR SYSTEM_TIME ALL AS f WHERE f.id = ?" 1]
(sut/format {:select :f.* :from [[:foo :f :for :system-time :all]] :where [:= :f.id 1]})))
(is (= ["SELECT * FROM foo FOR SYSTEM_TIME ALL WHERE id = ?" 1]
(sut/format {:select :* :from [[:foo :for :system-time :all]] :where [:= :id 1]}))))
@ -1310,5 +1310,8 @@ ORDER BY id = ? DESC
:quoted false})))))
(comment
;; partial workaround for #407:
(sut/format {:select :f.* :from [[:foo [:f :for :system-time]]] :where [:= :f.id 1]}))
;; partial (incorrect!) workaround for #407:
(sut/format {:select :f.* :from [[:foo [:f :for :system-time]]] :where [:= :f.id 1]})
;; correct version:
(sut/format {:select :f.* :from [[:foo :f :for :system-time]] :where [:= :f.id 1]})
)