Honey SQL – SQL as Clojure data structures
1–10 of 31 posts
Re: Honey SQL – SQL as Clojure data structures
#2In case anyone needs it for mysql, the following adds basic support for "on duplicate key update" clauses:
(defmethod sql-format/format-clause :upsert [[_ updates] _]
(let [parts (for [[column value] updates]
(str (sql-format/to-sql column) "=" (sql-format/to-sql value)))]
(str "ON DUPLICATE KEY UPDATE " (string/join "," parts))))
(sql-helpers/defhelper upsert [m [updates]]
(assoc m :upsert updates))Re: Honey SQL – SQL as Clojure data structures
#3Re: Honey SQL – SQL as Clojure data structures
#4What the heck? This makes me hate SQL and Clojure....
I definitely would be interested, since I am a current user. Its always good to get a differing perspective on your tools.
Re: Honey SQL – SQL as Clojure data structures
#5Also worth looking into are clojure.spec, Datomic, hiccup, rum
Re: Honey SQL – SQL as Clojure data structures
#6After dealing with ActiveRecord for the past few years, I'm ready to just be able to write plain old SQL again. It seems like yesql is a pretty sweet solution, but I haven't tried it in earnest.
Re: Honey SQL – SQL as Clojure data structures
#7Curious to hear if anyone uses yesql or similar[1]. I'd really be interested in hearing from someone who has used Honey SQL and yesql and can compare/contrast. After dealing with ActiveRecord for the past few years, I'm ready to just be able to write plain old SQL again. It seems like yesql is a pretty sweet solution, but I haven't tried it in earnest. [1] https://github.com/krisajenkins/yesql
As soon as I had to dynamically build queries (essential when moving beyond the complexity of "select this user record") I ran into issues with yesql's lack of power.
It also fits closer to one of the main principles of clojure, to be data-driven/data-first/just-use-data etc etc
Re: Honey SQL – SQL as Clojure data structures
#8There is some learning curve figuring put how things work, but the advantages of having SQL encoded as clojure data are worth it, in my opinion:
- s-expressions everywhere means that structural editing works
- allows for easy composing of sql queries - can very easily add custom filters, joins, etc and build up queries dynamically
- can easily add abstractions, for example something like https://github.com/metabase/toucan/blob/master/README.md
If you use postgresql, check out: https://github.com/nilenso/honeysql-postgres/blob/master/REA...
Re: Honey SQL – SQL as Clojure data structures
#9Curious to hear if anyone uses yesql or similar[1]. I'd really be interested in hearing from someone who has used Honey SQL and yesql and can compare/contrast. After dealing with ActiveRecord for the past few years, I'm ready to just be able to write plain old SQL again. It seems like yesql is a pretty sweet solution, but I haven't tried it in earnest. [1] https://github.com/krisajenkins/yesql
On the other hand if you need dynamic queries, then yes dsl is more suited, as well as for other query types where the dsl can be much better at handling multiple records at once... like say inserting 10 rows at once.
So to sum up:
* complex select queries - templated queries really shine
* simple dynamic queries - templates for simple replacements
* complex dynamic queries - dsl
* inserts/updates/deletes - dsl
* portable sql - dsl
Re: Honey SQL – SQL as Clojure data structures
#10Honey SQL is a great example for how elegant and powerful data-centric APIs can be. Also worth looking into are clojure.spec, Datomic, hiccup, rum