-
Notifications
You must be signed in to change notification settings - Fork 2
πͺ Create Table
Gustavo M. Paes edited this page Dec 10, 2021
·
1 revision
To create a WormTable you need create a java class and extend WormTable.
public class User extends WormTable {
}the mysql table name will be the class name, in this case will be 'User'
with you wanna make a table with diffent name:
public class User extends WormTable {
public User(){
super("user_table")
}
}now the mysql table name will be 'user_table'
WormTable sync the java class and mysql table.
To create columns in the WormTable you just use the @WormField annotation, like:
public class User extends WormTable {
@WormField(sqlType = "VARCHAR", length = 36, idColumn = true)
String userUuid;
@WormField(sqlType = "VARCHAR", length = 50)
String name;
@WormField(sqlType = "VARCHAR", length = 50, nullable = true, defaultValue = "NULL")
String email;
}in this example will create 3 columns:
- 'userUuid' will be a varchar, max 36 caracters and primary key
- 'name' will be a varchar, max 50 caracters
- 'email' will be a varchar, max 50 caracters, nullable and default value null
- sqlType ->
String- is the column type in mysql. Default: 'Text' - length ->
int- is the column value length (0 is unlimited). Default: 0 - autoIncrement ->
Boolean- if the column is auto increment in mysql. Default: false - idColumn ->
Boolean- if the column is the primary key in mysql. Default: false - defaultValue ->
String- is the column default value in mysql. Default: ''
When you create a class that extends WormTable, will automaticaly create a MySql table in the first class call
Worm it's created by GumpDev and use some repositories like HikariCP, Mysql Connector Java and slf4j