Skip to content

Commit

Permalink
完成final的实现
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Nov 3, 2024
1 parent 8caa292 commit 1dbbd44
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
31 changes: 31 additions & 0 deletions finalHint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package data

import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/hints"
)

type FinalHint struct {
}

func (indexHint FinalHint) Build(builder clause.Builder) {
builder.WriteString(" FINAL ")
}
func (indexHint FinalHint) ModifyStatement(stmt *gorm.Statement) {
for _, name := range []string{"FROM"} {
clause := stmt.Clauses[name]

if clause.AfterExpression == nil {
clause.AfterExpression = indexHint
} else {
clause.AfterExpression = hints.Exprs{clause.AfterExpression, indexHint}
}

if name == "FROM" {
clause.Builder = hints.IndexHintFromClauseBuilder
}

stmt.Clauses[name] = clause
}
}
24 changes: 0 additions & 24 deletions tableSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1123,27 +1123,3 @@ func snakeString(s string) string {
// 统一转小写
return strings.ToLower(string(data[:]))
}

type FinalHint struct {
}

func (indexHint FinalHint) Build(builder clause.Builder) {
builder.WriteString(" FINAL ")
}
func (indexHint FinalHint) ModifyStatement(stmt *gorm.Statement) {
for _, name := range []string{"FROM"} {
clause := stmt.Clauses[name]

if clause.AfterExpression == nil {
clause.AfterExpression = indexHint
} else {
clause.AfterExpression = hints.Exprs{clause.AfterExpression, indexHint}
}

if name == "FROM" {
clause.Builder = hints.IndexHintFromClauseBuilder
}

stmt.Clauses[name] = clause
}
}

0 comments on commit 1dbbd44

Please sign in to comment.