Documentation
¶
Index ¶
- Variables
- func NewErrorQueryResult(err error) def.QueryResult
- func NewFieldData(data any, idx int, refTable def.TableInfo) def.FieldData
- func NewTableRowData(TableInfo def.TableInfo, data []def.FieldData) def.RowData
- func ToColumn[T any](qr def.QueryResult, columnName string) ([]T, error)
- func ToResult[T any](qr def.QueryResult, opts ...structmap.Option) (T, error)
- func ToResultEx[T any](qr def.QueryResult, transform def.ItemTransformFunc, opts ...structmap.Option) (T, error)
- func ToValue[T any](qr def.QueryResult, columnName string, rowIndex ...int) (T, error)
- type ColumnSpec
- type CompositeForeignKey
- func (c *CompositeForeignKey) GetColumns() []string
- func (c *CompositeForeignKey) GetName() string
- func (c *CompositeForeignKey) GetOnDelete() def.ForeignKeyAction
- func (c *CompositeForeignKey) GetOnUpdate() def.ForeignKeyAction
- func (c *CompositeForeignKey) GetRefColumns() []string
- func (c *CompositeForeignKey) GetRefTable() string
- type CompositeIndex
- type DBIndex
- type FieldData
- type FieldInfo
- func (f *FieldInfo) GetComment() string
- func (f *FieldInfo) GetDefault() *string
- func (f *FieldInfo) GetForeignKey() def.ForeignKeyInfo
- func (f *FieldInfo) GetName() string
- func (f *FieldInfo) GetOrginalDataType() string
- func (f *FieldInfo) GetPrecision() int
- func (f *FieldInfo) GetScale() int
- func (f *FieldInfo) GetSize() int
- func (f *FieldInfo) GetType() def.StandardFieldType
- func (f *FieldInfo) GetTypeAndSize() (def.StandardFieldType, int)
- func (f *FieldInfo) IsAutoIncrement() bool
- func (f *FieldInfo) IsDefaultCurrentTimeOnCreate() bool
- func (f *FieldInfo) IsDefaultCurrentTimeOnUpdate() bool
- func (f *FieldInfo) IsIndex() bool
- func (f *FieldInfo) IsNotNull() bool
- func (f *FieldInfo) IsPrimaryKey() bool
- func (f *FieldInfo) IsUnique() bool
- type FieldMapping
- type ForeignKeyInfo
- type Kind
- type MigrationTableInfo
- type PaginatedResult
- type QueryMetadata
- type QueryResult
- func (qr *QueryResult) Bool(columnName string) (bool, error)
- func (qr *QueryResult) Count() int
- func (qr *QueryResult) Err() error
- func (qr *QueryResult) Float64(columnName string) (float64, error)
- func (qr *QueryResult) GetColumn(columnName string) ([]any, error)
- func (qr *QueryResult) GetColumns(columnNames ...string) (map[string][]any, error)
- func (qr *QueryResult) GetFirstRow() ([]any, []string, error)
- func (qr *QueryResult) GetMetaData() def.QueryMetadata
- func (qr *QueryResult) GetPage() int
- func (qr *QueryResult) GetPageSize() int
- func (qr *QueryResult) GetRow(rowIndex int) ([]any, []string, error)
- func (qr *QueryResult) GetTotalCount() int64
- func (qr *QueryResult) GetValue(columnName string, rowIndex ...int) (any, error)
- func (qr *QueryResult) HasError() bool
- func (qr *QueryResult) Int64(columnName string) (int64, error)
- func (qr *QueryResult) IsEmpty() bool
- func (qr *QueryResult) RawData() ([][]any, []string, error)
- func (qr *QueryResult) ScanInto(dest any, opts ...structmap.Option) error
- func (qr *QueryResult) ScanIntoEx(dest any, transform def.ItemTransformFunc, opts ...structmap.Option) error
- func (qr *QueryResult) ScanValue(dest any, columnName string, rowIndex ...int) error
- func (qr *QueryResult) SetPage(page int)
- func (qr *QueryResult) SetPageSize(size int)
- func (qr *QueryResult) SetTotalCount(total int64)
- func (qr *QueryResult) String(columnName string) (string, error)
- func (qr *QueryResult) ToMap() (map[string]any, error)
- func (qr *QueryResult) ToMaps() ([]map[string]any, error)
- type RowData
- func (r *RowData) AsObject() (map[string]any, error)
- func (r *RowData) ForEach(fn func(i int, d def.FieldData) error) error
- func (r *RowData) GetDatabase() string
- func (r *RowData) GetFieldDatas() ([]def.FieldData, error)
- func (r *RowData) GetFields() ([]string, error)
- func (r *RowData) GetFieldsSkipPk() ([]string, error)
- func (r *RowData) GetPkFields() ([]string, error)
- func (r *RowData) GetReplaceSql() (string, error)
- func (r *RowData) GetSchema() string
- func (r *RowData) GetTableName() string
- func (r *RowData) GetValues() ([]any, []string, error)
- func (r *RowData) GetValuesAsObj() map[string]any
- func (r *RowData) GetValuesSkipPK() ([]any, []string, error)
- func (r *RowData) IsEmpty() bool
- type TableColumnInfo
- type TableConstraint
- type TableConstraints
- type TableInfo
- type TableReference
- type TableSpec
- func (t *TableSpec) ColumnExist(columnName string) bool
- func (t *TableSpec) FilterColumns(columnNames []string, skipPK bool) []string
- func (t *TableSpec) GetColumn(idx int) def.ColumnInfo
- func (t *TableSpec) GetColumnIndex(name string) int
- func (t *TableSpec) GetColumnNameSet() map[string]struct{}
- func (t *TableSpec) GetColumnNameSetWithoutPK() map[string]struct{}
- func (t *TableSpec) GetColumns() []def.ColumnInfo
- func (t *TableSpec) GetComment() string
- func (t *TableSpec) GetCompositeForeignKeys() []def.CompositeForeignKey
- func (t *TableSpec) GetCompositeIndexes() []def.CompositeIndex
- func (t *TableSpec) GetConstraints() []def.TableConstraint
- func (t *TableSpec) GetDatabase() string
- func (t *TableSpec) GetName() string
- func (t *TableSpec) GetPrimaryKeys() []string
- func (t *TableSpec) GetSchema() string
- func (t *TableSpec) GetType() (string, string)
- func (t *TableSpec) GetUniqueKeys() []string
Constants ¶
This section is empty.
Variables ¶
var SliceContains = cyutil.SliceContains
Functions ¶
func NewErrorQueryResult ¶
func NewErrorQueryResult(err error) def.QueryResult
func NewTableRowData ¶
func ToColumn ¶
func ToColumn[T any](qr def.QueryResult, columnName string) ([]T, error)
ToColumn converts a column from QueryResult into a typed slice. Automatically converts each value in the column to the target type. Returns error if column not found or conversion fails.
Example:
result, err := db.QueryAsResult("SELECT age FROM users")
if err != nil {
return err
}
ages, err := cydb.ToColumn[int](result, "age")
if err != nil {
return err
}
fmt.Printf("Ages: %v\n", ages) // []int{25, 30, 35}
func ToResult ¶
ToResult converts the provided QueryResult into a typed result. It scans the first row into the result type.
Example:
result, err := db.FirstAsResult(...)
if err != nil {
return err
}
user, err := cydb.ToResult[User](result)
if err != nil {
return err
}
fmt.Printf("User: %+v\n", user)
func ToResultEx ¶
func ToResultEx[T any](qr def.QueryResult, transform def.ItemTransformFunc, opts ...structmap.Option) (T, error)
ToResultEx converts the provided QueryResult into a typed result. It is an extended version of ToResult that accepts a callback to mutate the row item map before it is mapped into the destination struct.
func ToValue ¶
ToValue converts a single value from QueryResult into the specified type. If rowIndex is not provided, it defaults to 0 (first row). Automatically converts the value to the target type. If the value is a string or []byte and T is a struct or slice, attempts JSON decoding.
Example:
result, err := db.QueryRowAsResult("SELECT age FROM users WHERE id = ?", 1)
if err != nil {
return err
}
age, err := cydb.ToValue[int](result, "age")
if err != nil {
return err
}
fmt.Printf("Age: %d\n", age) // Age: 25
// Get value from second row
age, err := cydb.ToValue[int](result, "age", 1)
// JSON decoding example for struct
type User struct {
Name string `json:"name"`
Age int `json:"age"`
}
result, err := db.QueryRowAsResult("SELECT data FROM users WHERE id = ?", 1)
user, err := cydb.ToValue[User](result, "data") // Automatically decodes JSON
// JSON decoding example for slice
type Item struct {
ID int `json:"id"`
Name string `json:"name"`
}
result, err := db.QueryRowAsResult("SELECT items FROM orders WHERE id = ?", 1)
items, err := cydb.ToValue[[]Item](result, "items") // Automatically decodes JSON array
Types ¶
type ColumnSpec ¶
type ColumnSpec = FieldInfo
ColumnSpec is the unified column definition (alias of FieldInfo for compatibility).
type CompositeForeignKey ¶
type CompositeForeignKey struct {
Name string // Foreign key constraint name
Columns []string // Local columns
RefTable string // Referenced table name
RefColumns []string // Referenced columns
OnDelete string // DELETE action (CASCADE, RESTRICT, SET NULL, NO ACTION)
OnUpdate string // UPDATE action (CASCADE, RESTRICT, SET NULL, NO ACTION)
}
CompositeForeignKey represents a composite foreign key constraint
func (*CompositeForeignKey) GetColumns ¶
func (c *CompositeForeignKey) GetColumns() []string
GetColumns implements def.CompositeForeignKey.
func (*CompositeForeignKey) GetName ¶
func (c *CompositeForeignKey) GetName() string
GetName implements def.CompositeForeignKey.
func (*CompositeForeignKey) GetOnDelete ¶
func (c *CompositeForeignKey) GetOnDelete() def.ForeignKeyAction
GetOnDelete implements def.CompositeForeignKey.
func (*CompositeForeignKey) GetOnUpdate ¶
func (c *CompositeForeignKey) GetOnUpdate() def.ForeignKeyAction
GetOnUpdate implements def.CompositeForeignKey.
func (*CompositeForeignKey) GetRefColumns ¶
func (c *CompositeForeignKey) GetRefColumns() []string
GetRefColumns implements def.CompositeForeignKey.
func (*CompositeForeignKey) GetRefTable ¶
func (c *CompositeForeignKey) GetRefTable() string
GetRefTable implements def.CompositeForeignKey.
type CompositeIndex ¶
type CompositeIndex struct {
Name string // Index name
Columns []string // Column names in the index
Unique bool // Whether it's a unique index
}
CompositeIndex represents a composite index
func (*CompositeIndex) GetColumns ¶
func (c *CompositeIndex) GetColumns() []string
GetColumns implements def.CompositeIndex.
func (*CompositeIndex) GetName ¶
func (c *CompositeIndex) GetName() string
GetName implements def.CompositeIndex.
func (*CompositeIndex) IsUnique ¶
func (c *CompositeIndex) IsUnique() bool
IsUnique implements def.CompositeIndex.
type FieldData ¶
func (*FieldData) GetFieldName ¶
GetFieldName implements def.FieldData.
func (*FieldData) GetFieldSize ¶
func (*FieldData) GetFieldType ¶
func (f *FieldData) GetFieldType() def.StandardFieldType
GetFieldType implements def.FieldData.
func (*FieldData) GetOrginalDataType ¶
GetOrginalDataType implements def.FieldData.
func (*FieldData) IsPrimary ¶
IsPrimary implements def.FieldData.
type FieldInfo ¶
type FieldInfo struct {
Name string
Type def.StandardFieldType
OrginalDataType string // raw type string from DB introspection
PrimaryKey bool
Index bool
Unique bool
NotNull bool
Default *string
Size int
Precision int
Scale int
AutoIncrement bool
ForeignKey *ForeignKeyInfo
DefaultCurrentTime bool // DEFAULT CURRENT_TIMESTAMP
UpdateCurrentTime bool // DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Comment string // column comment from DB introspection ("" when unsupported)
}
func (*FieldInfo) GetComment ¶
GetComment implements def.ColumnInfo.
func (*FieldInfo) GetDefault ¶
GetDefault implements def.ColumnInfo.
func (*FieldInfo) GetForeignKey ¶
func (f *FieldInfo) GetForeignKey() def.ForeignKeyInfo
GetForeignKey implements def.ColumnInfo.
func (*FieldInfo) GetOrginalDataType ¶
GetOrginalDataType implements def.ColumnInfo.
func (*FieldInfo) GetPrecision ¶
GetPrecision implements def.ColumnInfo.
func (*FieldInfo) GetType ¶
func (f *FieldInfo) GetType() def.StandardFieldType
GetType implements def.ColumnInfo.
func (*FieldInfo) GetTypeAndSize ¶
func (f *FieldInfo) GetTypeAndSize() (def.StandardFieldType, int)
GetTypeAndSize implements def.ColumnInfo.
func (*FieldInfo) IsAutoIncrement ¶
IsAutoIncrement implements def.ColumnInfo.
func (*FieldInfo) IsDefaultCurrentTimeOnCreate ¶
IsDefaultCurrentTimeOnCreate implements def.ColumnInfo.
func (*FieldInfo) IsDefaultCurrentTimeOnUpdate ¶
IsDefaultCurrentTimeOnUpdate implements def.ColumnInfo.
func (*FieldInfo) IsNotNull ¶
IsNotNull implements def.ColumnInfo.
func (*FieldInfo) IsPrimaryKey ¶
IsPrimaryKey implements def.ColumnInfo.
func (*FieldInfo) IsUnique ¶
IsUnique implements def.ColumnInfo.
type FieldMapping ¶
type ForeignKeyInfo ¶
type ForeignKeyInfo struct {
ReferencedTable string
ReferencedColumn string
OnDelete string
OnUpdate string
}
ForeignKeyInfo represents foreign key constraint information
func (*ForeignKeyInfo) GetOnDelete ¶
func (f *ForeignKeyInfo) GetOnDelete() def.ForeignKeyAction
GetOnDelete implements def.ForeignKeyInfo.
func (*ForeignKeyInfo) GetOnUpdate ¶
func (f *ForeignKeyInfo) GetOnUpdate() def.ForeignKeyAction
GetOnUpdate implements def.ForeignKeyInfo.
func (*ForeignKeyInfo) GetRefColumn ¶
func (f *ForeignKeyInfo) GetRefColumn() string
GetRefColumn implements def.ForeignKeyInfo.
func (*ForeignKeyInfo) GetRefTable ¶
func (f *ForeignKeyInfo) GetRefTable() string
GetRefTable implements def.ForeignKeyInfo.
type PaginatedResult ¶
type PaginatedResult[T any] struct { Items []T `json:"items"` // Items in the current page Total int64 `json:"total"` // Total number of items across all pages Page int `json:"page"` // Current page number (1-indexed) PageSize int `json:"pageSize"` // Number of items per page }
PaginatedResult represents a paginated query result with type-safe items. Used by ScanPagedResult to return typed paginated data.
func ToPagedResult ¶
func ToPagedResult[T any](qr def.QueryResult, opts ...structmap.Option) (*PaginatedResult[T], error)
ToPagedResult converts the provided QueryResult into a typed PaginatedResult. It reuses ScanInto to populate the Items slice and falls back to sensible defaults when pagination metadata is missing.
Example:
result, err := db.ListWithPageAsResult(...)
if err != nil {
return err
}
paged, err := cydb.ToPagedResult[User](result)
if err != nil {
return err
}
fmt.Printf("Total: %d, Page: %d, Items: %d\n", paged.Total, paged.Page, len(paged.Items))
func ToPagedResultEx ¶
func ToPagedResultEx[T any](qr def.QueryResult, transform def.ItemTransformFunc, opts ...structmap.Option) (*PaginatedResult[T], error)
ToPagedResultEx converts the provided QueryResult into a typed PaginatedResult. It is an extended version of ToPagedResult that accepts a callback to mutate each row (item) before it is mapped into the destination struct.
The callback is executed after the row is converted to map[column]value and before structmap mapping. Returning an error will abort the scan.
type QueryMetadata ¶
type QueryMetadata = def.QueryMetadata
type QueryResult ¶
type QueryResult struct {
Data [][]any `json:"data"`
Columns []string `json:"columns"`
Row []any `json:"row,omitempty"`
TotalCount int64 `json:"total_count,omitempty"`
Page int `json:"page,omitempty"`
PageSize int `json:"page_size,omitempty"`
Metadata QueryMetadata `json:"metadata,omitempty"`
Error error `json:"error,omitempty"`
}
QueryResult wraps query results with metadata and efficient data access
func (*QueryResult) Bool ¶
func (qr *QueryResult) Bool(columnName string) (bool, error)
Bool returns the first row's value for the specified column as bool.
Example:
active, err := result.Bool("is_active")
func (*QueryResult) Count ¶
func (qr *QueryResult) Count() int
Count returns the number of rows in the result
func (*QueryResult) Err ¶
func (qr *QueryResult) Err() error
Err returns the underlying error, implementing def.QueryResult contract.
func (*QueryResult) Float64 ¶
func (qr *QueryResult) Float64(columnName string) (float64, error)
Float64 returns the first row's value for the specified column as float64. Useful for AVG, SUM, and other aggregate queries.
Example:
avg, err := result.Float64("avg_price")
func (*QueryResult) GetColumn ¶
func (qr *QueryResult) GetColumn(columnName string) ([]any, error)
GetColumn returns all values for the specified column name, or error if column not found. Returns a slice of values for the column across all rows.
Example:
ages, err := result.GetColumn("age") // []any{25, 30, 35}
func (*QueryResult) GetColumns ¶
func (qr *QueryResult) GetColumns(columnNames ...string) (map[string][]any, error)
GetColumns returns values for multiple columns at once. Returns a map of column names to their values (as slices). More efficient than calling GetColumn multiple times.
Example:
cols, err := result.GetColumns("id", "name", "age")
ids := cols["id"] // []any
names := cols["name"] // []any
func (*QueryResult) GetFirstRow ¶
func (qr *QueryResult) GetFirstRow() ([]any, []string, error)
GetFirstRow returns the first row, or error if no data
func (*QueryResult) GetMetaData ¶
func (qr *QueryResult) GetMetaData() def.QueryMetadata
func (*QueryResult) GetPage ¶
func (qr *QueryResult) GetPage() int
GetPage implements def.QueryResult.
func (*QueryResult) GetPageSize ¶
func (qr *QueryResult) GetPageSize() int
GetPageSize implements def.QueryResult.
func (*QueryResult) GetRow ¶
func (qr *QueryResult) GetRow(rowIndex int) ([]any, []string, error)
GetRow returns the row at the specified index, or error if out of bounds
func (*QueryResult) GetTotalCount ¶
func (qr *QueryResult) GetTotalCount() int64
GetTotalCount implements def.QueryResult.
func (*QueryResult) GetValue ¶
func (qr *QueryResult) GetValue(columnName string, rowIndex ...int) (any, error)
GetValue returns the value at the specified column name, or error if not found. If rowIndex is not provided, it defaults to 0 (first row). Returns error if column not found or row index out of bounds.
Example:
value, err := result.GetValue("name") // Get first row
value, err := result.GetValue("name", 1) // Get second row
value, err := result.GetValue("age", 2) // Get third row
func (*QueryResult) HasError ¶
func (qr *QueryResult) HasError() bool
HasError checks if the query result contains an error
func (*QueryResult) Int64 ¶
func (qr *QueryResult) Int64(columnName string) (int64, error)
Int64 returns the first row's value for the specified column as int64. Useful for COUNT, SUM, and other aggregate queries.
Example:
count, err := result.Int64("count")
func (*QueryResult) IsEmpty ¶
func (qr *QueryResult) IsEmpty() bool
IsEmpty checks if the query result has no data
func (*QueryResult) RawData ¶
func (qr *QueryResult) RawData() ([][]any, []string, error)
RawData returns the raw data and column names. Returns a tuple of (rows, columns) for direct access to underlying data.
Example:
data, columns := result.RawData()
func (*QueryResult) ScanInto ¶
func (qr *QueryResult) ScanInto(dest any, opts ...structmap.Option) error
ScanInto scans the query result into the destination type. Supports scanning into a single struct or a slice of structs. Automatically handles type conversion with structmap options.
Example:
var user User
if err := result.ScanInto(&user); err != nil {
return err
}
var users []User
if err := result.ScanInto(&users); err != nil {
return err
}
func (*QueryResult) ScanIntoEx ¶
func (qr *QueryResult) ScanIntoEx(dest any, transform def.ItemTransformFunc, opts ...structmap.Option) error
ScanIntoEx is an extended version of ScanInto. It accepts a callback to mutate each row (item) before it is mapped into the destination struct.
The callback is executed after converting each row into map[column]value and before structmap mapping. Returning an error will abort the scan.
func (*QueryResult) ScanValue ¶
func (qr *QueryResult) ScanValue(dest any, columnName string, rowIndex ...int) error
ScanValue scans a single value from the specified column into the destination. If rowIndex is not provided, it defaults to 0 (first row). Automatically converts the value to the target type using structmap. The dest parameter should be a pointer to the target type.
Example:
var age int
if err := result.ScanValue(&age, "age"); err != nil {
return err
}
fmt.Printf("Age: %d\n", age) // Age: 25
// Get value from second row
var name string
if err := result.ScanValue(&name, "name", 1); err != nil {
return err
}
// Struct example
type User struct {
Name string `json:"name"`
Age int `json:"age"`
}
var user User
if err := result.ScanValue(&user, "data"); err != nil {
return err
}
func (*QueryResult) SetPage ¶
func (qr *QueryResult) SetPage(page int)
SetPage sets pagination page number.
func (*QueryResult) SetPageSize ¶
func (qr *QueryResult) SetPageSize(size int)
SetPageSize sets pagination page size.
func (*QueryResult) SetTotalCount ¶
func (qr *QueryResult) SetTotalCount(total int64)
SetTotalCount sets pagination total.
func (*QueryResult) String ¶
func (qr *QueryResult) String(columnName string) (string, error)
String returns the first row's value for the specified column as string.
Example:
name, err := result.String("name")
func (*QueryResult) ToMaps ¶
func (qr *QueryResult) ToMaps() ([]map[string]any, error)
ToMaps converts the QueryResult into a slice of maps. Each map represents a row with column names as keys.
Example:
maps, err := result.ToMaps()
for _, m := range maps {
fmt.Printf("Name: %s, Age: %d\n", m["name"], m["age"])
}
type RowData ¶
func (*RowData) GetDatabase ¶
GetDatabase implements def.RowData.
func (*RowData) GetFieldDatas ¶
GetFieldDatas implements def.RowData.
func (*RowData) GetFields ¶
GetFieldsString implements BuildSql interface Returns a comma-separated string of field names
func (*RowData) GetFieldsSkipPk ¶
func (*RowData) GetPkFields ¶
GetPkFieldsString implements BuildSql interface Returns a comma-separated string of primary key field names
func (*RowData) GetReplaceSql ¶
GetReplaceSql implements def.RowData.
func (*RowData) GetTableName ¶
GetTableName implements def.RowData.
func (*RowData) GetValues ¶
GetValuesString implements BuildSql interface Returns a comma-separated string of values and the field names all parameter: if true, includes all fields; if false, excludes primary key fields
func (*RowData) GetValuesAsObj ¶
type TableColumnInfo ¶
type TableColumnInfo = FieldInfo
TableColumnInfo is kept as an alias to the unified FieldInfo for compatibility. For introspected columns, set ColumnName (preferred) or Name.
type TableConstraint ¶
type TableConstraint struct {
Name string // 约束名(可选,数据库会自动生成)
Table string // 所属表
Columns []string // 作用列(复合主键/联合唯一等场景)
Kind Kind // 约束类型
Expression string // CHECK 表达式、DEFAULT 值等占位
Ref *TableReference // 外键专用
}
Constraint 一条完整的约束规则
func (*TableConstraint) GetColumns ¶
func (t *TableConstraint) GetColumns() []string
GetColumns implements def.TableConstraint.
func (*TableConstraint) GetName ¶
func (t *TableConstraint) GetName() string
GetName implements def.TableConstraint.
func (*TableConstraint) GetType ¶
func (t *TableConstraint) GetType() def.Kind
GetType implements def.TableConstraint.
type TableConstraints ¶
type TableConstraints struct {
Constraints []TableConstraint
// contains filtered or unexported fields
}
func (*TableConstraints) GetPrimaryKeys ¶
func (c *TableConstraints) GetPrimaryKeys() []string
func (*TableConstraints) GetUniqueKeys ¶
func (c *TableConstraints) GetUniqueKeys() []string
func (*TableConstraints) IsColumnNullable ¶
func (c *TableConstraints) IsColumnNullable(key string) bool
func (*TableConstraints) IsColumnPrimary ¶
func (c *TableConstraints) IsColumnPrimary(key string) bool
func (*TableConstraints) IsColumnUnique ¶
func (c *TableConstraints) IsColumnUnique(key string) bool
type TableReference ¶
TableReference 外键指向信息
type TableSpec ¶
type TableSpec struct {
DBType string
DBSubType string
// Identifiers
Database string
Schema string
Name string // Backward compatibility; if empty, fall back to Name
// Columns: unified source of truth.
// When built from structs (desired schema), these are populated from FieldInfo-equivalent data.
// When introspected from DB (current schema), these come from database metadata.
Columns []ColumnSpec
// Constraints and indexes
Constraints TableConstraints
Indexes []DBIndex
CompositeForeignKeys []CompositeForeignKey
CompositeIndexes []CompositeIndex
FieldMappings []FieldMapping // Column rename mappings
Comment string // table comment from DB introspection ("" when unsupported)
// contains filtered or unexported fields
}
TableSpec is the unified description of a table, used both for: 1) Desired schema (from code/structs) for migration. 2) Current schema (introspected from DB) for comparison.
func (*TableSpec) ColumnExist ¶
func (*TableSpec) FilterColumns ¶
func (*TableSpec) GetColumn ¶
func (t *TableSpec) GetColumn(idx int) def.ColumnInfo
GetColumn implements def.TableInfo.
func (*TableSpec) GetColumnIndex ¶
GetColumnIndex returns the index of a column by name (case-insensitive), matching ColumnName first, then falling back to Name.
func (*TableSpec) GetColumnNameSet ¶
func (*TableSpec) GetColumnNameSetWithoutPK ¶
func (*TableSpec) GetColumns ¶
func (t *TableSpec) GetColumns() []def.ColumnInfo
GetColumns implements def.TableInfo.
func (*TableSpec) GetComment ¶
GetComment implements def.TableInfo.
func (*TableSpec) GetCompositeForeignKeys ¶
func (t *TableSpec) GetCompositeForeignKeys() []def.CompositeForeignKey
GetCompositeForeignKeys implements def.TableInfo.
func (*TableSpec) GetCompositeIndexes ¶
func (t *TableSpec) GetCompositeIndexes() []def.CompositeIndex
GetCompositeIndexes implements def.TableInfo.
func (*TableSpec) GetConstraints ¶
func (t *TableSpec) GetConstraints() []def.TableConstraint
GetConstraints implements def.TableInfo.
func (*TableSpec) GetDatabase ¶
GetDatabase returns the database name if set.
func (*TableSpec) GetPrimaryKeys ¶
func (*TableSpec) GetType ¶
GetType implements def.TableInfo.