honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
Johannes F. Knauf 2020-05-20T04:02:56.031Z

On #sql we had a little discussion about vendor specific adapters for honeysql. It boiled down to the question, how much vendor-awareness is really desirable for honeysql. I think an example explains it best. Currently the translation of DSL to SQL in honeysql is quite literal, e.g. :limit 10 translates to "LIMIT 10", which is straightforward, but meaningless for most dialects (e.g. Oracle, DB2, MS SQL, ...), i.e. even syntactically wrong. Should honeysql focus on semantic meaning and translate to vendor-specific dialects or should it process syntax regardless of the DB vendor used? What is the design intention?

seancorfield 2020-05-20T04:09:47.031600Z

:limit is a bad example -- and was added before I took over the project -- since it is DB-specific.

seancorfield 2020-05-20T04:10:22.032400Z

The guiding principle for HoneySQL is that it should implement SQL-92 only and all DB-specific extensions should be in other libraries.

Johannes F. Knauf 2020-05-25T10:40:06.036300Z

Well, actually my scenario can be well covered with the status quo right now. Now that I know how the design philosophy is, it is easy to accept and provide local helpers for special constructs. However, my original solution idea would require something like that, yes. It would require some dynamic translation layer from Pure Clojure Query Representations to dialect-specific SQL queries. The problem is: What would the pure representation look like? That endeavour is the same as creating a new, feature-enhanced SQL standard. I mean a pragmatic starting point would be to just elevate PostgreSQL to the de-facto-standard and translate from Postgres to other dialects.

seancorfield 2020-05-25T16:52:01.043600Z

@johannes.f.knauf Unfortunately PostgreSQL has a lot of features that other databases don't have so there would be a lot of stuff that couldn't be translated to other database dialects.

seancorfield 2020-05-25T16:52:54.043800Z

(and such a library wouldn't come from me since I don't use PostgreSQL)

Johannes F. Knauf 2020-05-25T19:45:54.044Z

That is all true. The question is: Do we have a better candidate for some meta-SQL covering a good amount of the common cross-provider query features?

seancorfield 2020-05-20T04:10:42.032800Z

That principle hasn't always been followed -- hence :limit

seancorfield 2020-05-20T04:12:05.034200Z

There are some complex issues tho'. update/`set` seems to have different precedence in PostgreSQL vs MySQL for example, so HoneySQL has to support :set0 and :set1 for the two different precedences.

Johannes F. Knauf 2020-05-20T04:12:51.034400Z

Is https://github.com/nilenso/honeysql-postgres a good example for that practice?

seancorfield 2020-05-20T04:13:30.034800Z

Yes.

Johannes F. Knauf 2020-05-20T04:18:02.035100Z

If I understand that right, this implies: these libraries should just add syntax and map 1:1 between DSL and SQL statements. It's the user's responsibility to use the proper vendor-specific terms. (As you already mentioned in #sql, porting between databases is a rare occasion and hence considered a non-issue.) Correct?

seancorfield 2020-05-20T04:22:07.035300Z

No, what I said was that you -- or any library maintainers -- could add a common DSL with a different implementation in each library.

seancorfield 2020-05-20T04:22:19.035500Z

So far no one has wanted to do that.

seancorfield 2020-05-20T04:22:40.035700Z

Or at least, no one has been sufficiently motivated to contribute it.

seancorfield 2020-05-20T04:23:06.035900Z

Right now, that PostgreSQL-specific library is the only DB-specific extension library that I know of.

seancorfield 2020-05-20T04:25:56.036100Z

Specifically, no one has been motivated to provide a way to have format render different SQL based on some configuration -- I think it would have to be dynamic, so you could switch dialects on a per-call basis. Which is what I think you would need for the scenario you are suggesting @johannes.f.knauf?