Switch to seancorfield/readme for deps.edn run
This commit is contained in:
parent
9fb3d42660
commit
5bc1fafddd
2 changed files with 19 additions and 10 deletions
25
README.md
25
README.md
|
|
@ -312,6 +312,8 @@ Keywords that begin with `%` are interpreted as SQL function calls:
|
||||||
```clojure
|
```clojure
|
||||||
(-> (select :%count.*) (from :foo) sql/format)
|
(-> (select :%count.*) (from :foo) sql/format)
|
||||||
=> ["SELECT count(*) FROM foo"]
|
=> ["SELECT count(*) FROM foo"]
|
||||||
|
```
|
||||||
|
```clojure
|
||||||
(-> (select :%max.id) (from :foo) sql/format)
|
(-> (select :%max.id) (from :foo) sql/format)
|
||||||
=> ["SELECT max(id) FROM foo"]
|
=> ["SELECT max(id) FROM foo"]
|
||||||
```
|
```
|
||||||
|
|
@ -338,12 +340,14 @@ qualifiers, raw SQL fragments, inline values, and named input parameters:
|
||||||
(-> (select (sql/call :foo :bar) (sql/qualify :foo :a) (sql/raw "@var := foo.bar"))
|
(-> (select (sql/call :foo :bar) (sql/qualify :foo :a) (sql/raw "@var := foo.bar"))
|
||||||
(from :foo)
|
(from :foo)
|
||||||
(where [:= :a (sql/param :baz)] [:= :b (sql/inline 42)])))
|
(where [:= :a (sql/param :baz)] [:= :b (sql/inline 42)])))
|
||||||
|
```
|
||||||
|
```clojure
|
||||||
call-qualify-map
|
call-qualify-map
|
||||||
=> '{:where [:and [:= :a #sql/param :baz] [:= :b #sql/inline 42]]
|
=> '{:where [:and [:= :a #sql/param :baz] [:= :b #sql/inline 42]]
|
||||||
:from (:foo)
|
:from (:foo)
|
||||||
:select (#sql/call [:foo :bar] :foo.a #sql/raw "@var := foo.bar")}
|
:select (#sql/call [:foo :bar] :foo.a #sql/raw "@var := foo.bar")}
|
||||||
|
```
|
||||||
|
```clojure
|
||||||
(sql/format call-qualify-map :params {:baz "BAZ"})
|
(sql/format call-qualify-map :params {:baz "BAZ"})
|
||||||
=> ["SELECT foo(bar), foo.a, @var := foo.bar FROM foo WHERE (a = ? AND b = 42)" "BAZ"]
|
=> ["SELECT foo(bar), foo.a, @var := foo.bar FROM foo WHERE (a = ? AND b = 42)" "BAZ"]
|
||||||
```
|
```
|
||||||
|
|
@ -455,7 +459,8 @@ Here's a big, complicated query. Note that Honey SQL makes no attempt to verify
|
||||||
(order-by [:b.baz :desc] :c.quux [:f.a :nulls-first])
|
(order-by [:b.baz :desc] :c.quux [:f.a :nulls-first])
|
||||||
(limit 50)
|
(limit 50)
|
||||||
(offset 10)))
|
(offset 10)))
|
||||||
|
```
|
||||||
|
```clojure
|
||||||
big-complicated-map
|
big-complicated-map
|
||||||
=> {:select [:f.* :b.baz :c.quux [:b.bla "bla-bla"]
|
=> {:select [:f.* :b.baz :c.quux [:b.bla "bla-bla"]
|
||||||
(sql/call :now) (sql/raw "@x := 10")]
|
(sql/call :now) (sql/raw "@x := 10")]
|
||||||
|
|
@ -474,7 +479,8 @@ big-complicated-map
|
||||||
:order-by [[:b.baz :desc] :c.quux [:f.a :nulls-first]]
|
:order-by [[:b.baz :desc] :c.quux [:f.a :nulls-first]]
|
||||||
:limit 50
|
:limit 50
|
||||||
:offset 10}
|
:offset 10}
|
||||||
|
```
|
||||||
|
```clojure
|
||||||
(sql/format big-complicated-map {:param1 "gabba" :param2 2})
|
(sql/format big-complicated-map {:param1 "gabba" :param2 2})
|
||||||
=> [#sql/regularize
|
=> [#sql/regularize
|
||||||
"SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10
|
"SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10
|
||||||
|
|
@ -492,7 +498,8 @@ big-complicated-map
|
||||||
LIMIT ?
|
LIMIT ?
|
||||||
OFFSET ? "
|
OFFSET ? "
|
||||||
"bort" "gabba" 1 2 2 3 1 2 3 10 20 0 50 10]
|
"bort" "gabba" 1 2 2 3 1 2 3 10 20 0 50 10]
|
||||||
|
```
|
||||||
|
```clojure
|
||||||
;; Printable and readable
|
;; Printable and readable
|
||||||
(= big-complicated-map (read-string (pr-str big-complicated-map)))
|
(= big-complicated-map (read-string (pr-str big-complicated-map)))
|
||||||
=> true
|
=> true
|
||||||
|
|
@ -504,27 +511,27 @@ You can define your own function handlers for use in `where`:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(require '[honeysql.format :as fmt])
|
(require '[honeysql.format :as fmt])
|
||||||
|
```
|
||||||
|
```clojure
|
||||||
(defmethod fmt/fn-handler "betwixt" [_ field lower upper]
|
(defmethod fmt/fn-handler "betwixt" [_ field lower upper]
|
||||||
(str (fmt/to-sql field) " BETWIXT "
|
(str (fmt/to-sql field) " BETWIXT "
|
||||||
(fmt/to-sql lower) " AND " (fmt/to-sql upper)))
|
(fmt/to-sql lower) " AND " (fmt/to-sql upper)))
|
||||||
|
|
||||||
(-> (select :a) (where [:betwixt :a 1 10]) sql/format)
|
(-> (select :a) (where [:betwixt :a 1 10]) sql/format)
|
||||||
=> ["SELECT a WHERE a BETWIXT ? AND ?" 1 10]
|
=> ["SELECT a WHERE a BETWIXT ? AND ?" 1 10]
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also define your own clauses:
|
You can also define your own clauses:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
|
|
||||||
;; Takes a MapEntry of the operator & clause data, plus the entire SQL map
|
;; Takes a MapEntry of the operator & clause data, plus the entire SQL map
|
||||||
(defmethod fmt/format-clause :foobar [[op v] sqlmap]
|
(defmethod fmt/format-clause :foobar [[op v] sqlmap]
|
||||||
(str "FOOBAR " (fmt/to-sql v)))
|
(str "FOOBAR " (fmt/to-sql v)))
|
||||||
|
|
||||||
(sql/format {:select [:a :b] :foobar :baz})
|
(sql/format {:select [:a :b] :foobar :baz})
|
||||||
=> ["SELECT a, b FOOBAR baz"]
|
=> ["SELECT a, b FOOBAR baz"]
|
||||||
|
```
|
||||||
|
```clojure
|
||||||
(require '[honeysql.helpers :refer [defhelper]])
|
(require '[honeysql.helpers :refer [defhelper]])
|
||||||
|
|
||||||
;; Defines a helper function, and allows 'build' to recognize your clause
|
;; Defines a helper function, and allows 'build' to recognize your clause
|
||||||
|
|
|
||||||
4
deps.edn
4
deps.edn
|
|
@ -11,4 +11,6 @@
|
||||||
{:git/url "https://github.com/cognitect-labs/test-runner"
|
{:git/url "https://github.com/cognitect-labs/test-runner"
|
||||||
:sha "76568540e7f40268ad2b646110f237a60295fa3c"}}
|
:sha "76568540e7f40268ad2b646110f237a60295fa3c"}}
|
||||||
:main-opts ["-m" "cognitect.test-runner"
|
:main-opts ["-m" "cognitect.test-runner"
|
||||||
"-d" "test"]}}}
|
"-d" "test"]}
|
||||||
|
:readme {:extra-deps {seancorfield/readme {:mvn/version "1.0.8"}}
|
||||||
|
:main-opts ["-m" "seancorfield.readme"]}}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue