Skip to content

Commit

Permalink
cmd/gf: add DaMeng database driver support (#3606)
Browse files Browse the repository at this point in the history
  • Loading branch information
Insua authored May 30, 2024
1 parent 57583a9 commit bd8d046
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/gf/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.7.1
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.7.1
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.7.1
github.com/gogf/gf/contrib/drivers/dm/v2 v2.7.1
github.com/gogf/gf/v2 v2.7.1
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f
github.com/olekukonko/tablewriter v0.0.5
Expand Down
1 change: 1 addition & 0 deletions cmd/gf/go.work
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ replace (
github.com/gogf/gf/contrib/drivers/oracle/v2 => ../../contrib/drivers/oracle
github.com/gogf/gf/contrib/drivers/pgsql/v2 => ../../contrib/drivers/pgsql
github.com/gogf/gf/contrib/drivers/sqlite/v2 => ../../contrib/drivers/sqlite
github.com/gogf/gf/contrib/drivers/dm/v2 => ../../contrib/drivers/dm
github.com/gogf/gf/v2 => ../../
)
1 change: 1 addition & 0 deletions cmd/gf/internal/cmd/cmd_gen_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package cmd

import (
_ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
_ "github.com/gogf/gf/contrib/drivers/dm/v2"
_ "github.com/gogf/gf/contrib/drivers/mssql/v2"
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
Expand Down
8 changes: 4 additions & 4 deletions cmd/gf/internal/cmd/gendao/gendao_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func generateDaoSingle(ctx context.Context, in generateDaoSingleInput) {
mlog.Fatalf(`fetching tables fields failed for table "%s": %+v`, in.TableName, err)
}
var (
tableNameCamelCase = gstr.CaseCamel(in.NewTableName)
tableNameCamelLowerCase = gstr.CaseCamelLower(in.NewTableName)
tableNameCamelCase = gstr.CaseCamel(strings.ToLower(in.NewTableName))
tableNameCamelLowerCase = gstr.CaseCamelLower(strings.ToLower(in.NewTableName))
tableNameSnakeCase = gstr.CaseSnake(in.NewTableName)
importPrefix = in.ImportPrefix
)
Expand Down Expand Up @@ -178,7 +178,7 @@ func generateColumnNamesForDao(fieldMap map[string]*gdb.TableField, removeFieldP
}

array[index] = []string{
" #" + gstr.CaseCamel(newFiledName) + ":",
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)) + ":",
fmt.Sprintf(` #"%s",`, field.Name),
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func generateColumnDefinitionForDao(fieldMap map[string]*gdb.TableField, removeF
newFiledName = gstr.TrimLeftStr(newFiledName, v, 1)
}
array[index] = []string{
" #" + gstr.CaseCamel(newFiledName),
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)),
" # " + "string",
" #" + fmt.Sprintf(`// %s`, comment),
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gf/internal/cmd/gendao/gendao_do.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
structDefinition, _ = generateStructDefinition(ctx, generateStructDefinitionInput{
CGenDaoInternalInput: in,
TableName: tableName,
StructName: gstr.CaseCamel(newTableName),
StructName: gstr.CaseCamel(strings.ToLower(newTableName)),
FieldMap: fieldMap,
IsDo: true,
})
Expand All @@ -61,7 +61,7 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
ctx,
in,
tableName,
gstr.CaseCamel(newTableName),
gstr.CaseCamel(strings.ToLower(newTableName)),
structDefinition,
)
in.genItems.AppendGeneratedFilePath(doFilePath)
Expand Down
4 changes: 2 additions & 2 deletions cmd/gf/internal/cmd/gendao/gendao_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) {
structDefinition, appendImports = generateStructDefinition(ctx, generateStructDefinitionInput{
CGenDaoInternalInput: in,
TableName: tableName,
StructName: gstr.CaseCamel(newTableName),
StructName: gstr.CaseCamel(strings.ToLower(newTableName)),
FieldMap: fieldMap,
IsDo: false,
})
entityContent = generateEntityContent(
ctx,
in,
newTableName,
gstr.CaseCamel(newTableName),
gstr.CaseCamel(strings.ToLower(newTableName)),
structDefinition,
appendImports,
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gf/internal/cmd/gendao/gendao_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func generateStructFieldDefinition(
}

attrLines = []string{
" #" + gstr.CaseCamel(newFiledName),
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)),
" #" + localTypeNameStr,
}
attrLines = append(attrLines, fmt.Sprintf(` #%sjson:"%s"`, tagKey, jsonTag))
Expand Down

0 comments on commit bd8d046

Please sign in to comment.