db.clone的值控制函数getInstance是否返回新实例,一级新实列复制原实例的哪些数据。
问题
看下面一段代码,其中的三次查询为何不会相会影响,查询一的Where不会带到查询二和查询三。
package main
import (
"fmt"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
// 定义模型
type Product struct {
gorm.Model
Code string
Price uint
}
func main() {
// 连接数据库
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{
})
if err != nil {
panic("failed to connect database")
}
// 自动迁移模式
db.AutoMigrate(&Product{
})
// 插入3条示例数据
db.Create(&Product{
Code: "D42", Price: 100})
db.Create(&Product{
Code: "D43", Price: 200})
db.Create(&Product{
Code: "D44", Price: 300})
// 根据不同条件查询
var products []Product
// 查询一
db.Where("price > ?", 150).Find(&p