Skip to content
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

UNIQUE on the table #15

Open
arichiardi opened this issue Feb 1, 2018 · 4 comments
Open

UNIQUE on the table #15

arichiardi opened this issue Feb 1, 2018 · 4 comments

Comments

@arichiardi
Copy link
Contributor

I would like to achieve the following (from here:

CREATE TABLE example (
    a integer,
    b integer,
    c integer,
    UNIQUE (a, c)
);

And I see that there is an (sql/call :unique ...) I can use, but the problem is that I don't really see how to achieve that, maybe because I don't know how to hook in that :with-columns map.

Any recommendation on how to do that?

@arichiardi
Copy link
Contributor Author

arichiardi commented Feb 1, 2018

This is the ugly workaround:

(let [unique-sql & _] (when unique-columns
                        (-> (apply sql/call :unique unique-columns)
                            (sql/format :parameterizer :postgresql)))

   (str/replace table-stmt #"\)$" (str ", " unique-sql ")"))

@arichiardi
Copy link
Contributor Author

@krish8664 any advice/recommendation on this one?

@ukriish
Copy link
Contributor

ukriish commented Sep 29, 2018

@arichiardi I think the idea would be to come up with a way to specify constraints outside of the inlined way it is possible right now. Let me think about this for a bit.
Ideally I would like something of the following syntax

(-> (create-table :films)
    (with-columns [[:a :integer]
                   [:b :integer]
                   [:c :integer])
    (constrain [:unique [:a :c]]))

This should be possible to achieve. Alternatively if you have found a better way to do this, I would like to hear about that.

P.S: Sorry about the extremely delayed response, I haven't been very active here on github for quite sometime. This would change going forward.

@arichiardi
Copy link
Contributor Author

Agree that what you wrote feels right, basically a way to add constraints to columns.

I see inline would be difficult to make it work.

PS.: Good to have you back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants