Describe the feature

Add a method to get context from DB object easily, like this:

func (db *DB) Context() context.Context {
     return db.Statement.Context
}

Motivation

When I use transaction,I want to get context what pass in by WithContext method,I can only use tx.Statement.Context.

err := db.WithContext(context.WithValue(ctx, "aaa", "bbbb")).Transaction(func(tx *gorm.DB) error {
       aaa := tx.Statement.Context.Value("aaaa").(string)
})

instead:

err := db.WithContext(context.WithValue(ctx, "aaa", "bbbb")).Transaction(func(tx *gorm.DB) error {
       aaa := tx.Context().Value("aaaa").(string)
})

I think it is more easily.

Related Issues

NO

Comment From: townsymush

Assuming the feature request has been accepted, happy to add this as a first issue

Comment From: jinzhu

Sorry, but not going to add an API for that.

For people want to use context, he better to know the statement, we don't want to create a shortcut to hide it.