honeysql

Jakub Holý (HolyJak) 2023-04-17T10:04:46.206689Z

Hello, good people! I am not able to find out how to make Honey produce truncate table cascade I have tried (assoc (hh/truncate _:table_) :raw "cascade") but that renders "CASCADE TRUNCATE table" 😭 🙏

p-himik 2023-04-17T10:08:11.665309Z

(sql/format {:truncate [:my-table :cascade]})
=> ["TRUNCATE my_table CASCADE"]

p-himik 2023-04-17T10:08:54.732339Z

And with a helper function:

(sql/format (hh/truncate [:my-table :cascade]))
=> ["TRUNCATE my_table CASCADE"]

Jakub Holý (HolyJak) 2023-04-17T10:20:24.675789Z

many thanks! I would never have figured that out 😅

p-himik 2023-04-17T10:24:34.160619Z

Searching on GitHub brings answers in the speediest of manners. :)

Jakub Holý (HolyJak) 2023-04-17T10:26:26.518489Z

What did you search? I searched the honesql GH repo for “cascade” in vain

p-himik 2023-04-17T10:29:42.324599Z

That's actually exactly what I did. It's just that I look at commits and issues as well. The search landed me on this commit where I quickly saw the highlighted line which made it obvious how to specify :cascade: https://github.com/seancorfield/honeysql/commit/e8ea9283cc3cae5939750a0b540518143b87ff39#diff-49952233047493b6ede50abf2fce16b71d9c717d3b7c050f64e86a4514a1db1bR599

👍 1
🙏 1
marrs 2023-04-17T20:57:10.995189Z

Can honeysql quote table and column names to prevent clashes with names reserved by the DBRMS and are there any strong opinions about whether or not one should do this?

p-himik 2023-04-17T20:58:38.597609Z

Yes, quoting is very well documented. And you should definitely do that. There's no good reason not to quote your identifiers.

marrs 2023-04-17T21:26:43.964259Z

Ah, I found the relevant part in the doc. I guess the deeper question is, should one avoid using reserved words even if one is quoting?

p-himik 2023-04-17T21:40:14.276889Z

I would say no. E.g. "order" is way too good of a name to pass it up just because the DB reserved it in its unquoted form.

p-himik 2023-04-17T21:40:42.466239Z

But you probably shouldn't name your columns &%!@# even if quoted. ;)

marrs 2023-04-17T21:47:19.674929Z

yeah, that seems fair

marrs 2023-04-17T21:47:49.494019Z

thanks for sharing your opinion

👍 1