honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
zackteo 2021-02-16T11:42:16.166600Z

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)

dharrigan 2021-02-16T11:42:52.166800Z

That's the approach I take

dharrigan 2021-02-16T11:42:56.167Z

It works fine

dharrigan 2021-02-16T11:43:10.167500Z

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

dharrigan 2021-02-16T11:44:09.167800Z

i.e.,

dharrigan 2021-02-16T11:44:11.168Z

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

dharrigan 2021-02-16T11:44:31.168300Z

anything starting with a : is interpreted as a function call

dharrigan 2021-02-16T11:45:01.168500Z

(that is in honeysql v2 syntax)

zackteo 2021-02-16T13:14:54.170Z

Cool, excited to get this working! 🙂

zackteo 2021-02-16T13:15:09.170400Z

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

dharrigan 2021-02-16T13:23:56.170600Z

yes

dharrigan 2021-02-16T13:24:21.171Z

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

👍 1
seancorfield 2021-02-16T16:59:23.172600Z

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

seancorfield 2021-02-16T16:59:35.172900Z

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