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

Add skip output statement #6659

Closed
wants to merge 4 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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
17 changes: 16 additions & 1 deletion gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ type Config struct {
CreateBatchSize int
// TranslateError enabling error translation
TranslateError bool

// SkipOutputStatement disable OUTPUT clause when inserting a row
SkipOutputStatement bool
// ClauseBuilders clause builder
ClauseBuilders map[string]clause.ClauseBuilder
// ConnPool db conn pool
Expand Down Expand Up @@ -110,6 +111,7 @@ type Session struct {
AllowGlobalUpdate bool
FullSaveAssociations bool
QueryFields bool
SkipOutputStatement bool
Context context.Context
Logger logger.Interface
NowFunc func() time.Time
Expand Down Expand Up @@ -224,6 +226,11 @@ func (db *DB) Session(config *Session) *DB {
clone: 1,
}
)

if config.SkipOutputStatement {
tx.Config.SkipOutputStatement = true
}

if config.CreateBatchSize > 0 {
tx.Config.CreateBatchSize = config.CreateBatchSize
}
Expand Down Expand Up @@ -318,6 +325,14 @@ func (db *DB) Debug() (tx *DB) {
})
}

// Skip the output statement
func (db *DB) SkipOutput() (tx *DB) {
tx = db.getInstance()
return tx.Session(&Session{
SkipOutputStatement: true,
})
}

// Set store value with key into current db instance's context
func (db *DB) Set(key string, value interface{}) *DB {
tx := db.getInstance()
Expand Down
Loading