-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foreign key DDL support #386
Comments
I think the closest you'll get right now is |
Ah, it looks like FOREIGN KEY(company_id) REFERENCES COMPANY(ID) (I may be able to tweak the casing of |
|
Thanks for your quick reply! Given your explanation that
The result is not what I expected, which is
|
Isn't that exactly what I said above about the casing of |
The casing of the example here (https://cljdoc.org/d/com.github.seancorfield/honeysql/2.2.861/doc/getting-started/sql-special-syntax-#constraint-default-references) is properly handled. So I asked about it. |
Looks like a doc bug. What I showed above matches what you experienced and is how the code currently works. When/if I can fix the way |
I'm going to close this in favor of #439 where I want to track all column specification work and find a generic solution to this sort of thing. |
With the fix I'm working on for #439 your example becomes: (deftest references-issue-386
(is (= ["CREATE TABLE IF NOT EXISTS user (id VARCHAR(255) NOT NULL PRIMARY KEY, company_id INT NOT NULL, name VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, created_time DATETIME DEFAULT CURRENT_TIMESTAMP, updated_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY(company_id) REFERENCES company(id))"]
(-> {:create-table [:user :if-not-exists]
:with-columns
[[:id [:varchar 255] [:not nil] [:primary-key]]
[:company-id :int [:not nil]]
[:name [:varchar 255] [:not nil]]
[:password [:varchar 255] [:not nil]]
[:created-time :datetime [:default :CURRENT_TIMESTAMP]]
[:updated-time :datetime [:default :CURRENT_TIMESTAMP]
:on :update :CURRENT_TIMESTAMP]
[[:foreign-key :company-id] [:references :company :id]]]}
(sql/format))))) Note that |
I want to translate the following sql statement to honeysql.
So I tried it as follows.
What I want is
FOREIGN KEY company-id REFERENCES company(id))
, notforeign_key COMPANY_ID REFERENCES COMPANY(ID))
.How can I achieve what I want?
The text was updated successfully, but these errors were encountered: