The difficulties inherent in providing a database-independent abstraction over DDL is precisely why clojure.java.jdbc doesn't do this - and why there are strong recommendations to use other libraries (in combination with java.jdbc) if you want DSLs for that.
java.jdbc is intended to be a thin wrapper around JDBC that acts as a common base for all the other database libraries. If you want referential integrity constraints, use db-do-commands to run SQL/DDL to add them - or leverage a library that provides those abstractions on top of java.jdbc. (personally, I find heavy use of such constraints to be counter-productive since it makes refactoring and evolution of both schema and code to be much more difficult) Sean On Sat, Dec 14, 2013 at 2:29 AM, Simon Brooke <[email protected]> wrote: > First, yes, I now know I could build referential integrity constraints using > Korma, and that's almost certainly what I shall do next time. > > However, I'm quite a long way down building an app against a very tight > deadline and I've declared my tables in clojure.java.jdbc, e.g. > > (defn create-categories-table > "Reference data: award categories" > [db-spec] > (sql/with-connection db-spec > (sql/create-table > :categories > [:id "serial primary key"] > [:name "varchar(48)" "not null"]) > (sql/do-commands "insert into categories (name) values ('Best Use of > Ecommerce (UK market)')") > (sql/do-commands "insert into categories (name) values ('Best Use of > Ecommerce (International market)')") > (sql/do-commands "insert into categories (name) values ('Ecommerce > Innovation of the Year')") > (sql/do-commands "insert into categories (name) values ('Ecommerce > Newcomer of the Year')") > (sql/do-commands "insert into categories (name) values ('Ecommerce > Digital Agency of the Year')") > (sql/do-commands "insert into categories (name) values ('Ecommerce > Specialist Supplier of the Year')") > )) > > (defn create-nominations-table > "Actual nominations" > [db-spec] > (sql/with-connection db-spec > (sql/create-table > :nominations > [:id "serial primary key"] > [:firstname "varchar(64)" "not null"] > [:surname "varchar(64)" "not null"] > [:phone "varchar(24)" "not null"] > [:email "varchar(128)" "not null"] > [:business "varchar(64)" "not null"] > [:category "integer" "not null"] > [:url "varchar(256)" "not null"] > [:contact "varchar(128)"] > [:citation :text] > ))) > > Obviously, 'category' in the nominations table should reference categories. > And obviously, I can hack that in the database, so the fact that Clojure > doesn't automatically set it up doesn't (this time) matter. However, I'd > like to know for the future whether Korma is just the best way to go, or > whether there is some database-independent[*] way to set up referential > integrity constraints at the clojure.java.jdbc. > > [*] Yes, I know that the fact I'm using 'serial primary key' tells you > already that I'm using Postgres, so this isn't database-independent! > > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
