Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix "gf gen pb" api and ctrl not working well. #3076

Merged
merged 11 commits into from
Nov 8, 2023
Prev Previous commit
Next Next commit
fix: 修改单词错误filed改为field
  • Loading branch information
hailaz committed Nov 2, 2023
commit 5b2bbbaf4c404fd74a7ba5d27423affe64df5c78
2 changes: 1 addition & 1 deletion contrib/drivers/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (d *Driver) TableFields(ctx context.Context, table string, schema ...string
isNull = false
fieldType = m["type"].String()
)
// in clickhouse , filed type like is Nullable(int)
// in clickhouse , field type like is Nullable(int)
fieldsResult, _ := gregex.MatchString(`^Nullable\((.*?)\)`, fieldType)
if len(fieldsResult) == 2 {
isNull = true
Expand Down
2 changes: 1 addition & 1 deletion contrib/drivers/mysql/mysql_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4118,7 +4118,7 @@ func Test_Model_Embedded_Filter(t *testing.T) {
// Password string
// Nickname string
// CreateTime string
// NoneExistFiled string
// NoneExistField string
// }
// data := User{
// Id: 1,
Expand Down
2 changes: 1 addition & 1 deletion contrib/drivers/sqlite/sqlite_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3726,7 +3726,7 @@ func Test_Model_Insert_KeyFieldNameMapping_Error(t *testing.T) {
Password string
Nickname string
CreateTime string
NoneExistFiled string
NoneExistField string
}
data := User{
Id: 1,
Expand Down
2 changes: 1 addition & 1 deletion contrib/drivers/sqlitecgo/sqlite_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3765,7 +3765,7 @@ func Test_Model_Insert_KeyFieldNameMapping_Error(t *testing.T) {
Password string
Nickname string
CreateTime string
NoneExistFiled string
NoneExistField string
}
data := User{
Id: 1,
Expand Down
6 changes: 3 additions & 3 deletions database/gdb/gdb_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ func (c *Core) HasTable(name string) (bool, error) {
return result.Bool(), nil
}

// isSoftCreatedFieldName checks and returns whether given filed name is an automatic-filled created time.
// isSoftCreatedFieldName checks and returns whether given field name is an automatic-filled created time.
func (c *Core) isSoftCreatedFieldName(fieldName string) bool {
if fieldName == "" {
return false
Expand All @@ -794,9 +794,9 @@ func (c *Core) isSoftCreatedFieldName(fieldName string) bool {
if utils.EqualFoldWithoutChars(fieldName, config.CreatedAt) {
return true
}
return gstr.InArray(append([]string{config.CreatedAt}, createdFiledNames...), fieldName)
return gstr.InArray(append([]string{config.CreatedAt}, createdFieldNames...), fieldName)
}
for _, v := range createdFiledNames {
for _, v := range createdFieldNames {
if utils.EqualFoldWithoutChars(fieldName, v) {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions database/gdb/gdb_core_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ type ConfigNode struct {
ExecTimeout time.Duration `json:"execTimeout"` // (Optional) Max exec time for dml.
TranTimeout time.Duration `json:"tranTimeout"` // (Optional) Max exec time for a transaction.
PrepareTimeout time.Duration `json:"prepareTimeout"` // (Optional) Max exec time for prepare operation.
CreatedAt string `json:"createdAt"` // (Optional) The filed name of table for automatic-filled created datetime.
UpdatedAt string `json:"updatedAt"` // (Optional) The filed name of table for automatic-filled updated datetime.
DeletedAt string `json:"deletedAt"` // (Optional) The filed name of table for automatic-filled updated datetime.
CreatedAt string `json:"createdAt"` // (Optional) The field name of table for automatic-filled created datetime.
UpdatedAt string `json:"updatedAt"` // (Optional) The field name of table for automatic-filled updated datetime.
DeletedAt string `json:"deletedAt"` // (Optional) The field name of table for automatic-filled updated datetime.
TimeMaintainDisabled bool `json:"timeMaintainDisabled"` // (Optional) Disable the automatic time maintaining feature.
}

Expand Down
2 changes: 1 addition & 1 deletion database/gdb/gdb_model_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (m *Model) Scan(pointer interface{}, where ...interface{}) error {
// Where("u1.id<2").
// ScanAndCount(&users, &count, false)
func (m *Model) ScanAndCount(pointer interface{}, totalCount *int, useFieldForCount bool) (err error) {
// support Fileds with *, example: .Fileds("a.*, b.name"). Count sql is select count(1) from xxx
// support Fields with *, example: .Fields("a.*, b.name"). Count sql is select count(1) from xxx
countModel := m.Clone()
// If useFieldForCount is false, set the fields to a constant value of 1 for counting
if !useFieldForCount {
Expand Down
12 changes: 6 additions & 6 deletions database/gdb/gdb_model_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
)

var (
createdFiledNames = []string{"created_at", "create_at"} // Default filed names of table for automatic-filled created datetime.
updatedFiledNames = []string{"updated_at", "update_at"} // Default filed names of table for automatic-filled updated datetime.
deletedFiledNames = []string{"deleted_at", "delete_at"} // Default filed names of table for automatic-filled deleted datetime.
createdFieldNames = []string{"created_at", "create_at"} // Default field names of table for automatic-filled created datetime.
updatedFieldNames = []string{"updated_at", "update_at"} // Default field names of table for automatic-filled updated datetime.
deletedFieldNames = []string{"deleted_at", "delete_at"} // Default field names of table for automatic-filled deleted datetime.
)

// Unscoped disables the auto-update time feature for insert, update and delete options.
Expand Down Expand Up @@ -47,7 +47,7 @@ func (m *Model) getSoftFieldNameCreated(schema string, table string) string {
if config.CreatedAt != "" {
return m.getSoftFieldName(schema, tableName, []string{config.CreatedAt})
}
return m.getSoftFieldName(schema, tableName, createdFiledNames)
return m.getSoftFieldName(schema, tableName, createdFieldNames)
}

// getSoftFieldNameUpdate checks and returns the field name for record updating time.
Expand All @@ -68,7 +68,7 @@ func (m *Model) getSoftFieldNameUpdated(schema string, table string) (field stri
if config.UpdatedAt != "" {
return m.getSoftFieldName(schema, tableName, []string{config.UpdatedAt})
}
return m.getSoftFieldName(schema, tableName, updatedFiledNames)
return m.getSoftFieldName(schema, tableName, updatedFieldNames)
}

// getSoftFieldNameDelete checks and returns the field name for record deleting time.
Expand All @@ -89,7 +89,7 @@ func (m *Model) getSoftFieldNameDeleted(schema string, table string) (field stri
if config.DeletedAt != "" {
return m.getSoftFieldName(schema, tableName, []string{config.DeletedAt})
}
return m.getSoftFieldName(schema, tableName, deletedFiledNames)
return m.getSoftFieldName(schema, tableName, deletedFieldNames)
}

// getSoftFieldName retrieves and returns the field name of the table for possible key.
Expand Down
6 changes: 3 additions & 3 deletions database/gdb/gdb_type_result_scanlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func doScanList(in doScanListInput) (err error) {
relationBindToFieldName string // Eg: relationKV: id:uid -> uid
)
if len(in.RelationFields) > 0 {
// The relation key string of table filed name and attribute name
// The relation key string of table field name and attribute name
// can be joined with char '=' or ':'.
array := gstr.SplitAndTrim(in.RelationFields, "=")
if len(array) == 1 {
Expand Down Expand Up @@ -363,11 +363,11 @@ func doScanList(in doScanListInput) (err error) {
if in.RelationFields != "" && !relationBindToFieldNameChecked {
relationFromAttrField = relationFromAttrValue.FieldByName(relationBindToFieldName)
if !relationFromAttrField.IsValid() {
filedMap, _ := gstructs.FieldMap(gstructs.FieldMapInput{
fieldMap, _ := gstructs.FieldMap(gstructs.FieldMapInput{
Pointer: relationFromAttrValue,
RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag,
})
if key, _ := gutil.MapPossibleItemByKey(gconv.Map(filedMap), relationBindToFieldName); key == "" {
if key, _ := gutil.MapPossibleItemByKey(gconv.Map(fieldMap), relationBindToFieldName); key == "" {
return gerror.NewCodef(
gcode.CodeInvalidParameter,
`cannot find possible related attribute name "%s" from given relation fields "%s"`,
Expand Down
6 changes: 3 additions & 3 deletions util/gconv/gconv_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func doScanList(
relationBindToFieldName string // Eg: relationKV: id:uid -> uid
)
if len(relationFields) > 0 {
// The relation key string of table filed name and attribute name
// The relation key string of table field name and attribute name
// can be joined with char '=' or ':'.
array := utils.SplitAndTrim(relationFields, "=")
if len(array) == 1 {
Expand Down Expand Up @@ -396,12 +396,12 @@ func doScanList(
relationFromAttrField = relationFromAttrValue.FieldByName(relationBindToFieldName)
if !relationFromAttrField.IsValid() {
var (
filedMap, _ = gstructs.FieldMap(gstructs.FieldMapInput{
fieldMap, _ = gstructs.FieldMap(gstructs.FieldMapInput{
Pointer: relationFromAttrValue,
RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag,
})
)
if key, _ := utils.MapPossibleItemByKey(Map(filedMap), relationBindToFieldName); key == "" {
if key, _ := utils.MapPossibleItemByKey(Map(fieldMap), relationBindToFieldName); key == "" {
return gerror.NewCodef(
gcode.CodeInvalidParameter,
`cannot find possible related attribute name "%s" from given relation fields "%s"`,
Expand Down