Your Question
db.Statement.SQL.String() and db.Statement.Vars is always empty, is there any way I could get the raw statement of my query, I need to pass this query for my custom tracer
The document you expected this should be explained
Somewhere around this docs https://gorm.io/docs/logger.html
Expected answer
The example of custom logger implementation with tracer should be included on logger documentation
Comment From: github-actions[bot]
This issue has been automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days
Comment From: jinzhu
https://gorm.io/docs/sql_builder.html#ToSQL
Comment From: chumaumenze
Use this.
drySession := &gorm.Session{
SkipDefaultTransaction: true,
DryRun: true,
}
stmt = db.Session(drySession).Create(&model).Statement
fmt.Printf("SQL: %s\nVars: %v\n", stmt.Statement.SQL.String(), stmt.Vars)