nilenso / honeysql-postgres

PostgreSQL extension for honeysql
http://nilenso.com
Eclipse Public License 1.0
193 stars 28 forks source link

Add `constraints` format-clause with support for UNIQUE and PRIMARY KEY #60

Closed drew-patel closed 3 years ago

drew-patel commented 3 years ago

Related issue - #15

scimetfoo commented 3 years ago

@drew-patel thanks for submitting this PR!

A couple of suggestions:

  1. Use defhelper only to update the query map with the constraint clauses and not to construct the SQL function call. We want to utilise the format-clause multimethod to construct the function call so that it works with honeysql's priority-based ordering rule system. Also, add a priority to the constraint clause, which I think would be a number slightly larger than the priority assigned to with-columns. I just noticed that with-columns doesn't have a priority assigned to it either, but it will need one now. Could you please add one for it as well?
  2. Pluralise constraint so that going forward we're able to use this function for defining multiple constraints. Eg:
    (constraints [:unique [:product_no :product_sku]]
             [:primary-key [:name]])
  3. Add a top-level key called :constraints to the query map instead of associng the constraints to the collection of columns. It otherwise ends up treating each constraint as a column.
  4. Support multiple constraints? It could also just be multiple unique constraints to being with.
drew-patel commented 3 years ago

@scimetfoo Thanks for the feedback and suggestions!

All the points are clear. I'll ask questions if I'm unsure about anything while working on them. Will get back to you in a few days with the changes.

drew-patel commented 3 years ago

@scimetfoo I have addressed comments 1-3 as described above. I've only implemented the solution for UNIQUE and PRIMARY KEY so far since they behave similarly.

Thanks!

drew-patel commented 3 years ago

@scimetfoo Please let me know if the examples are sufficient. Thanks again for the review!