honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
maxp 2020-09-15T10:25:22.015400Z

@seancorfield - could you advise me how to make LATERAL join?

dharrigan 2020-09-15T10:34:24.016400Z

Honeysql doesn't support lateral joins (atm) as it's very PostgreSQL specific, whereas honeysql is meant to be more vendor netural. I would suggest if you need a lateral join to drop to doing raw sql

dharrigan 2020-09-15T10:34:59.016600Z

join, :merge-join
      :left-join, :merge-left-join
      :right-join, :merge-right-join
      :full-join, :merge-full-join
      :cross-join, :merge-cross-join

dharrigan 2020-09-15T10:35:04.016800Z

are the things it supports

seancorfield 2020-09-15T16:29:15.017400Z

@maxp It would be relatively easy to add it yourself by extending the multi-methods in HoneySQL if you wanted.

seancorfield 2020-09-15T16:36:12.019300Z

My feeling in HoneySQL 2.0 (which is still in "hammock mode") is that essentially arbitrary keywords should be auto-translatable (from :kebab-case to KEBAB CASE) but there will need to be some guidance somewhere about priorities of clauses (since everything goes through a hash map and that is inherently unordered).

dominicm 2020-09-15T16:43:15.020300Z

@seancorfield you've mentioned honey2.0 in a couple of places. It sounds "breaking", why not create GoldenSyrupSQL instead?

seancorfield 2020-09-15T16:50:25.021Z

It will have new namespaces at least, possibly a whole new library, but I'd like to preserve the underlying data format if I can (so migration is easier).

seancorfield 2020-09-15T16:52:52.023200Z

It will definitely be breaking for anyone who is extending HoneySQL today because one of my main goals is to make extension a lot easier! Right now you have to extend it in several places just to add a simple new clause, which is a lot of work. For example, supporting a lateral join should be at most the declaration of its relative priority compared to other clauses, if that's at all possible.

seancorfield 2020-09-15T16:54:34.024800Z

It will almost certainly support "dialects" out of the box, instead of just trying to stay "pure" and portable. It will have a base level of ANSI SQL and then a "layer" for each DB that is notably different (primarily MySQL, PostgreSQL, and SQL Server I suspect but I'm happy to support "any" SQL dialect).

seancorfield 2020-09-15T16:58:41.026700Z

I want to try and support a variety of "syntactic shapes" out of the box so using "unknown" operators and/or functions is a lot easier. For example, some expressions are just joined together with spaces, some have commas, some are infix, some are prefix, some always get parenthesized, some can have parens, some can't...

dharrigan 2020-09-15T17:00:57.027100Z

Happy to see all that and do some testing with whatever pops out 🙂

dominicm 2020-09-15T17:08:02.027500Z

I'd love to see the builder functions disappear...

seancorfield 2020-09-15T17:14:00.028500Z

I use the builder functions almost exclusively so, no. But they will get simplified. The whole merge vs non-merge thing is confusing and somewhat pointless.

seancorfield 2020-09-15T17:14:42.029100Z

But they should be generated consistently from a data structure that describes the available keywords perhaps.

seancorfield 2020-09-15T17:18:36.031900Z

I find this much more readable

(-> (select :*)
    (from [:table :t])
    (where [:= :id 42])
    (join [:other :o] [:= :o.id :t.otherid])) 
than this
(-> {:select [:*]}
    (assoc :from [:table :t])
    (assoc :where [:= :id 42])
    (assoc :join [[:other :o] [:= :o.id :t.otherid]]))

👍 2
seancorfield 2020-09-15T17:19:31.033Z

(and in fact that is wrong, it should be (assoc :from [[:table :t]]) and that whole do I wrap it with a vector / don't I? question is why I avoid the data structure approach -- but some people find the helper approach just as confusing)

dominicm 2020-09-15T17:29:55.033700Z

Why would you be associating at all? Most of my queries are whole maps with a tiny bit of dynamism.

dominicm 2020-09-15T17:34:20.034800Z

I think the fact the documentation omits the data structure form is what has always irked me. I have to run the helper to find out what the data looks like.

orestis 2020-09-15T17:58:22.035400Z

Most of my queries are a base query with a shit ton of dynamism 😜

orestis 2020-09-15T17:58:42.035900Z

I’ve had to write my own merge-with helper

seancorfield 2020-09-15T18:38:51.037300Z

Same here: we have tons of functions that conditionally add in all sorts of select/join/where clause fragments. That's why we use HoneySQL in the first place. If we had mostly static queries, we'd probably just use string-bashing.

seancorfield 2020-09-15T18:39:33.038Z

The documentation for 2.0 will definitely include lots of detail about the data structure and I will write Specs for it I expect.