mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【feat】 添加postgresql数据库支持,【修复】pg数据库的代码生成功能
This commit is contained in:
@@ -44,8 +44,13 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *restfulx.ReqCtx) {
|
||||
|
||||
// Get{{.ClassName}} 获取{{.FunctionName}}
|
||||
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
{{.PkJsonField}} := restfulx.PathParamInt(rc, "{{.PkJsonField}}")
|
||||
rc.ResData = p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}}))
|
||||
{{ if eq .PkGoType "string" -}}
|
||||
{{.PkJsonField}} := restfulx.PathParam(rc, "{{.PkJsonField}}")
|
||||
rc.ResData = p.{{.ClassName}}App.FindOne({{.PkJsonField}})
|
||||
{{- else -}}
|
||||
{{.PkJsonField}} := restfulx.PathParamInt(rc, "{{.PkJsonField}}")
|
||||
rc.ResData = p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}}))
|
||||
{{- end}}
|
||||
}
|
||||
|
||||
// Insert{{.ClassName}} 添加{{.FunctionName}}
|
||||
@@ -67,6 +72,11 @@ func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
// Delete{{.ClassName}} 删除{{.FunctionName}}
|
||||
func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
{{.PkJsonField}} := restfulx.PathParam(rc,"{{.PkJsonField}}")
|
||||
{{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}})
|
||||
|
||||
{{ if eq .PkGoType "string" -}}
|
||||
{{.PkJsonField}}s := strings.Split({{.PkJsonField}}, ",")
|
||||
{{- else -}}
|
||||
{{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}})
|
||||
{{- end }}
|
||||
p.{{.ClassName}}App.Delete({{.PkJsonField}}s)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func Init{{.ClassName}}Router(container *restful.Container) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取{{.FunctionName}}信息").Handle(s.Get{{.ClassName}})
|
||||
}).
|
||||
Doc("获取{{.FunctionName}}信息").
|
||||
Param(ws.PathParameter("{{.PkJsonField}}", "Id").DataType("int")).
|
||||
Param(ws.PathParameter("{{.PkJsonField}}", "Id").DataType("{{.PkGoType}}")).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes(entity.{{.ClassName}}{}). // on the response
|
||||
Returns(200, "OK", entity.{{.ClassName}}{}).
|
||||
|
||||
@@ -15,11 +15,11 @@ import (
|
||||
type (
|
||||
{{.ClassName}}Model interface {
|
||||
Insert(data entity.{{.ClassName}}) *entity.{{.ClassName}}
|
||||
FindOne({{.PkJsonField}} int64) *entity.{{.ClassName}}
|
||||
FindOne({{.PkJsonField}} {{.PkGoType}}) *entity.{{.ClassName}}
|
||||
FindListPage(page, pageSize int, data entity.{{.ClassName}}) (*[]entity.{{.ClassName}}, int64)
|
||||
FindList(data entity.{{ .ClassName }}) *[]entity.{{.ClassName}}
|
||||
Update(data entity.{{.ClassName}}) *entity.{{.ClassName}}
|
||||
Delete({{.PkJsonField}}s []int64)
|
||||
Delete({{.PkJsonField}}s []{{.PkGoType}})
|
||||
}
|
||||
|
||||
{{.BusinessName}}ModelImpl struct {
|
||||
@@ -38,7 +38,7 @@ func (m *{{.BusinessName}}ModelImpl) Insert(data entity.{{$model}}) *entity.{{$m
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *{{.BusinessName}}ModelImpl) FindOne({{.PkJsonField}} int64) *entity.{{$model}} {
|
||||
func (m *{{.BusinessName}}ModelImpl) FindOne({{.PkJsonField}} {{.PkGoType}}) *entity.{{$model}} {
|
||||
resData := new(entity.{{$model}})
|
||||
db := global.Db.Table(m.table).Where("{{.PkColumn}} = ?", {{.PkJsonField}})
|
||||
{{- range $index, $column := .Columns -}}
|
||||
@@ -198,6 +198,6 @@ func (m *{{.BusinessName}}ModelImpl) Update(data entity.{{$model}}) *entity.{{$m
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *{{.BusinessName}}ModelImpl) Delete({{.PkJsonField}}s []int64) {
|
||||
func (m *{{.BusinessName}}ModelImpl) Delete({{.PkJsonField}}s []{{.PkGoType}}) {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Delete(&entity.{{$model}}{}, "{{.PkColumn}} in (?)", {{.PkJsonField}}s).Error, "删除{{.TableComment}}失败")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user