From 1dbbd4445b5030d934b26d3190308bc32c0c5c8d Mon Sep 17 00:00:00 2001 From: steden <1470804@qq.com> Date: Sun, 3 Nov 2024 18:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90final=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- finalHint.go | 31 +++++++++++++++++++++++++++++++ tableSet.go | 24 ------------------------ 2 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 finalHint.go diff --git a/finalHint.go b/finalHint.go new file mode 100644 index 0000000..ac3abca --- /dev/null +++ b/finalHint.go @@ -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 + } +} diff --git a/tableSet.go b/tableSet.go index 9256564..f1ec9d3 100644 --- a/tableSet.go +++ b/tableSet.go @@ -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 - } -}