From 05aa4db5191b700c32d2e13509af8f48d7c9af12 Mon Sep 17 00:00:00 2001 From: jack li Date: Thu, 18 Jul 2024 11:25:07 +0800 Subject: [PATCH 1/3] fix: allow overriding existing meta --- generator.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/generator.go b/generator.go index 1635ab0d..fbae579f 100644 --- a/generator.go +++ b/generator.go @@ -571,13 +571,13 @@ func (g *Generator) output(fileName string, content []byte) error { func (g *Generator) pushQueryStructMeta(meta *generate.QueryStructMeta) (*genInfo, error) { structName := meta.ModelStructName - if g.Data[structName] == nil { - g.Data[structName] = &genInfo{QueryStructMeta: meta} - } - if g.Data[structName].Source != meta.Source { - return nil, fmt.Errorf("cannot generate struct with the same name from different source:%s.%s and %s.%s", - meta.StructInfo.Package, meta.ModelStructName, g.Data[structName].StructInfo.Package, g.Data[structName].ModelStructName) + if v, ok := g.Data[structName]; ok { + if v.Source != meta.Source { + return nil, fmt.Errorf("cannot generate struct with the same name from different source:%s.%s and %s.%s", + meta.StructInfo.Package, meta.ModelStructName, g.Data[structName].StructInfo.Package, g.Data[structName].ModelStructName) + } } + g.Data[structName] = &genInfo{QueryStructMeta: meta} return g.Data[structName], nil } From 117fceeacf61bfc64eb4fb50ba7b23b61facd637 Mon Sep 17 00:00:00 2001 From: jack li Date: Sat, 17 Aug 2024 12:08:10 +0800 Subject: [PATCH 2/3] feat(field): add func WEEK --- field/time.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/field/time.go b/field/time.go index ec86f0cd..e5d70458 100644 --- a/field/time.go +++ b/field/time.go @@ -119,6 +119,11 @@ func (field Time) Month() Int { return Int{expr{e: clause.Expr{SQL: "MONTH(?)", Vars: []interface{}{field.RawExpr()}}}} } +// Week equal to WEEK(self) +func (field Time) Week() Int { + return Int{expr{e: clause.Expr{SQL: "WEEK(?)", Vars: []interface{}{field.RawExpr()}}}} +} + // Day equal to DAY(self) func (field Time) Day() Int { return Int{expr{e: clause.Expr{SQL: "DAY(?)", Vars: []interface{}{field.RawExpr()}}}} From 81538d5e17c81119f19551f633e67c85fad9a3ba Mon Sep 17 00:00:00 2001 From: jack li Date: Sat, 17 Aug 2024 14:10:34 +0800 Subject: [PATCH 3/3] feat(field): week func support set mode --- field/time.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/field/time.go b/field/time.go index e5d70458..a2b3863e 100644 --- a/field/time.go +++ b/field/time.go @@ -120,8 +120,8 @@ func (field Time) Month() Int { } // Week equal to WEEK(self) -func (field Time) Week() Int { - return Int{expr{e: clause.Expr{SQL: "WEEK(?)", Vars: []interface{}{field.RawExpr()}}}} +func (field Time) Week(mode int) Int { + return Int{expr{e: clause.Expr{SQL: fmt.Sprintf("WEEK(?, %d)", mode), Vars: []interface{}{field.RawExpr()}}}} } // Day equal to DAY(self)