You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While using gorm.io/plugin/dbresolver to split read-write, raw query having whitespace(s) as prefix should go to read server.
import (
"gorm.io/gorm""gorm.io/plugin/dbresolver""gorm.io/driver/mysql"
)
DB, err:=gorm.Open(mysql.Open("db1_dsn"), &gorm.Config{})
DB.Use(dbresolver.Register(dbresolver.Config{
// use `db1` as sources, `db2` as replicas for Sources: []gorm.Dialector{mysql.Open("db1_dsn")},
Replicas: []gorm.Dialector{mysql.Open("db2_dsn")}
}, "users"))
// ...readDB, err:=gorm.Open(mysql.Open("db2_dsn"), &gorm.Config{})
iferr!=nil {
// handle error
}
readDB.Create(&User{Name: "read"})
// this query should go to the read db with db2_dsnDB.Raw(`select name from userswhere name = ?`, "read").Row().Scan(&name)
This query should go to the read db with db2_dsn, but the current dbresolver sends it to the write db with db1_dsn.
The text was updated successfully, but these errors were encountered:
GORM Playground Link
go-gorm/playground#239
Description
While using
gorm.io/plugin/dbresolver
to split read-write, raw query having whitespace(s) as prefix should go to read server.This query should go to the read db with
db2_dsn
, but the current dbresolver sends it to the write db withdb1_dsn
.The text was updated successfully, but these errors were encountered: