feat: 新增类级 @TableIndex 注解(复合/唯一/部分索引,对齐 .NET [Index(...)])、索引 diff 统一为 IndexSpec、快照升级 v4、迁移源码还原 filter,版本 1.3.0

This commit is contained in:
2026-08-25 11:38:59 +08:00
parent 270a01fd49
commit 95b18084d5
10 changed files with 347 additions and 56 deletions
+52
View File
@@ -101,3 +101,55 @@ public class MaxLength {
public class Index {
public const init() {}
}
/**
* 类级复合/条件索引(对齐 .NET 类级 [Index(...)],支持多列 + 唯一 + 部分索引)。
* 标注在实体类上,一个类声明一个复合索引(Cangjie 反射 findAnnotation 在同类多标注时读不到)。
*
* 用法:
* @TableIndex["source_server,name", true, "kind = 'Passport'"]
* public class Asset { ... }
*
* 参数(顺序):
* - columns 逗号分隔的列名/字段名(字段名自动映射为列名,如 "source_server,name" 或 "_sourceServer,_name")
* - unique 是否唯一索引,默认 false
* - filter 部分索引过滤条件(原始 SQL,如 "kind = 'Passport'";空串表示全表索引,不生成 WHERE),默认空
* - name 索引名,可为空;为空时自动生成 ix_<表名>_<首列名>
*
* 重载:@TableIndex[columns](全默认)、[columns, unique]、[columns, unique, filter]、[columns, unique, filter, name]。
*/
@Annotation[target: [Type]]
public class TableIndex {
public let columns: String
public let unique: Bool
public let filter: String
public let name: String
public const init(columns: String, unique: Bool, filter: String, name: String) {
this.columns = columns
this.unique = unique
this.filter = filter
this.name = name
}
public const init(columns: String, unique: Bool, filter: String) {
this.columns = columns
this.unique = unique
this.filter = filter
this.name = ""
}
public const init(columns: String, unique: Bool) {
this.columns = columns
this.unique = unique
this.filter = ""
this.name = ""
}
public const init(columns: String) {
this.columns = columns
this.unique = false
this.filter = ""
this.name = ""
}
}