smallnest / gen

Converts a database into gorm structs and RESTful api
Apache License 2.0
1.43k stars 233 forks source link

how to ignore annotations like //[ 0] id bigint null: false primary: true isArray: false auto: true col: bigint len: -1 default: [] #162

Closed yuanbaode closed 2 years ago

yuanbaode commented 3 years ago

image

how to ignore annotations above

satoshi0ta commented 3 years ago

Probably you can't delete it because it is defined in the slice. https://github.com/smallnest/gen/blob/dcfa6a9e671f82b302467334010169e19d0ca4a4/dbmeta/meta.go#L253 In my case, I added the delete flag and ran the sed command. \n is included so that you can delete only the relevant lines.

{{workdir}}/templates/model.go.tmpl

package {{.modelPackageName}}

import "time"

const (
    {{singular .StructName}}ModelName = "{{singular .StructName}}"
    {{singular .StructName}}TableName = "{{toSnakeCase .StructName}}"
)

type {{singular .StructName}} struct {
    {{range .TableInfo.Fields}}commentDeleteFlag{{.}}
    {{end}}
}
$ gen --templateDir=./templates --connstr=... && sed -i "/commentDeleteFlag/d" $$OUT_DIR/*