-
-
Save mymedia2/9e809d210c68ab5107f0bce3d28587b8 to your computer and use it in GitHub Desktop.
Incorrect parenthesis?
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
package main | |
import ( | |
"time" | |
"gorm.io/driver/sqlite" | |
"gorm.io/gorm" | |
) | |
func PaidWithCreditCard(db *gorm.DB) *gorm.DB { | |
return db.Where("pay_mode = ?", "card") | |
} | |
func main() { | |
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{}) | |
db.AutoMigrate(&Order{}) | |
thisYear := time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local) | |
var orders []Order | |
db.Debug().Scopes(PaidWithCreditCard). | |
Where("product = ?", "banana").Or("created_at > ?", thisYear). | |
Find(&orders) | |
_ = err // we ignore errors for simplicity | |
} | |
type Order struct { | |
gorm.Model | |
Product string | |
PayMode string | |
} |
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
2022/11/09 18:15:18 /home/mymedia/.go/pkg/mod/gorm.io/gorm@v1.24.1/callbacks.go:134 | |
[0.073ms] [rows:0] SELECT * FROM `orders` WHERE (product = "banana" OR created_at > "2022-01-01 00:00:00" AND pay_mode = "card") AND `orders`.`deleted_at` IS NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment