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
funccustomAfterModifyCallback(db*gorm.DB) {
ifdb.Error==nil { //This should only happen if GORM successfully make a `commit`tbName:=db.Statement.Schema.TablevarrowIdany//Row ID should only be a string or a numberfor_, field:=rangedb.Statement.Schema.Fields { //Get model fieldsiffield.PrimaryKey {
rowId, _=field.ValueOf(db.Statement.Context, db.Statement.ReflectValue)
}
}
fmt.Println(db.RowsAffected, tbName, rowId)
}
}
//...ifsvDB, err:=gorm.Open(sqlite.Open(serverDsn), &gorm.Config{SkipDefaultTransaction: true, PrepareStmt: true}); err==nil {
//svDB.Callback().Create().After("gorm:commit").Register("cbf:customAfterModifyCallback", customAfterModifyCallback)
svDB.Callback().Update().After("gorm:commit").Register("cbf:customAfterModifyCallback", customAfterModifyCallback)
svDB.Callback().Delete().After("gorm:commit").Register("cbf:customAfterModifyCallback", customAfterModifyCallback)
//
}
How do I know which operation was use in the callback?
For instance, I want to know if it was INSERT, UPDATE or DELETE operation?
Thanks,
The document you expected this should be explained
N/A
Expected answer
...
The text was updated successfully, but these errors were encountered:
Your Question
I have a custom callback like this:
How do I know which operation was use in the callback?
For instance, I want to know if it was
INSERT
,UPDATE
orDELETE
operation?Thanks,
The document you expected this should be explained
N/A
Expected answer
...
The text was updated successfully, but these errors were encountered: