Skip to content

Commit

Permalink
add formatf experiment #495
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Jun 23, 2023
1 parent e7972ac commit e679e93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changes

* 2.4.next in progress
* Address [#495](https://github.com/seancorfield/honeysql/issues/495) by adding (experimental) `formatf` function. Documentation TBD.
* Fix [#494](https://github.com/seancorfield/honeysql/issues/494) by supporting expressions in `:on-conflict` instead of just entities.
* Address [#493](https://github.com/seancorfield/honeysql/issues/493) by clarifying use of `:values` in CTEs (using `:with`).
* Address [#489](https://github.com/seancorfield/honeysql/issues/489) by adding more examples around `:update`.
Expand Down
9 changes: 9 additions & 0 deletions src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,13 @@
(mapv #(unwrap % opts) (formatter data opts))))))
([data k v & {:as opts}] (format data (assoc opts k v))))

(defn formatf
"Experimental implementation of https://github.com/seancorfield/honeysql/issues/495
Currently, does not support options."
[dsl & params]
(format dsl {:params (zipmap (map (comp keyword str inc) (range)) params)}))

(defn set-dialect!
"Set the default dialect for formatting.
Expand Down Expand Up @@ -2074,4 +2081,6 @@
(sql/register-fn! :foo foo-formatter)

(sql/format {:select [:*], :from [:table], :where [:foo [:+ :a 1]]})
(sql/formatf '{select * from table where (foo (+ a 1))})
(sql/formatf '{select * from table where (foo (+ a ?1))} 42)
)

0 comments on commit e679e93

Please sign in to comment.