diff --git a/CHANGELOG.md b/CHANGELOG.md index b294c8e..8b1ffbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # Changes * 2.0.0-alpha3 in progress + * Support much richer range of syntax on `CREATE`/`DROP` statements in general, including columns, `TABLESPACE`, `CASCADE`, `WITH [NO] DATA`, etc. + * Fix #306 by supporting `CREATE TABLE .. AS ..`. * Fix #305 by supporting more complex join clauses. + * Fix #301 by adding support for `CREATE`/`DROP`/`REFRESH` on `MATERIALIZED VIEW`. * Add tests to confirm #299 does not affect v2. * Confirm the whole of the [nilenso/honeysql-postgres](https://github.com/nilenso/honeysql-postgres) is implemented out-of-the-box (#293). * Reconcile `where` behavior with recent 1.0 changes (porting #283 to v2). + * Fix #280 by adding `:escape` as special syntax for regular expression patterns. * Fix #277 by adding `:join-by`/`join-by` so that you can have multiple `JOIN`'s in a specific order. * 2.0.0-alpha2 (for early testing) diff --git a/doc/special-syntax.md b/doc/special-syntax.md index 54512ab..e191a82 100644 --- a/doc/special-syntax.md +++ b/doc/special-syntax.md @@ -67,6 +67,11 @@ SQL entity. This is intended for use in contexts that would otherwise produce a sequence of SQL keywords, such as when constructing DDL statements. +## escape + +Intended to be used with regular expression patterns to +specify the escape characters (if any). + ## inline Accepts a single argument and tries to render it as a diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 6416b78..5eeb92d 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -943,6 +943,13 @@ (fn [_ [& args]] (let [[sqls params] (format-expr-list args)] (into [(str "(" (str/join ", " sqls) ")")] params))) + :escape + (fn [_ [pattern escape-chars]] + (let [[sql-p & params-p] (format-expr pattern) + [sql-e & params-e] (format-expr escape-chars)] + (-> [(str sql-p " " (sql-kw :escape) " " sql-e)] + (into params-p) + (into params-e)))) :inline (fn [_ [x]] (if (sequential? x) diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 3a475b6..dfdb7e8 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -294,6 +294,12 @@ [[1 2] [3 4] [5 6]])}]]}) ["WITH bar (spam, eggs) AS (VALUES (1, 2), (3, 4), (5, 6)) (SELECT foo FROM bar1) UNION (SELECT foo FROM bar2)"])))) +(deftest similar-regex-tests + (testing "basic similar to" + (is (= (format {:select :* :from :foo + :where [:similar-to :foo [:escape "bar" [:inline "*"]]]}) + ["SELECT * FROM foo WHERE foo SIMILAR TO ? ESCAPE '*'" "bar"])))) + (deftest former-parameterizer-tests-where-and ;; I have no plans for positional parameters -- I just don't see the point #_(testing "should ignore a nil predicate -- fail: postgresql parameterizer"