- exec/scanner: 用 *interface{} 替换 **json.RawMessage 扫描目标,兼容 DuckDB 返回 map[string]interface{} 的场景;新增 toJSONRawMessage 转换函数
- exec/scanner: ScanVal 支持结构体指针,通过 JSON 中间层转换(DuckDB STRUCT 列)
- exec/scanner: 将 *sql.RawBytes 和 *[]byte 的处理从 ScanValContext 移入 scanner.ScanVal
- exec/query_executor: 简化 ScanValContext,移除私有 scan 方法
- exec: 补充 scanner 级别 ScanVal 测试用例
- internal/util/reflect: 重写 SafeSetVarValue,修复非指针 src 及 nil 指针字段的 panic
- internal/util/column_map: 恢复非匿名带标签结构体字段的展开逻辑
- schema: 新增 vector 列类型支持
- engine: 补充 DuckDB 相关配置
- dialect/sqlite3/vtab: 完善虚拟表适配器
- 各方言测试改用 sqlmock 虚拟连接
183 lines
4.9 KiB
Go
Executable File
183 lines
4.9 KiB
Go
Executable File
package schema
|
|
|
|
type ColumnDefinition struct {
|
|
Type string // kind of column, string / int
|
|
Name string // name of column
|
|
ColumnOptions
|
|
}
|
|
|
|
type ColumnOptions struct {
|
|
Length int // 字段长度
|
|
Allowed []string // enum 选项
|
|
Precision int // 日期时间精度
|
|
Total int // 小数位数
|
|
Places int // 小数精度
|
|
rename string // 重命名
|
|
useCurrent bool // CURRENT TIMESTAMP
|
|
after string // Place the column "after" another column (MySQL)
|
|
always bool // Used as a modifier for generatedAs() (PostgreSQL)
|
|
autoIncrement bool // Set INTEGER columns as auto-increment (primary key)
|
|
change bool // Change the column
|
|
charset string // Specify a character set for the column (MySQL)
|
|
collation string // Specify a collation for the column (MySQL/PostgreSQL/SQL Server)
|
|
comment string // Add a comment to the column (MySQL)
|
|
def any // Specify a "default" value for the column
|
|
first bool // Place the column "first" in the table (MySQL)
|
|
nullable bool // Allow NULL values to be inserted into the column
|
|
storedAs string // Create a stored generated column (MySQL)
|
|
unsigned bool // Set the INTEGER column as UNSIGNED (MySQL)
|
|
virtualAs string // Create a virtual generated column (MySQL)
|
|
unique bool // Add a unique index
|
|
primary bool // Add a primary index
|
|
index bool // Add an index
|
|
spatialIndex bool // Add a spatial index
|
|
hidden bool // SQLite 虚拟表 HIDDEN 列:不出现在 SELECT *,可在 WHERE 中作为参数传入
|
|
}
|
|
|
|
// VirtualAs Create a virtual generated column (MySQL)。
|
|
// 在 SQLite 虚拟表 schema 中无效,自动退化为 HIDDEN 列。
|
|
func (c *ColumnDefinition) VirtualAs(as string) *ColumnDefinition {
|
|
c.virtualAs = as
|
|
c.hidden = true
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) GetVirtualAs() string {
|
|
return c.virtualAs
|
|
}
|
|
|
|
// StoredAs Create a stored generated column (MySQL)
|
|
func (c *ColumnDefinition) StoredAs(as string) *ColumnDefinition {
|
|
c.storedAs = as
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) GetStoredAs() string {
|
|
return c.storedAs
|
|
}
|
|
|
|
// Unsigned Set INTEGER columns as UNSIGNED (MySQL)
|
|
func (c *ColumnDefinition) Unsigned() *ColumnDefinition {
|
|
c.unsigned = true
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) IsUnsigned() bool {
|
|
return c.unsigned
|
|
}
|
|
|
|
// First Place the column "first" in the table (MySQL)
|
|
func (c *ColumnDefinition) First() *ColumnDefinition {
|
|
c.first = true
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) IsFirst() bool {
|
|
return c.first
|
|
}
|
|
|
|
// Default Specify a "default" value for the column
|
|
func (c *ColumnDefinition) Default(def any) *ColumnDefinition {
|
|
c.def = def
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) GetDefault() any {
|
|
return c.def
|
|
}
|
|
|
|
// Comment Add a comment to a column (MySQL/PostgreSQL)
|
|
func (c *ColumnDefinition) Comment(comm string) *ColumnDefinition {
|
|
c.comment = comm
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) GetComment() string {
|
|
return c.comment
|
|
}
|
|
|
|
// Collaction Specify a collation for the column (MySQL/PostgreSQL/SQL Server)
|
|
func (c *ColumnDefinition) Collaction(coll string) *ColumnDefinition {
|
|
c.collation = coll
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) GetCollaction() string {
|
|
return c.collation
|
|
}
|
|
|
|
// Charset Specify a character set for the column (MySQL)
|
|
func (c *ColumnDefinition) Charset(chars string) *ColumnDefinition {
|
|
c.charset = chars
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) GetCharset() string {
|
|
return c.charset
|
|
}
|
|
|
|
// AutoIncrement set INTEGER columns as auto-increment (primary key)
|
|
func (c *ColumnDefinition) AutoIncrement() *ColumnDefinition {
|
|
c.autoIncrement = true
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) IsAutoIncrement() bool {
|
|
return c.autoIncrement
|
|
}
|
|
|
|
// After place the column "after" another column (MySQL)
|
|
func (c *ColumnDefinition) After(column string) *ColumnDefinition {
|
|
c.after = column
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) GetAfter() string {
|
|
return c.after
|
|
}
|
|
|
|
// Nullable makes a column nullable
|
|
func (c *ColumnDefinition) Nullable() *ColumnDefinition {
|
|
c.nullable = true
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) IsNullable() bool {
|
|
return c.nullable
|
|
}
|
|
|
|
// 修改字段, 默认新增
|
|
func (c *ColumnDefinition) Change(param ...string) *ColumnDefinition {
|
|
if len(param) > 0 && param[0] != "" {
|
|
c.rename = param[0]
|
|
}
|
|
c.change = true
|
|
return c
|
|
}
|
|
|
|
// 时间戳
|
|
func (c *ColumnDefinition) UseCurrent() *ColumnDefinition {
|
|
c.useCurrent = true
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) IsUseCurrent() bool {
|
|
return c.useCurrent
|
|
}
|
|
|
|
// 获取重命名
|
|
func (c *ColumnDefinition) GetRename() string {
|
|
return c.rename
|
|
}
|
|
|
|
// Hidden 将列标记为 SQLite 虚拟表 HIDDEN 列。
|
|
// HIDDEN 列不出现在 SELECT * 结果中,但可以通过 WHERE col = ? 向虚拟表传递参数。
|
|
func (c *ColumnDefinition) Hidden() *ColumnDefinition {
|
|
c.hidden = true
|
|
return c
|
|
}
|
|
|
|
func (c *ColumnDefinition) IsHidden() bool {
|
|
return c.hidden
|
|
}
|