add cockroach support
This commit is contained in:
parent
4e59597a49
commit
c6ec19c5ed
|
@ -1022,8 +1022,8 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att
|
||||||
|
|
||||||
col.Nullable = (isNullable == "YES")
|
col.Nullable = (isNullable == "YES")
|
||||||
|
|
||||||
switch dataType {
|
switch strings.ToLower(dataType) {
|
||||||
case "character varying", "character":
|
case "character varying", "character", "string":
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.Varchar, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: schemas.Varchar, DefaultLength: 0, DefaultLength2: 0}
|
||||||
case "timestamp without time zone":
|
case "timestamp without time zone":
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 0, DefaultLength2: 0}
|
||||||
|
@ -1035,11 +1035,20 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.Bool, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: schemas.Bool, DefaultLength: 0, DefaultLength2: 0}
|
||||||
case "time without time zone":
|
case "time without time zone":
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.Time, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: schemas.Time, DefaultLength: 0, DefaultLength2: 0}
|
||||||
|
case "bytes":
|
||||||
|
col.SQLType = schemas.SQLType{Name: schemas.Binary, DefaultLength: 0, DefaultLength2: 0}
|
||||||
case "oid":
|
case "oid":
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.BigInt, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: schemas.BigInt, DefaultLength: 0, DefaultLength2: 0}
|
||||||
default:
|
default:
|
||||||
|
startIdx := strings.Index(strings.ToLower(dataType), "string(")
|
||||||
|
if startIdx != -1 && strings.HasSuffix(dataType, ")") {
|
||||||
|
length := dataType[startIdx+8 : len(dataType)-1]
|
||||||
|
l, _ := strconv.Atoi(length)
|
||||||
|
col.SQLType = schemas.SQLType{Name: "STRING", DefaultLength: l, DefaultLength2: 0}
|
||||||
|
} else {
|
||||||
col.SQLType = schemas.SQLType{Name: strings.ToUpper(dataType), DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: strings.ToUpper(dataType), DefaultLength: 0, DefaultLength2: 0}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if _, ok := schemas.SqlTypes[col.SQLType.Name]; !ok {
|
if _, ok := schemas.SqlTypes[col.SQLType.Name]; !ok {
|
||||||
return nil, nil, fmt.Errorf("Unknown colType: %v", dataType)
|
return nil, nil, fmt.Errorf("Unknown colType: %v", dataType)
|
||||||
}
|
}
|
||||||
|
@ -1128,6 +1137,10 @@ func (db *postgres) GetIndexes(ctx context.Context, tableName string) (map[strin
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if indexName == "primary" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
indexName = strings.Trim(indexName, `" `)
|
indexName = strings.Trim(indexName, `" `)
|
||||||
if strings.HasSuffix(indexName, "_pkey") {
|
if strings.HasSuffix(indexName, "_pkey") {
|
||||||
continue
|
continue
|
||||||
|
@ -1149,7 +1162,7 @@ func (db *postgres) GetIndexes(ctx context.Context, tableName string) (map[strin
|
||||||
|
|
||||||
index := &schemas.Index{Name: indexName, Type: indexType, Cols: make([]string, 0)}
|
index := &schemas.Index{Name: indexName, Type: indexType, Cols: make([]string, 0)}
|
||||||
for _, colName := range colNames {
|
for _, colName := range colNames {
|
||||||
index.Cols = append(index.Cols, strings.Trim(colName, `" `))
|
index.Cols = append(index.Cols, strings.TrimSpace(strings.Replace(colName, `"`, "", -1)))
|
||||||
}
|
}
|
||||||
index.IsRegular = isRegular
|
index.IsRegular = isRegular
|
||||||
indexes[index.Name] = index
|
indexes[index.Name] = index
|
||||||
|
|
11
engine.go
11
engine.go
|
@ -284,12 +284,19 @@ func (engine *Engine) loadTableInfo(table *schemas.Table) error {
|
||||||
}
|
}
|
||||||
table.Indexes = indexes
|
table.Indexes = indexes
|
||||||
|
|
||||||
|
var seq int
|
||||||
for _, index := range indexes {
|
for _, index := range indexes {
|
||||||
for _, name := range index.Cols {
|
for _, name := range index.Cols {
|
||||||
if col := table.GetColumn(name); col != nil {
|
parts := strings.Split(name, " ")
|
||||||
|
if len(parts) > 1 {
|
||||||
|
if parts[1] == "DESC" {
|
||||||
|
seq = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if col := table.GetColumn(parts[0]); col != nil {
|
||||||
col.Indexes[index.Name] = index.Type
|
col.Indexes[index.Name] = index.Type
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("Unknown col %s in index %v of table %v, columns %v", name, index.Name, table.Name, table.ColumnsSeq())
|
return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
go test -db=postgres -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable"
|
Loading…
Reference in New Issue