Live data from Hacker News

Honey SQL – SQL as Clojure data structures

github.com

1–10 of 31 posts

Re: Honey SQL – SQL as Clojure data structures

#2
I'm currently using honeysql in clojure projects at work, it's definitely my favourite option for interfacing with mysql (although would of course rather use datomic, but then what patriotic clojure fan wouldn't?).

In 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

#4
post #3

What the heck? This makes me hate SQL and Clojure....

You may find your comment turning less gray if you articulated the issues you see with this lib.

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

#6
Curious 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

Re: Honey SQL – SQL as Clojure data structures

#7

Curious 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

I found yesql inadaquete for use with anything other than simple queries. Writing plain SQL is definitely nicer than an ORM, however, I find that manipulating SQL as data (honeysql) is far superior to .sql files with added magic (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

#8
I recently started using honeysql and so far it has been great.

There 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

#9

Curious 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

I've found templated queries(e.g. yesql) are far preferable for complex selects/joins/subselects and just can't imagine using the data structure dsl for such queries. One huge downside of dsl queries is that they NEVER support the full sql syntax of any database, in my case postgres. The best part is being able to write the query in a sql editor then copy/paste directly, rather than needing to translate into a dsl.

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

Post reply on HN