Add PostGIS example

A lot of people ask about this so having it in the README should help 
head off those questions!
This commit is contained in:
Sean Corfield 2019-10-19 12:12:23 -07:00
parent a732815b37
commit 370ff4f45d

View file

@ -19,7 +19,7 @@ All sample code in this README is automatically run as a unit test using
Note that while some of these samples show pretty-printed SQL, this is just for
README readability; honeysql does not generate pretty-printed SQL.
The #sql/regularize directive tells the test-runner to ignore the extraneous
The `#sql/regularize` directive tells the test-runner to ignore the extraneous
whitespace.
## Usage
@ -326,6 +326,21 @@ call-qualify-map
=> ["SELECT foo(bar), foo.a, @var := foo.bar FROM foo WHERE (a = ? AND b = 42)" "BAZ"]
```
A common example in the wild is the PostGIS extension to PostgreSQL where you
have a lot of function calls needed in code:
```clojure
(-> (insert-into :sample)
(values [{:location (sql/call :ST_SetSRID
(sql/call :ST_MakePoint 0.291 32.621)
(sql/call :cast 4326 :integer))}])
(sql/format))
=> [#sql/regularize
"INSERT INTO sample (location)
VALUES (ST_SetSRID(ST_MakePoint(?, ?), CAST(? AS integer)))"
0.291 32.621 4326]
```
Raw SQL fragments that are strings are treated exactly as-is when rendered into
the formatted SQL string (with no parsing or parameterization). Inline values
will not be lifted out as parameters, so they end up in the SQL string as-is.