Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow overriding existing meta #1181

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions field/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(mode int) Int {
return Int{expr{e: clause.Expr{SQL: fmt.Sprintf("WEEK(?, %d)", mode), 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()}}}}
Expand Down
12 changes: 6 additions & 6 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading