Most case we use ....Scan(), ....First(), ...Find(), ...Delete(), ...Update, ... Updates ...Create to executed a sql.

However, in some case, we want to build a proxy db-api to do some pre-control for db operations.

It means we might transfer all orm executions to raw sql, and pass it to proxy db-api-srv.

Is there a way to get sql prepared befoe it 's executed.

It works like

// This will not execute insert into u values(...)
// Instead it just return string sql detail  " insert into u(...) values(...)", which is totally executable in database terminal.
sql :=db.PipeSQL().Model(u).Create(&u)
fmt.Println(sql)

sql := db.PipeSQL().Model(u).Update(...)
fmt.Println(sql)

// All cases below work like it:
// .PipeSQL()....Raw()...Scan()
// ..PipeSQL()......Delete()
// ..PipeSQL().....Exec()
// .PipeSQL()......Firrst
// ..PipeSQL().....Find
// 

Comment From: fwhezfwhez

@jinzhu

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking