go-zero
go-zero copied to clipboard
goctl model parser, Field struct to have the name as declared in the model type
The field struct which has the NameOriginal, Name, DataType, Comment, SeqInIndex, OrdinalPosition, should also have the model type name so as to identify or link between the model type and field.
Field struct {
NameOriginal string
Name stringx.String
StructField string
DataType string
Comment string
SeqInIndex int
OrdinalPosition int
}
A sample generated model. eg:
type Student struct {
ID int64 `db:"id"`
Name string `db:"name"`
Age sql.NullInt64 `db:"age"`
Score sql.NullFloat64 `db:"score"`
CreateTime time.Time `db:"create_time"`
UpdateTime sql.NullTime `db:"update_time"`
}
The field name should be available while passing the data (parser.Table) object to the template.
A sample generated update function which makes use of the model type to generate the squirrel builder. eg:
query, values, err := squirrel.
Update(m.table).
SetMap(squirrel.Eq{
name: data.Name,
age: data.Age,
score: data.Score,
update_time: data.UpdateTime,
}).
Where(squirrel.Eq{"id": data.ID}).
ToSql()
What's the problem can be resolved? I saw it add a came case field, it's not need to do this action, you can use field Name
and call stringx
package instead.
I utilized the struct Field.Name as it is of type stringx, but the resultant varied for some columns as, SafeString
has been used to convert the tableName, columnName, modelFileName after converting to camel case.
If SafeString
also would have been the available in stringx there was no need to use camel-case and then safe-string in the modified files, or making utils
available as list of functions to all the templates would be useful.