Fork me on GitHub
#honeysql
<
2022-10-11
>
sheluchin11:10:29

Sorry if I'm missing it in the docs, but how do I keep something from being wrapped in parens? I'm trying to get:

REFERENCES FOO ON DELETE CASCADE
but end up with:
REFERENCES FOO ON DELETE(CASCADE)

seancorfield14:10:15

In DDL you can probably use :delete-cascade to produce plain SQL keywords with spaces.

seancorfield14:10:17

But it would help if you showed what DSL day you are trying...😁

sheluchin14:10:33

@U04V70XH6 I'm trying to do something like this:

(-> (hh/create-table :bar)
    (hh/with-columns
      [[:did :uuid [:default [:gen_random_uuid]]]
       [:foo-id :varchar [:not nil]]
       [[:primary-key :did :foo-id]]
       [[:foreign-key :foo-id]
        [:references :foo]
        [:on-delete :cascade]]]))
The Postgres syntax I'm trying to produce is like this:
CREATE TABLE order_items (
    product_no integer REFERENCES products ON DELETE RESTRICT,
    order_id integer REFERENCES orders ON DELETE CASCADE,
    quantity integer,
    PRIMARY KEY (product_no, order_id)
);

seancorfield16:10:48

Can you create a GH issue with that example so I can think about it? DDL is horribly non-regular so trying to figure out DSL syntax for it is tricky at times. I'm not sure right now what the best solution for this case is -- I'll have to look at how various databases handle this.

sheluchin16:10:02

Thanks, @U04V70XH6. I'll have that issue up sometime soon. I was asking in here just in case I missed it. Grepping through the project I saw there was some mention of added support for CREATE TABLE / CASCADE a while ago, but couldn't find supporting examples to match my target: https://github.com/seancorfield/honeysql/blob/dda3aa017e62b54863d302252c574fabf687543c/CHANGELOG.md?plain=1#L139-L141

seancorfield16:10:45

DROP .. CASCADE is supported, as I recall, but that change entry refers to the top-level DSL clauses, not columns within CREATE TABLE.

👍 1
sheluchin12:10:52

https://github.com/seancorfield/honeysql/issues/437 Just leaving the link to the issue here for reference.

1
hifumi12314:10:57

Recently I had to deal with DDLs as well. In particular clauses like ON DELETE SET NULL ON UPDATE CASCADE. I wasn't able to get this outputted with e.g. [:on-delete :set nil], but as a temporary workaround you can use individual keywords. That is, you can use :on :delete :set nil :on :update :cascade for the time being. This is what I plan to do until HoneySQL improves support for this kind of syntax

👍 1