forked from WinterYukky/gorm-extra-clause-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.go
30 lines (25 loc) · 829 Bytes
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package gormextraclauseplugin
import "gorm.io/gorm"
// ExtraClausePlugin support plugin that not supported clause by gorm
type ExtraClausePlugin struct{}
// Name return plugin name
func (e *ExtraClausePlugin) Name() string {
return "ExtraClausePlugin"
}
// Initialize register BuildClauses
func (e *ExtraClausePlugin) Initialize(db *gorm.DB) error {
db.Callback().Query().Clauses = []string{
"WITH", "SELECT", "FROM", "WHERE", "GROUP BY", "UNION", "INTERSECT", "EXCEPT", "ORDER BY", "LIMIT", "FOR",
}
db.Callback().Row().Clauses = []string{
"WITH", "SELECT", "FROM", "WHERE", "GROUP BY", "UNION", "INTERSECT", "EXCEPT", "ORDER BY", "LIMIT", "FOR",
}
return nil
}
// New create new ExtraClausePlugin
//
// // example
// db.Use(extraClausePlugin.New())
func New() *ExtraClausePlugin {
return &ExtraClausePlugin{}
}