go-gorm / postgres

GORM PostgreSQL driver
MIT License
234 stars 123 forks source link

WithoutReturning set true, select panic #177

Closed ppanphper closed 1 year ago

ppanphper commented 1 year ago

GORM Playground Link

https://github.com/go-gorm/playground/pull/1

Description

image 当设置 WithoutReturning = true

没有执行注册默认callback callbacks.RegisterDefaultCallbacks

select insert等操作会报panic

ppanphper commented 1 year ago

image 我目前的解决方式

ppanphper commented 1 year ago

可以学习一下mysql组件的写法

image

a631807682 commented 1 year ago

~~Can you provide reproduction code? In fact, if not registered, the default clauses will be used. https://github.com/go-gorm/gorm/blob/master/callbacks/callbacks.go#L27~~ No need, I have reproduced.

ppanphper commented 1 year ago

当我设置WithoutReturning = true 同时使用Scan方法,会出现panic

ppanphper commented 1 year ago

postgresConfig := postgres.New(postgres.Config{ PreferSimpleProtocol: true, DSN: dsn, WithoutReturning: true, }) db, _ := gorm.Open(postgresConfig, &gorm.Config{}) var data = map[string]interface{}{} sql := select * from table where condition

db.Raw(sql).Scan(&data)

ppanphper commented 1 year ago

image fns is nil

a631807682 commented 1 year ago

After this https://github.com/go-gorm/gorm/commit/af3fbdc2fcfface01ce2a0795ee0fac3997ddc8e change, whether to support return is specified by the clauses, which means that we cannot support those that neither support returning (or the user does not want return), nor support database of LastInsertId

cc @jinzhu