honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
seancorfield 2021-02-13T00:24:50.117900Z

Q for folks using nilenso/honeysql-postgres: how many of you actually use alter-table (and the undocumented rename-table)? It looks like it doesn't currently let you have multiple altering clauses (e.g., alter table foo add column id int, drop column ident; type stuff). Would a syntax allowing multiple clauses be appreciated?

seancorfield 2021-02-13T00:28:57.120900Z

I'm thinking of something like:

{:alter-table :foo :add-column [:id :int]} ; single clause case
(-> (alter-table :foo) (add-column :id :int)) ; single clause helper version
;; proposed:
{:alter-table [:foo {:add-column [:id :int]} {:drop-column :ident}]} ; multi-clause case
(alter-table :foo (add-column :id :int) (:drop-column :ident)) ; multi-clause helper version

kwrooijen 2021-02-13T21:29:15.131700Z

Yes it would be nice to have!

kwrooijen 2021-02-13T21:30:38.132Z

I actually had to write my own to get it to work in Gungnir 😅 https://github.com/kwrooijen/gungnir/blob/ef0c9a25bb00792e27a6d07871bb82feb8aaf50d/src/clj/gungnir/extension/honeysql_postgres.clj#L46-L60

kwrooijen 2021-02-13T21:31:03.132400Z

If Honeysql would get first class support for creating / altering tables etc. It would simplify it for my library and I'd get rid of an extra dependency 🙂

kwrooijen 2021-02-13T21:32:45.132700Z

(I currently use this to implement my migration system)

seancorfield 2021-02-13T22:10:33.132900Z

@kevin.van.rooijen Thanks for the feedback -- I'm most of the way through integrating and testing the last few parts of the nilenso library this afternoon (`do update set` is giving me fits! 👀 ) but by Monday this should all be sorted out and documented (integrating all these clauses in a consistent manner has led to some divergence -- so I plan to write a full "differences" page in the documentation).

1👍
seancorfield 2021-02-13T05:38:29.121700Z

And another PG Q about that library: is anyone actually using create-extension and/or drop-extension? What on earth do those even mean?

kwrooijen 2021-02-13T20:50:56.131400Z

I use it to enable uuids

1
2021-02-13T06:26:28.121800Z

I don't use honeysql for ddl, but create and drop extension are for enabling and disabling postgres extensions (https://www.postgresql.org/docs/current/external-extensions.html), which are basically plug-ins adding functionality to postgres. For example, PostGIS is a popular extension adding spatial and geographic data types.

1
dharrigan 2021-02-13T07:47:18.123Z

Morning - whilst I don't use alter table/rename table clauses, perhaps in the name of completeness they should be included (if minimal work involved!)

dharrigan 2021-02-13T07:47:35.123300Z

Yeah, create and drop extensions are for installing extensions within schemas

dharrigan 2021-02-13T07:47:48.123700Z

for example "create extension postgis schema foo"

dharrigan 2021-02-13T07:47:56.124Z

would install the postgis extension into schema foo

dharrigan 2021-02-13T07:48:09.124300Z

there are lots of extensions

dharrigan 2021-02-13T07:53:51.125300Z

The problem, perhaps, with alter table (including it's rename variant) is there are tonnes of options on how to alter/create the table. <https://www.postgresql.org/docs/13/sql-altertable.html>

dharrigan 2021-02-13T07:54:15.125500Z

Would it be too much effort?

dharrigan 2021-02-13T07:55:33.127Z

The way I use those clauses (create schema, alter table etc...) is only in my migration scripts (I use flywaydb). Since i would expect these to run on application start.

seancorfield 2021-02-13T17:09:02.128600Z

@dharrigan Thanks for that feedback. I ended up implementing add/drop/modify/rename column and add/drop index. I may implement more if folks request it. I'll go ahead and implement create/drop extension then since nilenso does have it.

seancorfield 2021-02-13T17:09:52.129600Z

I also added rename table (that's in the nilenso library but not documented -- seems there are quite a few things implemented and not documented there, so at least they'll all get documented now in HoneySQL v2!)

dharrigan 2021-02-13T17:13:32.130200Z

I've finished off testing my application, works perfectly with minimal changes to support honeysql v2

seancorfield 2021-02-13T17:15:40.130400Z

Brilliant! Thank you!

seancorfield 2021-02-13T17:16:31.131100Z

Today I'm going to post over the nilenso test suite and adjust it to work with v2 to check I have everything implemented.

dharrigan 2021-02-13T17:19:49.131300Z

you're most welcome 🙂

kwrooijen 2021-02-13T20:50:56.131400Z

I use it to enable uuids

1
kwrooijen 2021-02-13T21:29:15.131700Z

Yes it would be nice to have!

kwrooijen 2021-02-13T21:30:38.132Z

I actually had to write my own to get it to work in Gungnir 😅 https://github.com/kwrooijen/gungnir/blob/ef0c9a25bb00792e27a6d07871bb82feb8aaf50d/src/clj/gungnir/extension/honeysql_postgres.clj#L46-L60

kwrooijen 2021-02-13T21:31:03.132400Z

If Honeysql would get first class support for creating / altering tables etc. It would simplify it for my library and I'd get rid of an extra dependency 🙂

kwrooijen 2021-02-13T21:32:45.132700Z

(I currently use this to implement my migration system)

seancorfield 2021-02-13T22:10:33.132900Z

@kevin.van.rooijen Thanks for the feedback -- I'm most of the way through integrating and testing the last few parts of the nilenso library this afternoon (`do update set` is giving me fits! 👀 ) but by Monday this should all be sorted out and documented (integrating all these clauses in a consistent manner has led to some divergence -- so I plan to write a full "differences" page in the documentation).

1👍