Fork me on GitHub
#honeysql
<
2021-02-16
>
zackteo11:02:16

Hello! I was looking for a query builder for PostGIS and was directed to HoneySQL. I understand that there is no PostGIS support but might something like this work through JDBC?

(def postgis-map {:select [:city/name :state/name :city/geom]
                  :from   [:city]
                  :join   [:state (sql/raw ["ST_Intersects(" :city/geom ", " :state/geom ")"])]})

(sql/format postgis-map :namespace-as-table? true)
;; => ["SELECT city.name, state.name, city.geom FROM city INNER JOIN state ON ST_Intersects(city.geom, state.geom)"]
Am trying to see if I can compose PostGIS queries by simply using sql/raw and sql/forma which seems to work 🙂 Any advice on how I might want to improve my approach to this? And just wondering if there is anything I should be aware of when linking up to JDBC to PostgreSQL + PostGIS (extension)

dharrigan11:02:52

That's the approach I take

dharrigan11:02:56

It works fine

dharrigan11:02:10

With honeysql v2, out in due course, it becomes a lot easier

dharrigan11:02:11

(defn location->st-point
  [{:keys [lat lng] :as location}]
  [[:ST_SetSRID [:ST_MakePoint (round6 lng) (round6 lat)] [:cast 4326 :integer]]])

dharrigan11:02:31

anything starting with a : is interpreted as a function call

dharrigan11:02:01

(that is in honeysql v2 syntax)

zackteo13:02:54

Cool, excited to get this working! 🙂

zackteo13:02:09

On a sidenote, is there a place I can look at the unstable(?) implementation of honeysql v2?

dharrigan13:02:21

seancorfield/honeysql {:mvn/version "2.0.0-alpha1"}

👍 3
seancorfield16:02:23

@zackteo Even 1.x supports PostGIS expressions -- there's a section in the README about it: https://github.com/seancorfield/honeysql/#postgis /cc @dharrigan

seancorfield16:02:35

(and, yes, 2.x makes this even easier)