Created
May 10, 2023 09:09
-
-
Save Kamandlou/8bbbc74f17ba90873a8cfed2741d84a0 to your computer and use it in GitHub Desktop.
Set timeout for sql query in GORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It will cancel at one second | |
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | |
defer cancel() | |
db.WithContext(ctx).Find(&User) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment