mirror of https://github.com/go-gorm/gorm.git
Fix some typos (#4294)
This commit is contained in:
parent
7701c88507
commit
15a46bc042
|
@ -84,7 +84,7 @@ jobs:
|
||||||
matrix:
|
matrix:
|
||||||
dbversion: ['postgres:latest', 'postgres:11', 'postgres:10']
|
dbversion: ['postgres:latest', 'postgres:11', 'postgres:10']
|
||||||
go: ['1.16', '1.15', '1.14']
|
go: ['1.16', '1.15', '1.14']
|
||||||
platform: [ubuntu-latest] # can not run in macOS and widnowsOS
|
platform: [ubuntu-latest] # can not run in macOS and Windows
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
|
@ -33,8 +33,8 @@ var (
|
||||||
ErrEmptySlice = errors.New("empty slice found")
|
ErrEmptySlice = errors.New("empty slice found")
|
||||||
// ErrDryRunModeUnsupported dry run mode unsupported
|
// ErrDryRunModeUnsupported dry run mode unsupported
|
||||||
ErrDryRunModeUnsupported = errors.New("dry run mode unsupported")
|
ErrDryRunModeUnsupported = errors.New("dry run mode unsupported")
|
||||||
// ErrInvaildDB invalid db
|
// ErrInvalidDB invalid db
|
||||||
ErrInvaildDB = errors.New("invalid db")
|
ErrInvalidDB = errors.New("invalid db")
|
||||||
// ErrInvalidValue invalid value
|
// ErrInvalidValue invalid value
|
||||||
ErrInvalidValue = errors.New("invalid value")
|
ErrInvalidValue = errors.New("invalid value")
|
||||||
// ErrInvalidValueOfLength invalid values do not match length
|
// ErrInvalidValueOfLength invalid values do not match length
|
||||||
|
|
2
gorm.go
2
gorm.go
|
@ -348,7 +348,7 @@ func (db *DB) DB() (*sql.DB, error) {
|
||||||
return sqldb, nil
|
return sqldb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, ErrInvaildDB
|
return nil, ErrInvalidDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) getInstance() *DB {
|
func (db *DB) getInstance() *DB {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func isPrintable(s []byte) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var convertableTypes = []reflect.Type{reflect.TypeOf(time.Time{}), reflect.TypeOf(false), reflect.TypeOf([]byte{})}
|
var convertibleTypes = []reflect.Type{reflect.TypeOf(time.Time{}), reflect.TypeOf(false), reflect.TypeOf([]byte{})}
|
||||||
|
|
||||||
func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, avars ...interface{}) string {
|
func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, avars ...interface{}) string {
|
||||||
var convertParams func(interface{}, int)
|
var convertParams func(interface{}, int)
|
||||||
|
@ -91,7 +91,7 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
|
||||||
} else if rv.Kind() == reflect.Ptr && !rv.IsZero() {
|
} else if rv.Kind() == reflect.Ptr && !rv.IsZero() {
|
||||||
convertParams(reflect.Indirect(rv).Interface(), idx)
|
convertParams(reflect.Indirect(rv).Interface(), idx)
|
||||||
} else {
|
} else {
|
||||||
for _, t := range convertableTypes {
|
for _, t := range convertibleTypes {
|
||||||
if rv.Type().ConvertibleTo(t) {
|
if rv.Type().ConvertibleTo(t) {
|
||||||
convertParams(rv.Convert(t).Interface(), idx)
|
convertParams(rv.Convert(t).Interface(), idx)
|
||||||
return
|
return
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (db *PreparedStmtDB) GetDBConn() (*sql.DB, error) {
|
||||||
return sqldb, nil
|
return sqldb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, ErrInvaildDB
|
return nil, ErrInvalidDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *PreparedStmtDB) Close() {
|
func (db *PreparedStmtDB) Close() {
|
||||||
|
|
|
@ -73,16 +73,16 @@ func (ns NamingStrategy) IndexName(table, column string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns NamingStrategy) formatName(prefix, table, name string) string {
|
func (ns NamingStrategy) formatName(prefix, table, name string) string {
|
||||||
formatedName := strings.Replace(fmt.Sprintf("%v_%v_%v", prefix, table, name), ".", "_", -1)
|
formattedName := strings.Replace(fmt.Sprintf("%v_%v_%v", prefix, table, name), ".", "_", -1)
|
||||||
|
|
||||||
if utf8.RuneCountInString(formatedName) > 64 {
|
if utf8.RuneCountInString(formattedName) > 64 {
|
||||||
h := sha1.New()
|
h := sha1.New()
|
||||||
h.Write([]byte(formatedName))
|
h.Write([]byte(formattedName))
|
||||||
bs := h.Sum(nil)
|
bs := h.Sum(nil)
|
||||||
|
|
||||||
formatedName = fmt.Sprintf("%v%v%v", prefix, table, name)[0:56] + string(bs)[:8]
|
formattedName = fmt.Sprintf("%v%v%v", prefix, table, name)[0:56] + string(bs)[:8]
|
||||||
}
|
}
|
||||||
return formatedName
|
return formattedName
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -89,7 +89,7 @@ func (schema *Schema) parseRelation(field *Field) *Relationship {
|
||||||
}
|
}
|
||||||
|
|
||||||
if relation.Type == has {
|
if relation.Type == has {
|
||||||
// don't add relations to embeded schema, which might be shared
|
// don't add relations to embedded schema, which might be shared
|
||||||
if relation.FieldSchema != relation.Schema && relation.Polymorphic == nil && field.OwnerSchema == nil {
|
if relation.FieldSchema != relation.Schema && relation.Polymorphic == nil && field.OwnerSchema == nil {
|
||||||
relation.FieldSchema.Relationships.Relations["_"+relation.Schema.Name+"_"+relation.Name] = relation
|
relation.FieldSchema.Relationships.Relations["_"+relation.Schema.Name+"_"+relation.Name] = relation
|
||||||
}
|
}
|
||||||
|
@ -308,9 +308,9 @@ func (schema *Schema) buildMany2ManyRelation(relation *Relationship, field *Fiel
|
||||||
f.Size = fieldsMap[f.Name].Size
|
f.Size = fieldsMap[f.Name].Size
|
||||||
}
|
}
|
||||||
relation.JoinTable.PrimaryFields = append(relation.JoinTable.PrimaryFields, f)
|
relation.JoinTable.PrimaryFields = append(relation.JoinTable.PrimaryFields, f)
|
||||||
ownPriamryField := schema == fieldsMap[f.Name].Schema && ownFieldsMap[f.Name]
|
ownPrimaryField := schema == fieldsMap[f.Name].Schema && ownFieldsMap[f.Name]
|
||||||
|
|
||||||
if ownPriamryField {
|
if ownPrimaryField {
|
||||||
joinRel := relation.JoinTable.Relationships.Relations[relName]
|
joinRel := relation.JoinTable.Relationships.Relations[relName]
|
||||||
joinRel.Field = relation.Field
|
joinRel.Field = relation.Field
|
||||||
joinRel.References = append(joinRel.References, &Reference{
|
joinRel.References = append(joinRel.References, &Reference{
|
||||||
|
@ -331,7 +331,7 @@ func (schema *Schema) buildMany2ManyRelation(relation *Relationship, field *Fiel
|
||||||
relation.References = append(relation.References, &Reference{
|
relation.References = append(relation.References, &Reference{
|
||||||
PrimaryKey: fieldsMap[f.Name],
|
PrimaryKey: fieldsMap[f.Name],
|
||||||
ForeignKey: f,
|
ForeignKey: f,
|
||||||
OwnPrimaryKey: ownPriamryField,
|
OwnPrimaryKey: ownPrimaryField,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ func checkSchema(t *testing.T, s *schema.Schema, v schema.Schema, primaryFields
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
t.Errorf("schema %v failed to found priamry key: %v", s, field)
|
t.Errorf("schema %v failed to found primary key: %v", s, field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -328,7 +328,7 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) []
|
||||||
} else if _, ok := v[key].(Valuer); ok {
|
} else if _, ok := v[key].(Valuer); ok {
|
||||||
conds = append(conds, clause.Eq{Column: key, Value: v[key]})
|
conds = append(conds, clause.Eq{Column: key, Value: v[key]})
|
||||||
} else {
|
} else {
|
||||||
// optimize relect value length
|
// optimize reflect value length
|
||||||
valueLen := reflectValue.Len()
|
valueLen := reflectValue.Len()
|
||||||
values := make([]interface{}, valueLen)
|
values := make([]interface{}, valueLen)
|
||||||
for i := 0; i < valueLen; i++ {
|
for i := 0; i < valueLen; i++ {
|
||||||
|
@ -398,7 +398,7 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) []
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
switch reflectValue.Kind() {
|
switch reflectValue.Kind() {
|
||||||
case reflect.Slice, reflect.Array:
|
case reflect.Slice, reflect.Array:
|
||||||
// optimize relect value length
|
// optimize reflect value length
|
||||||
valueLen := reflectValue.Len()
|
valueLen := reflectValue.Len()
|
||||||
values := make([]interface{}, valueLen)
|
values := make([]interface{}, valueLen)
|
||||||
for i := 0; i < valueLen; i++ {
|
for i := 0; i < valueLen; i++ {
|
||||||
|
|
Loading…
Reference in New Issue