本文整理匯總了Golang中github.com/xormplus/core.Column.Indexes方法的典型用法代碼示例。如果您正苦於以下問題:Golang Column.Indexes方法的具體用法?Golang Column.Indexes怎麽用?Golang Column.Indexes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/xormplus/core.Column
的用法示例。
在下文中一共展示了Column.Indexes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetColumns
func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
args := []interface{}{}
s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale
from sys.columns a left join sys.types b on a.user_type_id=b.user_type_id
where a.object_id=object_id('` + tableName + `')`
db.LogSQL(s, args)
rows, err := db.DB().Query(s, args...)
if err != nil {
return nil, nil, err
}
defer rows.Close()
cols := make(map[string]*core.Column)
colSeq := make([]string, 0)
for rows.Next() {
var name, ctype, precision, scale string
var maxLen int
err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale)
if err != nil {
return nil, nil, err
}
col := new(core.Column)
col.Indexes = make(map[string]int)
col.Length = maxLen
col.Name = strings.Trim(name, "` ")
ct := strings.ToUpper(ctype)
switch ct {
case "DATETIMEOFFSET":
col.SQLType = core.SQLType{core.TimeStampz, 0, 0}
case "NVARCHAR":
col.SQLType = core.SQLType{core.NVarchar, 0, 0}
case "IMAGE":
col.SQLType = core.SQLType{core.VarBinary, 0, 0}
default:
if _, ok := core.SqlTypes[ct]; ok {
col.SQLType = core.SQLType{ct, 0, 0}
} else {
return nil, nil, errors.New(fmt.Sprintf("unknow colType %v for %v - %v",
ct, tableName, col.Name))
}
}
if col.SQLType.IsText() || col.SQLType.IsTime() {
if col.Default != "" {
col.Default = "'" + col.Default + "'"
} else {
if col.DefaultIsEmpty {
col.Default = "''"
}
}
}
cols[col.Name] = col
colSeq = append(colSeq, col.Name)
}
return colSeq, cols, nil
}