From 6c23f8a5eb964a68898929e43daa4859ea474fb2 Mon Sep 17 00:00:00 2001 From: WaterCool8258 Date: Thu, 14 Nov 2024 11:31:56 +0800 Subject: [PATCH] feat:extract table comments --- internal/generate/query.go | 1 + internal/parser/method.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/internal/generate/query.go b/internal/generate/query.go index c9e27e10..c18d2ec9 100644 --- a/internal/generate/query.go +++ b/internal/generate/query.go @@ -191,6 +191,7 @@ func (b *QueryStructMeta) ReviseDIYMethod() error { } if tableName == nil { methods = append(methods, parser.DefaultMethodTableName(b.ModelStructName)) + methods = append(methods, parser.DefaultMethodTableComment(b.ModelStructName, b.TableComment)) } else { // e.g. return "@@table" => return TableNameUser tableName.Body = strings.ReplaceAll(tableName.Body, "\"@@table\"", "TableName"+b.ModelStructName) diff --git a/internal/parser/method.go b/internal/parser/method.go index b5800830..2811559d 100644 --- a/internal/parser/method.go +++ b/internal/parser/method.go @@ -19,6 +19,16 @@ func DefaultMethodTableName(structName string) *Method { } } +func DefaultMethodTableComment(structName, comment string) *Method { + return &Method{ + Receiver: Param{IsPointer: true, Type: structName}, + MethodName: "TableComment", + Doc: fmt.Sprint("TableComment ", structName, "'s table comment "), + Result: []Param{{Type: "string"}}, + Body: fmt.Sprintf("{\n\treturn `%s`\n} ", comment), + } +} + // Method Apply to query struct and base struct custom method type Method struct { Receiver Param