Create table using primary key using jOOQ

jOOQ has the CREATE TABLE syntax, as stated in the documentation :

create.createTable(AUTHOR) .column(AUTHOR.ID, SQLDataType.INTEGER) .column(AUTHOR.FIRST_NAME, SQLDataType.VARCHAR.length(50)) .column(AUTHOR_LAST_NAME, SQLDataType.VARCHAR.length(50)) .execute(); 

I am wondering how to determine which column belongs to the primary key? So, is there a way in jOOQ to create a CREATE TABLE statement with PRIMARY KEY information?

I am particularly interested in the solution for SQLite, which has no syntax for adding a primary key, so I think in the worst case I need to go to a specific database solution?

+5
source share
1 answer

This feature was implemented for jOOQ 3.8: # 4050 .

 create.createTable(AUTHOR) .column(AUTHOR.ID, SQLDataType.INTEGER) .column(AUTHOR.FIRST_NAME, SQLDataType.VARCHAR.length(50)) .column(AUTHOR_LAST_NAME, SQLDataType.VARCHAR.length(50)) .constraints( constraint("PK_AUTHOR").primaryKey(AUTHOR.ID) ) .execute(); 

Since jOOQ 3.6 ( # 3338 ), you can also use the ALTER TABLE statement to add a constraint after creating the table:

 create.alterTable(AUTHOR) .add(constraint("PK_AUTHOR").primaryKey(AUTHOR.ID)) .execute(); 
+4
source

Source: https://habr.com/ru/post/1212263/


All Articles