mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-05 00:25:32 +08:00
[0.3.10] 新增 SQLTable 用于快速创建与该表相关的操作。
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.SQLTable;
|
||||
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
||||
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||
import cc.carm.lib.easysql.api.enums.NumberType;
|
||||
@@ -43,6 +44,33 @@ public class EasySQLDemo {
|
||||
.build().execute(null /* 不处理错误 */);
|
||||
}
|
||||
|
||||
public void useSQLTable(SQLManager sqlManager) {
|
||||
SQLTable tags = SQLTable.of("servers", table -> {
|
||||
table.addAutoIncrementColumn("id", true);
|
||||
table.addColumn("user", "INT UNSIGNED NOT NULL");
|
||||
table.addColumn("content", "TEXT NOT NULL");
|
||||
table.addColumn("time", "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP");
|
||||
|
||||
table.addForeignKey(
|
||||
"user", "fk_user_tags",
|
||||
"users", "id",
|
||||
ForeignKeyRule.CASCADE, ForeignKeyRule.CASCADE
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
try {
|
||||
tags.create(sqlManager);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
tags.createQuery().addCondition("id", 5).build()
|
||||
.executeAsync(success -> {
|
||||
System.out.println("success!");
|
||||
});
|
||||
}
|
||||
|
||||
public void alertTable(SQLManager sqlManager) {
|
||||
// 同步更新表
|
||||
sqlManager.alterTable("users")
|
||||
|
||||
Reference in New Issue
Block a user